@@ -221,9 +221,27 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
221
221
position : ts . LineAndCharacter
222
222
) : vscode . CompletionList {
223
223
const cached = this . _completionsCache . getCached ( context , position ) ;
224
+ const completions : vscode . CompletionList = {
225
+ isIncomplete : false ,
226
+ items : [ ] ,
227
+ } ;
228
+
224
229
if ( cached ) {
225
230
return cached ;
226
231
}
232
+
233
+ /**
234
+ * This would happen if a ` is triggered causing VSCode to open up two ``. At this stage completions aren't needed
235
+ * but they are still requested.
236
+ * Due to the fact there's nothing to complete (empty template) the language servers below end up requesting everything,
237
+ * causing a 3-4 second delay. When a template string is opened up we should do nothing and return an empty list.
238
+ *
239
+ * Also fixes: https://github.com/styled-components/vscode-styled-components/issues/276
240
+ **/
241
+ if ( context . node . getText ( ) === '``' ) {
242
+ return completions ;
243
+ }
244
+
227
245
const doc = this . virtualDocumentFactory . createVirtualDocument ( context ) ;
228
246
const virtualPosition = this . virtualDocumentFactory . toVirtualDocPosition ( position ) ;
229
247
const stylesheet = this . scssLanguageService . parseStylesheet ( doc ) ;
@@ -232,10 +250,8 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
232
250
const completionsCss = this . cssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
233
251
const completionsScss = this . scssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
234
252
completionsScss . items = filterScssCompletionItems ( completionsScss . items ) ;
235
- const completions : vscode . CompletionList = {
236
- isIncomplete : false ,
237
- items : [ ...completionsCss . items , ...completionsScss . items ] ,
238
- } ;
253
+
254
+ completions . items = [ ...completionsCss . items , ...completionsScss . items ] ;
239
255
if ( emmetResults . items . length ) {
240
256
completions . items . push ( ...emmetResults . items ) ;
241
257
completions . isIncomplete = true ;
0 commit comments