Skip to content

Commit

Permalink
fix: functions in string interpolation get suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Aug 4, 2024
1 parent e8f3348 commit 6085e8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,32 @@ test("should suggest symbols when interpolation is part of CSS selector", async
const { items } = await ls.doComplete(two, Position.create(1, 7));
assert.ok(items.find((annotation) => annotation.label === "$selector"));
});

test("should suggest variables and functions as function parameters in string interpolation ", async () => {
ls.configure({
completionSettings: {
suggestFromUseOnly: true,
},
});

const one = fileSystemProvider.createDocument(
["$primary: limegreen;", "@function compare($a: 1, $b) {}"],
{
uri: "one.scss",
},
);
const two = fileSystemProvider.createDocument(
['@use "./one";', '$test: "#{one.compare(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, 26));
assert.ok(items.find((annotation) => annotation.label === "$primary"));
assert.ok(items.find((annotation) => annotation.label === "compare"));
});
3 changes: 2 additions & 1 deletion packages/language-services/src/features/do-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ export class DoComplete extends LanguageFeature {
};
}

const isInterpolation = currentWord.includes("#{");
const isInterpolation =
currentWord.includes("#{") || lineBeforePosition.includes("#{");

const context: CompletionContext = {
currentWord,
Expand Down

0 comments on commit 6085e8b

Please sign in to comment.