diff --git a/src/Completion.ts b/src/Completion.ts index 4c0aa696d..6d6bf2860 100644 --- a/src/Completion.ts +++ b/src/Completion.ts @@ -9,6 +9,12 @@ import * as language from "./Language"; import { UserFunctionNamespaceDefinition } from "./UserFunctionNamespaceDefinition"; import { IVariableDefinition } from "./VariableDefinition"; +export enum CompletionPriority { + normal = "normal", + high = "high", + low = "low", +} + /** * A completion item in the list of completion suggestions that appear when a user invokes auto-completion (Ctrl + Space). */ @@ -23,7 +29,7 @@ export class Item { public readonly additionalEdits: { span: language.Span; insertText: string }[] | undefined; public readonly sortText: string | undefined; public readonly commitCharacters: string[] | undefined; - public readonly highPriority: boolean; + public readonly priority: CompletionPriority; public readonly preselect: boolean; public readonly telemetryProperties: { [key: string]: string } | undefined; @@ -61,7 +67,7 @@ export class Item { /** * Priority for sorting used in addition to sortText. */ - highPriority?: boolean; + priority?: CompletionPriority; preselect?: boolean; /** * Optional additional telemetry properties for if the completion is activated @@ -79,7 +85,7 @@ export class Item { this.additionalEdits = options.additionalEdits; this.sortText = options.sortText; this.commitCharacters = options.commitCharacters; - this.highPriority = !!options.highPriority; + this.priority = options.priority ?? CompletionPriority.normal; this.preselect = !!options.preselect; this.telemetryProperties = options.telemetryProperties; } diff --git a/src/SnippetManager.ts b/src/SnippetManager.ts index cab7bcade..369048b42 100644 --- a/src/SnippetManager.ts +++ b/src/SnippetManager.ts @@ -86,7 +86,9 @@ export class SnippetManager implements ISnippetManager { detail, insertText: snippet.insertText, span, - kind: Completion.CompletionKind.Snippet + kind: Completion.CompletionKind.Snippet, + // Make sure snippets show up after normal completions + priority: Completion.CompletionPriority.low })); } diff --git a/src/getResourceIdCompletions.ts b/src/getResourceIdCompletions.ts index 2abbc4d81..4cc716514 100644 --- a/src/getResourceIdCompletions.ts +++ b/src/getResourceIdCompletions.ts @@ -123,7 +123,7 @@ function getCompletions( insertText, span, kind: Completion.CompletionKind.DtResourceIdResName, - highPriority: true, + priority: Completion.CompletionPriority.high, // Force the first of the resourceId completions to be preselected, otherwise // vscode tends to preselect one of the regular function completions based // on recently-typed text @@ -225,7 +225,7 @@ function getResourceTypeCompletions( insertText, span, kind: Completion.CompletionKind.DtResourceIdResType, - highPriority: true, + priority: Completion.CompletionPriority.high, // Force the first of the resourceId completions to be preselected, otherwise // vscode tends to preselect one of the regular function completions based // on recently-typed text diff --git a/src/util/toVsCodeCompletionItem.ts b/src/util/toVsCodeCompletionItem.ts index bfc407736..783c5e85a 100644 --- a/src/util/toVsCodeCompletionItem.ts +++ b/src/util/toVsCodeCompletionItem.ts @@ -22,8 +22,23 @@ export function toVsCodeCompletionItem(deploymentFile: DeploymentDocument, item: vscodeItem.commitCharacters = item.commitCharacters; vscodeItem.preselect = item.preselect; - // Add priority string to start of sortText; - vscodeItem.sortText = `${item.highPriority ? '0' : '1'}-${item.sortText ?? item.label}`; + let sortPriorityPrefix: string; + switch (item.priority) { + case Completion.CompletionPriority.low: + sortPriorityPrefix = `${String.fromCharCode(255)}-`; + break; + case Completion.CompletionPriority.high: + sortPriorityPrefix = `${String.fromCharCode(1)}-`; + break; + case Completion.CompletionPriority.normal: + sortPriorityPrefix = ''; + break; + default: + assertNever(item.priority); + } + + // Add priority string to start of sortText, use label if no sortText + vscodeItem.sortText = `${sortPriorityPrefix}${item.sortText ?? item.label}`; switch (item.kind) { case Completion.CompletionKind.Function: