@@ -221,9 +221,27 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
221221 position : ts . LineAndCharacter
222222 ) : vscode . CompletionList {
223223 const cached = this . _completionsCache . getCached ( context , position ) ;
224+ const completions : vscode . CompletionList = {
225+ isIncomplete : false ,
226+ items : [ ] ,
227+ } ;
228+
224229 if ( cached ) {
225230 return cached ;
226231 }
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+
227245 const doc = this . virtualDocumentFactory . createVirtualDocument ( context ) ;
228246 const virtualPosition = this . virtualDocumentFactory . toVirtualDocPosition ( position ) ;
229247 const stylesheet = this . scssLanguageService . parseStylesheet ( doc ) ;
@@ -232,10 +250,8 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
232250 const completionsCss = this . cssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
233251 const completionsScss = this . scssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
234252 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 ] ;
239255 if ( emmetResults . items . length ) {
240256 completions . items . push ( ...emmetResults . items ) ;
241257 completions . isIncomplete = true ;
0 commit comments