From 58b360d9bb6e40c32580e0ff903d8625155f0afd Mon Sep 17 00:00:00 2001 From: William Killerud Date: Mon, 29 Jul 2024 20:50:19 +0200 Subject: [PATCH] fix: support suggestions in interpolation in class selector --- .../do-complete-interpolation.test.ts | 25 +++++++++++++++++++ .../src/features/do-complete.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) 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);