Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suggest from forwarded sass built-ins #200

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ test("suggests built-in sass modules", async () => {
);
});

test("suggest sass built-ins that are forwarded by the stylesheet that is @used", async () => {
const one = fileSystemProvider.createDocument(['@forward "sass:math";'], {
uri: "test.scss",
});
const two = fileSystemProvider.createDocument([
'@use "./test";',
"$var: test.",
]);

// 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, 11));
assert.notEqual(
items.length,
0,
"Expected to get completions from the sass:math module",
);

// Quick sampling of the results
assert.deepStrictEqual(
items.find((annotation) => annotation.label === "$pi"),
{
documentation: {
kind: "markdown",
value:
"The value of the mathematical constant **π**.\n\n[Sass documentation](https://sass-lang.com/documentation/modules/math#$pi)",
},
filterText: "test.$pi",
insertText: ".$pi",
insertTextFormat: InsertTextFormat.PlainText,
kind: CompletionItemKind.Variable,
label: "$pi",
labelDetails: {
detail: undefined,
},
},
);
});

test("should suggest symbol from a different document via @use", async () => {
const one = fileSystemProvider.createDocument("$primary: limegreen;", {
uri: "one.scss",
Expand Down
24 changes: 24 additions & 0 deletions packages/language-services/src/features/do-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,30 @@ export class DoComplete extends LanguageFeature {
}
}
}

// check if the document @forwards a sass built-in
// since they aren't documents that are visited by findInWorkspace
const links = await this.ls.findDocumentLinks(currentDocument);
for (let link of links) {
if (
link.type === NodeType.Forward &&
link.target &&
link.target.includes("sass:")
) {
// Look for matches in built-in namespaces, which do not appear in storage
for (const [builtIn, docs] of Object.entries(sassBuiltInModules)) {
if (builtIn === link.target) {
const suggestions = this.doSassBuiltInCompletion(
document,
context,
docs,
);
items.push(...suggestions);
}
}
}
}

return items;
},
start,
Expand Down
Loading