diff --git a/packages/language-services/src/features/__tests__/do-complete-interpolation.test.ts b/packages/language-services/src/features/__tests__/do-complete-interpolation.test.ts index 74c7927f..62eb60d5 100644 --- a/packages/language-services/src/features/__tests__/do-complete-interpolation.test.ts +++ b/packages/language-services/src/features/__tests__/do-complete-interpolation.test.ts @@ -61,3 +61,28 @@ test("should suggest symbol from a different document via @use when in string in const { items } = await ls.doComplete(two, Position.create(1, 29)); assert.ok(items.find((annotation) => annotation.label === "$primary")); }); + +test("should suggest symbols when interpolation is part of CSS selector", async () => { + ls.configure({ + completionSettings: { + suggestFromUseOnly: true, + }, + }); + + const one = fileSystemProvider.createDocument("$selector: 'test';", { + uri: "one.scss", + }); + const two = fileSystemProvider.createDocument( + ['@use "./one";', ".#{one.} {}"], + { + uri: "two.scss", + }, + ); + + // emulate scanner of language service which adds workspace documents to the cache + ls.parseStylesheet(one); + ls.parseStylesheet(two); + + const { items } = await ls.doComplete(two, Position.create(1, 7)); + assert.ok(items.find((annotation) => annotation.label === "$selector")); +}); diff --git a/packages/language-services/src/features/do-complete.ts b/packages/language-services/src/features/do-complete.ts index 5637e41b..0e6e2c1d 100644 --- a/packages/language-services/src/features/do-complete.ts +++ b/packages/language-services/src/features/do-complete.ts @@ -425,7 +425,7 @@ export class DoComplete extends LanguageFeature { : currentWord.substring( // Skip #{ if this is interpolation isInterpolation ? currentWord.indexOf("{") + 1 : 0, - currentWord.indexOf("."), + currentWord.indexOf(".", currentWord.indexOf("{") + 1), ); const isPropertyValue = rePropertyValue.test(lineBeforePosition);