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