@@ -217,9 +217,27 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
217217 position : ts . LineAndCharacter
218218 ) : vscode . CompletionList {
219219 const cached = this . _completionsCache . getCached ( context , position ) ;
220+ const completions : vscode . CompletionList = {
221+ isIncomplete : false ,
222+ items : [ ] ,
223+ } ;
224+
220225 if ( cached ) {
221226 return cached ;
222227 }
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+
223241 const doc = this . virtualDocumentFactory . createVirtualDocument ( context ) ;
224242 const virtualPosition = this . virtualDocumentFactory . toVirtualDocPosition ( position ) ;
225243 const stylesheet = this . scssLanguageService . parseStylesheet ( doc ) ;
@@ -228,10 +246,8 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
228246 const completionsCss = this . cssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
229247 const completionsScss = this . scssLanguageService . doComplete ( doc , virtualPosition , stylesheet ) || emptyCompletionList ;
230248 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 ] ;
235251 if ( emmetResults . items . length ) {
236252 completions . items . push ( ...emmetResults . items ) ;
237253 completions . isIncomplete = true ;
0 commit comments