Skip to content

Commit

Permalink
fix: for wildcard use, omit . for functions in filtertext
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Jun 16, 2024
1 parent 473d3ed commit d72e997
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,12 @@ test("should suggest symbol from a different document via @use with wildcard ali
},
});

const one = fileSystemProvider.createDocument("$primary: limegreen;", {
uri: "one.scss",
});
const one = fileSystemProvider.createDocument(
["$primary: limegreen;", "@function one() { @return 1; }"],
{
uri: "one.scss",
},
);
const two = fileSystemProvider.createDocument(
['@use "./one" as *;', ".a { color: "],
{
Expand All @@ -1016,11 +1019,7 @@ test("should suggest symbol from a different document via @use with wildcard ali
ls.parseStylesheet(two);

const { items } = await ls.doComplete(two, Position.create(1, 12));
assert.notEqual(
0,
items.length,
"Expected to find a completion item for $primary",
);
assert.notEqual(2, items.length, "Expected to find two completion items");
assert.deepStrictEqual(
items.find((annotation) => annotation.label === "$primary"),
{
Expand All @@ -1034,4 +1033,24 @@ test("should suggest symbol from a different document via @use with wildcard ali
tags: [],
},
);
assert.deepStrictEqual(
items.find((annotation) => annotation.label === "one"),
{
documentation: {
kind: "markdown",
value:
"```scss\n@function one()\n```\n____\nFunction declared in one.scss",
},
filterText: "one",
insertText: "one()",
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Function,
label: "one",
labelDetails: {
detail: "()",
},
sortText: undefined,
tags: [],
},
);
});
24 changes: 16 additions & 8 deletions packages/language-services/src/features/do-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,24 @@ export class DoComplete extends LanguageFeature {
const items: CompletionItem[] = [];

const label = `${prefix}${symbol.name}`;
const filterText = namespace
? `${namespace !== "*" ? namespace : ""}.${prefix}${symbol.name}`
: symbol.name;
let filterText = symbol.name;
if (namespace) {
if (namespace === "*") {
filterText = `${prefix}${symbol.name}`;
} else {
filterText = `${namespace}.${prefix}${symbol.name}`;
}
}

const isEmbedded = this.isEmbedded(initialDocument);
const insertText = namespace
? namespace !== "*" && !isEmbedded
? `.${prefix}${symbol.name}`
: `${prefix}${symbol.name}`
: symbol.name;
let insertText = symbol.name;
if (namespace) {
if (namespace === "*" || isEmbedded) {
insertText = `${prefix}${symbol.name}`;
} else {
insertText = `.${prefix}${symbol.name}`;
}
}

const sortText = isPrivate ? label.replace(/^$[_]/, "") : undefined;

Expand Down

0 comments on commit d72e997

Please sign in to comment.