@@ -13,7 +13,7 @@ import {
13
13
CompletionItemKind ,
14
14
Connection ,
15
15
} from 'vscode-languageserver/node'
16
- import { TextDocument } from 'vscode-languageserver-textdocument'
16
+ import { Position , TextDocument } from 'vscode-languageserver-textdocument'
17
17
import { Utils , URI } from 'vscode-uri'
18
18
import { getLanguageModelCache } from './languageModelCache'
19
19
import { Stylesheet } from 'vscode-css-languageservice'
@@ -137,8 +137,58 @@ export class CssServer {
137
137
} )
138
138
}
139
139
140
+ function isInImportDirective ( doc : TextDocument , pos : Position ) {
141
+ let text = doc . getText ( {
142
+ start : { line : pos . line , character : 0 } ,
143
+ end : pos ,
144
+ } )
145
+
146
+ // Scan backwards to see if we're inside an `@import` directive
147
+ let foundImport = false
148
+ let foundDirective = false
149
+
150
+ for ( let i = text . length - 1 ; i >= 0 ; i -- ) {
151
+ let char = text [ i ]
152
+ if ( char === '\n' ) break
153
+
154
+ if ( char === '(' && ! foundDirective ) {
155
+ if ( text . startsWith ( ' source(' , i - 7 ) ) {
156
+ foundDirective = true
157
+ }
158
+
159
+ //
160
+ else if ( text . startsWith ( ' theme(' , i - 6 ) ) {
161
+ foundDirective = true
162
+ }
163
+
164
+ //
165
+ else if ( text . startsWith ( ' prefix(' , i - 7 ) ) {
166
+ foundDirective = true
167
+ }
168
+ }
169
+
170
+ //
171
+ else if ( char === '@' && ! foundImport ) {
172
+ if ( text . startsWith ( '@import ' , i ) ) {
173
+ foundImport = true
174
+ }
175
+ }
176
+ }
177
+
178
+ return foundImport && foundDirective
179
+ }
180
+
140
181
connection . onCompletion ( async ( { textDocument, position } , _token ) =>
141
182
withDocumentAndSettings ( textDocument . uri , async ( { original, document, settings } ) => {
183
+ // If we're inside source(…), prefix(…), or theme(…), don't show
184
+ // completions from the CSS language server
185
+ if ( isInImportDirective ( original , position ) ) {
186
+ return {
187
+ isIncomplete : false ,
188
+ items : [ ] ,
189
+ }
190
+ }
191
+
142
192
let result = await cssLanguageService . doComplete2 (
143
193
document ,
144
194
position ,
0 commit comments