@@ -11,6 +11,8 @@ import * as vscode from 'vscode-languageserver-types';
11
11
import * as config from './_config' ;
12
12
import { ConfigurationManager } from './_configuration' ;
13
13
import { VirtualDocumentProvider } from './_virtual-document-provider' ;
14
+ import { TextDocument } from 'vscode-languageserver-textdocument' ;
15
+
14
16
15
17
const cssErrorCode = 9999 ;
16
18
@@ -115,7 +117,9 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
115
117
position : ts . LineAndCharacter
116
118
) : ts . WithMetadata < ts . CompletionInfo > {
117
119
const items = this . getCompletionItems ( context , position ) ;
118
- return translateCompletionItemsToCompletionInfo ( this . typescript , items ) ;
120
+ const doc = this . virtualDocumentFactory . createVirtualDocument ( context ) ;
121
+ const wrapper = this . virtualDocumentFactory . getVirtualDocumentWrapper ( context ) ;
122
+ return translateCompletionItemsToCompletionInfo ( this . typescript , items , doc , wrapper ) ;
119
123
}
120
124
121
125
public getCompletionEntryDetails (
@@ -242,7 +246,7 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
242
246
243
247
private translateDiagnostics (
244
248
diagnostics : vscode . Diagnostic [ ] ,
245
- doc : vscode . TextDocument ,
249
+ doc : TextDocument ,
246
250
context : TemplateContext ,
247
251
content : string
248
252
) {
@@ -254,7 +258,7 @@ export class StyledTemplateLanguageService implements TemplateLanguageService {
254
258
private translateDiagnostic (
255
259
diagnostic : vscode . Diagnostic ,
256
260
file : ts . SourceFile ,
257
- doc : vscode . TextDocument ,
261
+ doc : TextDocument ,
258
262
context : TemplateContext ,
259
263
content : string
260
264
) : ts . Diagnostic | undefined {
@@ -378,7 +382,9 @@ function filterScssCompletionItems(
378
382
379
383
function translateCompletionItemsToCompletionInfo (
380
384
typescript : typeof ts ,
381
- items : vscode . CompletionList
385
+ items : vscode . CompletionList ,
386
+ doc : TextDocument ,
387
+ wrapper : string
382
388
) : ts . WithMetadata < ts . CompletionInfo > {
383
389
return {
384
390
metadata : {
@@ -387,7 +393,7 @@ function translateCompletionItemsToCompletionInfo(
387
393
isGlobalCompletion : false ,
388
394
isMemberCompletion : false ,
389
395
isNewIdentifierLocation : false ,
390
- entries : items . items . map ( x => translateCompetionEntry ( typescript , x ) ) ,
396
+ entries : items . items . map ( x => translateCompetionEntry ( typescript , x , doc , wrapper ) ) ,
391
397
} ;
392
398
}
393
399
@@ -407,13 +413,20 @@ function translateCompletionItemsToCompletionEntryDetails(
407
413
408
414
function translateCompetionEntry (
409
415
typescript : typeof ts ,
410
- item : vscode . CompletionItem
416
+ item : vscode . CompletionItem ,
417
+ doc : TextDocument ,
418
+ wrapper : string
411
419
) : ts . CompletionEntry {
412
420
return {
413
421
name : item . label ,
414
422
kind : item . kind ? translateCompletionItemKind ( typescript , item . kind ) : typescript . ScriptElementKind . unknown ,
415
423
kindModifiers : getKindModifiers ( item ) ,
416
424
sortText : item . sortText || item . label ,
425
+ replacementSpan : {
426
+ // The correct offset for start seems to be the range.start minus the wrapper
427
+ start : doc . offsetAt ( ( item as any ) . textEdit . range . start ) - wrapper . length ,
428
+ length : doc . offsetAt ( ( item as any ) . textEdit . range . end ) - doc . offsetAt ( ( item as any ) . textEdit . range . start ) ,
429
+ } ,
417
430
} ;
418
431
}
419
432
0 commit comments