Skip to content

Commit

Permalink
fix: completions understand show
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Nov 18, 2023
1 parent ab3b7ea commit 8ccf768
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
19 changes: 17 additions & 2 deletions server/src/features/completion/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function traverseTree(
accumulator: Map<string, CompletionItem[]>,
leaf: IScssDocument,
hiddenSymbols: string[] = [],
shownSymbols: string[] = [],
accumulatedPrefix = "",
) {
if (accumulator.has(leaf.uri)) {
Expand All @@ -263,6 +264,7 @@ function traverseTree(
document,
context,
hiddenSymbols,
shownSymbols,
accumulatedPrefix,
);
completionItems = completionItems.concat(variables);
Expand All @@ -274,6 +276,7 @@ function traverseTree(
document,
context,
hiddenSymbols,
shownSymbols,
accumulatedPrefix,
);
completionItems = completionItems.concat(mixins);
Expand All @@ -285,6 +288,7 @@ function traverseTree(
document,
context,
hiddenSymbols,
shownSymbols,
accumulatedPrefix,
);
completionItems = completionItems.concat(functions);
Expand All @@ -294,12 +298,17 @@ function traverseTree(
const placeholders = createPlaceholderCompletionItems(
scssDocument,
hiddenSymbols,
shownSymbols,
);
completionItems = completionItems.concat(placeholders);
}

accumulator.set(leaf.uri, completionItems);

// Reset these once we've processed the document they refered to
let hidden: string[] = [];
let shown: string[] = [];

// Check to see if we have to go deeper
// Don't follow uses, since we start with the document behind the first use, and symbols from further uses aren't available to us
// Don't follow imports, since the whole point here is to use the new module system
Expand All @@ -313,12 +322,17 @@ function traverseTree(
continue;
}

let hidden = hiddenSymbols;
if (
(child as ScssForward).hide &&
(child as ScssForward).hide.length > 0
) {
hidden = hiddenSymbols.concat((child as ScssForward).hide);
hidden = hidden.concat((child as ScssForward).hide);
}
if (
(child as ScssForward).show &&
(child as ScssForward).show.length > 0
) {
shown = shown.concat((child as ScssForward).show);
}

let prefix = accumulatedPrefix;
Expand All @@ -332,6 +346,7 @@ function traverseTree(
accumulator,
childDocument,
hidden,
shown,
prefix,
);
}
Expand Down
5 changes: 5 additions & 0 deletions server/src/features/completion/function-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function createFunctionCompletionItems(
currentDocument: TextDocument,
context: CompletionContext,
hiddenSymbols: string[] = [],
shownSymbols: string[] = [],
prefix = "",
): CompletionItem[] {
const completions: CompletionItem[] = [];
Expand All @@ -39,6 +40,10 @@ export function createFunctionCompletionItems(
continue;
}

if (shownSymbols.length > 0 && !shownSymbols.includes(func.name)) {
continue;
}

// Client needs the namespace as part of the text that is matched,
// and inserted text needs to include the `.` which will otherwise
// be replaced (except when we're embedded in Vue, Svelte or Astro).
Expand Down
5 changes: 5 additions & 0 deletions server/src/features/completion/mixin-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function createMixinCompletionItems(
currentDocument: TextDocument,
context: CompletionContext,
hiddenSymbols: string[] = [],
shownSymbols: string[] = [],
prefix = "",
): CompletionItem[] {
const completions: CompletionItem[] = [];
Expand All @@ -40,6 +41,10 @@ export function createMixinCompletionItems(
continue;
}

if (shownSymbols.length > 0 && !shownSymbols.includes(mixin.name)) {
continue;
}

const documentation = makeMixinDocumentation(mixin, scssDocument);

// Client needs the namespace as part of the text that is matched,
Expand Down
5 changes: 5 additions & 0 deletions server/src/features/completion/placeholder-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { applySassDoc } from "../../utils/sassdoc";
export function createPlaceholderCompletionItems(
scssDocument: IScssDocument,
hiddenSymbols: string[] = [],
shownSymbols: string[] = [],
): CompletionItem[] {
const completions: CompletionItem[] = [];

Expand All @@ -19,6 +20,10 @@ export function createPlaceholderCompletionItems(
continue;
}

if (shownSymbols.length > 0 && !shownSymbols.includes(placeholder.name)) {
continue;
}

const label = placeholder.name;
const filterText = placeholder.name.substring(1);

Expand Down
5 changes: 5 additions & 0 deletions server/src/features/completion/variable-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function createVariableCompletionItems(
currentDocument: TextDocument,
context: CompletionContext,
hiddenSymbols: string[] = [],
shownSymbols: string[] = [],
prefix = "",
): CompletionItem[] {
const completions: CompletionItem[] = [];
Expand Down Expand Up @@ -65,6 +66,10 @@ export function createVariableCompletionItems(
continue;
}

if (shownSymbols.length > 0 && !shownSymbols.includes(variable.name)) {
continue;
}

if (isPrivate) {
sortText = label.replace(/^$[_-]/, "");
}
Expand Down

0 comments on commit 8ccf768

Please sign in to comment.