From 8ccf7687dd0b1c0332e42ebcf7b4949005e54d15 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Sat, 18 Nov 2023 18:04:10 +0100 Subject: [PATCH] fix: completions understand show --- server/src/features/completion/completion.ts | 19 +++++++++++++++++-- .../completion/function-completion.ts | 5 +++++ .../features/completion/mixin-completion.ts | 5 +++++ .../completion/placeholder-completion.ts | 5 +++++ .../completion/variable-completion.ts | 5 +++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/server/src/features/completion/completion.ts b/server/src/features/completion/completion.ts index dccdd644..13803c30 100644 --- a/server/src/features/completion/completion.ts +++ b/server/src/features/completion/completion.ts @@ -240,6 +240,7 @@ function traverseTree( accumulator: Map, leaf: IScssDocument, hiddenSymbols: string[] = [], + shownSymbols: string[] = [], accumulatedPrefix = "", ) { if (accumulator.has(leaf.uri)) { @@ -263,6 +264,7 @@ function traverseTree( document, context, hiddenSymbols, + shownSymbols, accumulatedPrefix, ); completionItems = completionItems.concat(variables); @@ -274,6 +276,7 @@ function traverseTree( document, context, hiddenSymbols, + shownSymbols, accumulatedPrefix, ); completionItems = completionItems.concat(mixins); @@ -285,6 +288,7 @@ function traverseTree( document, context, hiddenSymbols, + shownSymbols, accumulatedPrefix, ); completionItems = completionItems.concat(functions); @@ -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 @@ -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; @@ -332,6 +346,7 @@ function traverseTree( accumulator, childDocument, hidden, + shown, prefix, ); } diff --git a/server/src/features/completion/function-completion.ts b/server/src/features/completion/function-completion.ts index e3f4ff44..2339f880 100644 --- a/server/src/features/completion/function-completion.ts +++ b/server/src/features/completion/function-completion.ts @@ -23,6 +23,7 @@ export function createFunctionCompletionItems( currentDocument: TextDocument, context: CompletionContext, hiddenSymbols: string[] = [], + shownSymbols: string[] = [], prefix = "", ): CompletionItem[] { const completions: CompletionItem[] = []; @@ -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). diff --git a/server/src/features/completion/mixin-completion.ts b/server/src/features/completion/mixin-completion.ts index d10bdac2..3b4b599c 100644 --- a/server/src/features/completion/mixin-completion.ts +++ b/server/src/features/completion/mixin-completion.ts @@ -24,6 +24,7 @@ export function createMixinCompletionItems( currentDocument: TextDocument, context: CompletionContext, hiddenSymbols: string[] = [], + shownSymbols: string[] = [], prefix = "", ): CompletionItem[] { const completions: CompletionItem[] = []; @@ -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, diff --git a/server/src/features/completion/placeholder-completion.ts b/server/src/features/completion/placeholder-completion.ts index cb8b9b86..a555c2c0 100644 --- a/server/src/features/completion/placeholder-completion.ts +++ b/server/src/features/completion/placeholder-completion.ts @@ -11,6 +11,7 @@ import { applySassDoc } from "../../utils/sassdoc"; export function createPlaceholderCompletionItems( scssDocument: IScssDocument, hiddenSymbols: string[] = [], + shownSymbols: string[] = [], ): CompletionItem[] { const completions: CompletionItem[] = []; @@ -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); diff --git a/server/src/features/completion/variable-completion.ts b/server/src/features/completion/variable-completion.ts index 96ee0040..ad79c80e 100644 --- a/server/src/features/completion/variable-completion.ts +++ b/server/src/features/completion/variable-completion.ts @@ -18,6 +18,7 @@ export function createVariableCompletionItems( currentDocument: TextDocument, context: CompletionContext, hiddenSymbols: string[] = [], + shownSymbols: string[] = [], prefix = "", ): CompletionItem[] { const completions: CompletionItem[] = []; @@ -65,6 +66,10 @@ export function createVariableCompletionItems( continue; } + if (shownSymbols.length > 0 && !shownSymbols.includes(variable.name)) { + continue; + } + if (isPrivate) { sortText = label.replace(/^$[_-]/, ""); }