@@ -10,7 +10,7 @@ import { loadLanguageBlocks } from './data';
10
10
let sfcDataProvider : html . IHTMLDataProvider | undefined ;
11
11
12
12
export function create ( ) : LanguageServicePlugin {
13
- const htmlPlugin = createHtmlService ( {
13
+ const htmlService = createHtmlService ( {
14
14
documentSelector : [ 'vue-root-tags' ] ,
15
15
useDefaultDataProvider : false ,
16
16
getCustomData ( context ) {
@@ -23,7 +23,7 @@ export function create(): LanguageServicePlugin {
23
23
const formatSettings = await context . env . getConfiguration ?.< html . HTMLFormatConfiguration > ( 'html.format' ) ?? { } ;
24
24
const blockTypes = [ 'template' , 'script' , 'style' ] ;
25
25
26
- for ( const customBlock of root . _sfc . customBlocks ) {
26
+ for ( const customBlock of root . sfc . customBlocks ) {
27
27
blockTypes . push ( customBlock . type ) ;
28
28
}
29
29
@@ -41,14 +41,21 @@ export function create(): LanguageServicePlugin {
41
41
} ,
42
42
} ) ;
43
43
return {
44
- ...htmlPlugin ,
44
+ ...htmlService ,
45
45
name : 'vue-sfc' ,
46
+ capabilities : {
47
+ ...htmlService . capabilities ,
48
+ diagnosticProvider : {
49
+ interFileDependencies : false ,
50
+ workspaceDiagnostics : false ,
51
+ }
52
+ } ,
46
53
create ( context ) {
47
- const htmlPluginInstance = htmlPlugin . create ( context ) ;
54
+ const htmlServiceInstance = htmlService . create ( context ) ;
48
55
49
56
return {
50
57
51
- ...htmlPluginInstance ,
58
+ ...htmlServiceInstance ,
52
59
53
60
provideDocumentLinks : undefined ,
54
61
@@ -73,11 +80,53 @@ export function create(): LanguageServicePlugin {
73
80
return options ;
74
81
} ,
75
82
83
+ provideDiagnostics ( document , token ) {
84
+ return worker ( document , context , async root => {
85
+ const { vueSfc, sfc } = root ;
86
+ if ( ! vueSfc ) {
87
+ return ;
88
+ }
89
+
90
+ const originalResult = await htmlServiceInstance . provideDiagnostics ?.( document , token ) ;
91
+ const sfcErrors : vscode . Diagnostic [ ] = [ ] ;
92
+ const { template } = sfc ;
93
+
94
+ const {
95
+ startTagEnd = Infinity ,
96
+ endTagStart = - Infinity
97
+ } = template ?? { } ;
98
+
99
+ for ( const error of vueSfc . errors ) {
100
+ if ( 'code' in error ) {
101
+ const start = error . loc ?. start . offset ?? 0 ;
102
+ const end = error . loc ?. end . offset ?? 0 ;
103
+ if ( end < startTagEnd || start >= endTagStart ) {
104
+ sfcErrors . push ( {
105
+ range : {
106
+ start : document . positionAt ( start ) ,
107
+ end : document . positionAt ( end ) ,
108
+ } ,
109
+ severity : 1 satisfies typeof vscode . DiagnosticSeverity . Error ,
110
+ code : error . code ,
111
+ source : 'vue' ,
112
+ message : error . message ,
113
+ } ) ;
114
+ }
115
+ }
116
+ }
117
+
118
+ return [
119
+ ...originalResult ?? [ ] ,
120
+ ...sfcErrors
121
+ ] ;
122
+ } ) ;
123
+ } ,
124
+
76
125
provideDocumentSymbols ( document ) {
77
126
return worker ( document , context , root => {
78
127
79
128
const result : vscode . DocumentSymbol [ ] = [ ] ;
80
- const sfc = root . _sfc ;
129
+ const { sfc } = root ;
81
130
82
131
if ( sfc . template ) {
83
132
result . push ( {
@@ -162,7 +211,7 @@ export function create(): LanguageServicePlugin {
162
211
} ,
163
212
164
213
async provideCompletionItems ( document , position , context , token ) {
165
- const result = await htmlPluginInstance . provideCompletionItems ?.( document , position , context , token ) ;
214
+ const result = await htmlServiceInstance . provideCompletionItems ?.( document , position , context , token ) ;
166
215
if ( ! result ) {
167
216
return ;
168
217
}
0 commit comments