Skip to content

Commit

Permalink
fix: add prefix support to forwarded sass built-ins
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Aug 11, 2024
1 parent 1159665 commit b65d8b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ test("suggest sass built-ins that are forwarded with a prefix", async () => {
},
},
);
assert.ok(items.find((a) => a.label === "math-clamp"));
});

test("should suggest symbol from a different document via @use", async () => {
Expand Down
22 changes: 18 additions & 4 deletions packages/language-services/src/features/do-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ export class DoComplete extends LanguageFeature {
document,
context,
docs,
link.as ? prefix + link.as : "",
);
items.push(...suggestions);
}
Expand Down Expand Up @@ -1072,23 +1073,36 @@ export class DoComplete extends LanguageFeature {
document: TextDocument,
context: CompletionContext,
moduleDocs: SassBuiltInModule,
prefix: string = "",
): CompletionItem[] {
const items: CompletionItem[] = [];
for (const [name, docs] of Object.entries(moduleDocs.exports)) {
const { description, signature, parameterSnippet, returns } = docs;
const kind = signature
? CompletionItemKind.Function
: CompletionItemKind.Variable;

let label = name;
if (kind === CompletionItemKind.Variable) {
// Avoid ending up with namespace.prefix-$variable
label = `$${prefix}${asDollarlessVariable(name)}`;
} else {
label = `${prefix}${name}`;
}

// Client needs the namespace as part of the text that is matched,
const filterText = `${context.namespace}.${name}`;
const filterText = `${context.namespace}.${label}`;

// Inserted text needs to include the `.` which will otherwise
// be replaced (except when we're embedded in Vue, Svelte or Astro).
// Example result: .floor(${1:number})
const isEmbedded = this.isEmbedded(document);

const insertText = context.currentWord.includes(".")
? `${isEmbedded ? "" : "."}${name}${
? `${isEmbedded ? "" : "."}${label}${
signature ? `(${parameterSnippet})` : ""
}`
: name;
: label;

items.push({
documentation: {
Expand All @@ -1103,7 +1117,7 @@ export class DoComplete extends LanguageFeature {
kind: signature
? CompletionItemKind.Function
: CompletionItemKind.Variable,
label: name,
label,
labelDetails: {
detail:
signature && returns ? `${signature} => ${returns}` : signature,
Expand Down

0 comments on commit b65d8b1

Please sign in to comment.