From dc238c72680aafcbed2835c05411e288692096e0 Mon Sep 17 00:00:00 2001 From: Tal Wertheimer Date: Wed, 13 Dec 2023 11:40:13 +0200 Subject: [PATCH] Upgrade VSCode dependency to version 1.55 Signed-off-by: Tal Wertheimer --- package.json | 2 +- src/assistant/diagnostics.ts | 4 +- .../TabnineAuthenticationProvider.ts | 5 + src/debounceCompletions.ts | 5 +- src/getInlineCompletionItems.ts | 2 +- .../tabnineInlineCompletionItem.ts | 2 - src/lookAheadSuggestion.ts | 2 +- src/provideInlineCompletionItems.ts | 5 +- src/reportSuggestionShown.ts | 7 +- src/tabnineChatWidget/webviews/getIcon.ts | 1 + src/test/suite/utils/completion.utils.ts | 5 +- .../suite/utils/preReleaseInstaller.utils.ts | 3 + src/utils/logo.utils.ts | 1 + src/utils/utils.ts | 7 +- src/vscode.proposed.inlineCompletions.d.ts | 145 ------------------ yarn.lock | 8 +- 16 files changed, 31 insertions(+), 173 deletions(-) delete mode 100644 src/vscode.proposed.inlineCompletions.d.ts diff --git a/package.json b/package.json index f2d5601ca0..7a2d1502cc 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "@types/sinon": "^9.0.11", "@types/tmp": "^0.2.0", "@types/underscore": "^1.11.15", - "@types/vscode": "^1.50.0", + "@types/vscode": "^1.55.0", "@types/yauzl": "^2.9.1", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^4.18.0", diff --git a/src/assistant/diagnostics.ts b/src/assistant/diagnostics.ts index 47724579df..8b913ded68 100644 --- a/src/assistant/diagnostics.ts +++ b/src/assistant/diagnostics.ts @@ -61,7 +61,7 @@ const cancellationToken = new CancellationToken(); function getRelevantRange( document: vscode.TextDocument, - visibleRanges: vscode.Range[] + visibleRanges: readonly vscode.Range[] ): vscode.Range | undefined { const firstEditingPosition = changesTrackMap.get(document.uri); const visibleRange = visibleRanges.reduce((accumulator, currentValue) => @@ -79,7 +79,7 @@ function getRelevantRange( async function refreshDiagnostics( document: vscode.TextDocument, diagnosticsCollection: vscode.DiagnosticCollection, - visibleRanges: vscode.Range[] + visibleRanges: readonly vscode.Range[] ): Promise { cancellationToken.cancel(); const lock = await mutex.acquire(); diff --git a/src/authentication/TabnineAuthenticationProvider.ts b/src/authentication/TabnineAuthenticationProvider.ts index 2cb61e3fce..f579a266fc 100644 --- a/src/authentication/TabnineAuthenticationProvider.ts +++ b/src/authentication/TabnineAuthenticationProvider.ts @@ -125,12 +125,16 @@ export default class TabnineAuthenticationProvider if (!last && current) { this.sessionsChangeEventEmitter.fire({ added: [toSession(current)], + removed: undefined, + changed: undefined, }); } if (last && !current) { this.sessionsChangeEventEmitter.fire({ removed: [toSession(last)], + added: undefined, + changed: undefined, }); } @@ -138,6 +142,7 @@ export default class TabnineAuthenticationProvider this.sessionsChangeEventEmitter.fire({ removed: [toSession(last)], added: [toSession(current)], + changed: undefined, }); } } diff --git a/src/debounceCompletions.ts b/src/debounceCompletions.ts index 311a533049..2f3f67e0bf 100644 --- a/src/debounceCompletions.ts +++ b/src/debounceCompletions.ts @@ -1,7 +1,6 @@ import * as vscode from "vscode"; import { Capability, isCapabilityEnabled } from "./capabilities/capabilities"; import getInlineCompletionItems from "./getInlineCompletionItems"; -import TabnineInlineCompletionItem from "./inlineSuggestions/tabnineInlineCompletionItem"; import { sleep, timed } from "./utils/utils"; const ALPHA_ONE_SECOND_DEBOUNCE = 1000; @@ -10,9 +9,7 @@ export default async function debounceCompletions( document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken -): Promise< - vscode.InlineCompletionList | undefined -> { +): Promise { const { time, value: current } = await timed(() => getInlineCompletionItems(document, position, token) ); diff --git a/src/getInlineCompletionItems.ts b/src/getInlineCompletionItems.ts index 5a55730806..ff62552e85 100644 --- a/src/getInlineCompletionItems.ts +++ b/src/getInlineCompletionItems.ts @@ -10,7 +10,7 @@ export default async function getInlineCompletionItems( document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken -): Promise> { +): Promise { const response = await runCompletion({ document, position, diff --git a/src/inlineSuggestions/tabnineInlineCompletionItem.ts b/src/inlineSuggestions/tabnineInlineCompletionItem.ts index 9ade7315f9..671fb1e351 100644 --- a/src/inlineSuggestions/tabnineInlineCompletionItem.ts +++ b/src/inlineSuggestions/tabnineInlineCompletionItem.ts @@ -14,8 +14,6 @@ export default class TabnineInlineCompletionItem extends InlineCompletionItem { snippetContext?: SnippetContext; - insertText?: string; - constructor( text: string, suggestionEntry: ResultEntry, diff --git a/src/lookAheadSuggestion.ts b/src/lookAheadSuggestion.ts index 9d9547748b..bce6706a78 100644 --- a/src/lookAheadSuggestion.ts +++ b/src/lookAheadSuggestion.ts @@ -42,7 +42,7 @@ export async function getLookAheadSuggestion( { range, text }: SelectedCompletionInfo, position: Position, cancellationToken: CancellationToken -): Promise> { +): Promise { const textAtRange = document.getText(range); const isContainsCompletionInfo = text.startsWith(textAtRange); diff --git a/src/provideInlineCompletionItems.ts b/src/provideInlineCompletionItems.ts index c4b1482c46..8c98f6deb8 100644 --- a/src/provideInlineCompletionItems.ts +++ b/src/provideInlineCompletionItems.ts @@ -1,5 +1,4 @@ import * as vscode from "vscode"; -import TabnineInlineCompletionItem from "./inlineSuggestions/tabnineInlineCompletionItem"; import { completionIsAllowed } from "./provideCompletionItems"; import { getShouldComplete } from "./inlineSuggestions/documentChangesTracker"; import { @@ -18,9 +17,7 @@ export default async function provideInlineCompletionItems( position: vscode.Position, context: vscode.InlineCompletionContext, token: vscode.CancellationToken -): Promise< - vscode.InlineCompletionList | undefined -> { +): Promise { try { clearCurrentLookAheadSuggestion(); if ( diff --git a/src/reportSuggestionShown.ts b/src/reportSuggestionShown.ts index 1551d55776..2c20e24559 100644 --- a/src/reportSuggestionShown.ts +++ b/src/reportSuggestionShown.ts @@ -1,15 +1,16 @@ import * as vscode from "vscode"; -import TabnineInlineCompletionItem from "./inlineSuggestions/tabnineInlineCompletionItem"; import suggestionShown from "./binary/requests/suggestionShown"; import { ResultEntry } from "./binary/requests/requests"; +import TabnineInlineCompletionItem from "./inlineSuggestions/tabnineInlineCompletionItem"; let lastShownSuggestion: ResultEntry | undefined | null; export default function reportSuggestionShown( document: vscode.TextDocument, - completions?: vscode.InlineCompletionList + completions?: vscode.InlineCompletionList ): void { - const item = completions?.items[0]?.suggestionEntry; + const item = (completions?.items[0] as TabnineInlineCompletionItem) + .suggestionEntry; if (item && !lastShownSuggestion?.new_prefix.endsWith(item.new_prefix)) { void suggestionShown({ diff --git a/src/tabnineChatWidget/webviews/getIcon.ts b/src/tabnineChatWidget/webviews/getIcon.ts index 33fa115dc6..978a9162aa 100644 --- a/src/tabnineChatWidget/webviews/getIcon.ts +++ b/src/tabnineChatWidget/webviews/getIcon.ts @@ -4,6 +4,7 @@ const LOGO_BY_THEME = { [ColorThemeKind.Dark]: "tabnine-logo-dark.svg", [ColorThemeKind.Light]: "tabnine-logo-light.svg", [ColorThemeKind.HighContrast]: "logo.svg", + [ColorThemeKind.HighContrastLight]: "logo-light.svg", }; export function getIcon(context: ExtensionContext, view: Webview) { diff --git a/src/test/suite/utils/completion.utils.ts b/src/test/suite/utils/completion.utils.ts index afb7706f1c..d9186a91d0 100644 --- a/src/test/suite/utils/completion.utils.ts +++ b/src/test/suite/utils/completion.utils.ts @@ -10,7 +10,6 @@ import { SelectionStateRequest } from "../../../binary/requests/setState"; import { CompletionArguments } from "../../../CompletionArguments"; import { sleep } from "../../../utils/utils"; import { TAB_OVERRIDE_COMMAND } from "../../../globals/consts"; -import TabnineInlineCompletionItem from "../../../inlineSuggestions/tabnineInlineCompletionItem"; import provideInlineCompletionItems from "../../../provideInlineCompletionItems"; // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-argument @@ -116,9 +115,7 @@ export async function triggerSelectionAcceptance(): Promise { export async function getInlineCompletions( editor: vscode.TextEditor -): Promise< - vscode.InlineCompletionList | undefined -> { +): Promise { return provideInlineCompletionItems( editor.document, editor.selection.active, diff --git a/src/test/suite/utils/preReleaseInstaller.utils.ts b/src/test/suite/utils/preReleaseInstaller.utils.ts index 3e842401ef..07ee651796 100644 --- a/src/test/suite/utils/preReleaseInstaller.utils.ts +++ b/src/test/suite/utils/preReleaseInstaller.utils.ts @@ -110,6 +110,9 @@ export async function runInstallation( export function getContext(contextGetMocks: ContextGetMocks): ExtensionContext { return { globalState: { + keys() { + return []; + }, get: (key: string) => contextGetMocks[key], update: updateGlobalState, }, diff --git a/src/utils/logo.utils.ts b/src/utils/logo.utils.ts index 7828186371..0e2c996b71 100644 --- a/src/utils/logo.utils.ts +++ b/src/utils/logo.utils.ts @@ -5,6 +5,7 @@ export const LOGO_BY_THEME = { [ColorThemeKind.Light]: "logo-dark.svg", [ColorThemeKind.Dark]: "logo-light.svg", [ColorThemeKind.HighContrast]: "logo.svg", + [ColorThemeKind.HighContrastLight]: "logo-light.svg", }; export function getLogoPath(context: ExtensionContext): string { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5ad23c5b17..bce74b8212 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -96,8 +96,11 @@ export function trimEnd(str: string, suffix: string): string { return str.replace(new RegExp(`${escapeRegExp(suffix)}$`), ""); } -export function escapeTabStopSign(value: string): string { - return value.replace(new RegExp("\\$", "g"), "\\$"); +export function escapeTabStopSign( + value: string | vscode.SnippetString +): string { + const val = typeof value === "string" ? value : value.value; + return val.replace(new RegExp("\\$", "g"), "\\$"); } export function isMultiline(text?: string): boolean { diff --git a/src/vscode.proposed.inlineCompletions.d.ts b/src/vscode.proposed.inlineCompletions.d.ts deleted file mode 100644 index 438de75446..0000000000 --- a/src/vscode.proposed.inlineCompletions.d.ts +++ /dev/null @@ -1,145 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module "vscode" { - // https://github.com/microsoft/vscode/issues/124024 @hediet @alexdima - - export namespace languages { - /** - * Registers an inline completion provider. - */ - export function registerInlineCompletionItemProvider( - selector: DocumentSelector, - provider: InlineCompletionItemProvider - ): Disposable; - } - - export interface InlineCompletionItemProvider< - T extends InlineCompletionItem = InlineCompletionItem - > { - /** - * Provides inline completion items for the given position and document. - * If inline completions are enabled, this method will be called whenever the user stopped typing. - * It will also be called when the user explicitly triggers inline completions or asks for the next or previous inline completion. - * Use `context.triggerKind` to distinguish between these scenarios. - */ - provideInlineCompletionItems( - document: TextDocument, - position: Position, - context: InlineCompletionContext, - token: CancellationToken - ): ProviderResult | T[]>; - } - - export interface InlineCompletionContext { - /** - * How the completion was triggered. - */ - readonly triggerKind: InlineCompletionTriggerKind; - - /** - * Provides information about the currently selected item in the autocomplete widget if it is visible. - * - * If set, provided inline completions must extend the text of the selected item - * and use the same range, otherwise they are not shown as preview. - * As an example, if the document text is `console.` and the selected item is `.log` replacing the `.` in the document, - * the inline completion must also replace `.` and start with `.log`, for example `.log()`. - * - * Inline completion providers are requested again whenever the selected item changes. - * - * The user must configure `"editor.suggest.preview": true` for this feature. - */ - readonly selectedCompletionInfo: SelectedCompletionInfo | undefined; - } - - export interface SelectedCompletionInfo { - range: Range; - text: string; - completionKind: CompletionItemKind; - isSnippetText: boolean; - } - - /** - * How an {@link InlineCompletionItemProvider inline completion provider} was triggered. - */ - export enum InlineCompletionTriggerKind { - /** - * Completion was triggered automatically while editing. - * It is sufficient to return a single completion item in this case. - */ - Automatic = 0, - - /** - * Completion was triggered explicitly by a user gesture. - * Return multiple completion items to enable cycling through them. - */ - Explicit = 1, - } - - export class InlineCompletionList< - T extends InlineCompletionItem = InlineCompletionItem - > { - items: T[]; - - constructor(items: T[]); - } - - export class InlineCompletionItem { - /** - * The text to replace the range with. - * - * The text the range refers to should be a prefix of this value and must be a subword (`AB` and `BEF` are subwords of `ABCDEF`, but `Ab` is not). - */ - text: string; - - /** - * The range to replace. - * Must begin and end on the same line. - * - * Prefer replacements over insertions to avoid cache invalidation: - * Instead of reporting a completion that inserts an extension at the end of a word, - * the whole word should be replaced with the extended word. - */ - range?: Range; - - /** - * An optional {@link Command} that is executed *after* inserting this completion. - */ - command?: Command; - - constructor(text: string, range?: Range, command?: Command); - } - - /** - * Be aware that this API will not ever be finalized. - */ - export namespace window { - export function getInlineCompletionItemController< - T extends InlineCompletionItem - >(provider: InlineCompletionItemProvider): InlineCompletionController; - } - - /** - * Be aware that this API will not ever be finalized. - */ - export interface InlineCompletionController { - /** - * Is fired when an inline completion item is shown to the user. - */ - // eslint-disable-next-line vscode-dts-event-naming - readonly onDidShowCompletionItem: Event< - InlineCompletionItemDidShowEvent - >; - } - - /** - * Be aware that this API will not ever be finalized. - */ - export interface InlineCompletionItemDidShowEvent< - T extends InlineCompletionItem - > { - completionItem: T; - } -} diff --git a/yarn.lock b/yarn.lock index 9c5f5f86be..47a4b01e2e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -332,10 +332,10 @@ resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.11.15.tgz#29c776daecf6f1935da9adda17509686bf979947" integrity sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g== -"@types/vscode@^1.50.0": - version "1.55.0" - resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.55.0.tgz#58cfbebbd32b3e374e07e7858b1fd0e92b1a1d2b" - integrity sha512-49hysH7jneTQoSC8TWbAi7nKK9Lc5osQNjmDHVosrcU8o3jecD9GrK0Qyul8q4aGPSXRfNGqIp9CBdb13akETg== +"@types/vscode@^1.55.0": + version "1.85.0" + resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.85.0.tgz#46beb07f0f626665b52d1e2294382b2bc63b602e" + integrity sha512-CF/RBon/GXwdfmnjZj0WTUMZN5H6YITOfBCP4iEZlOtVQXuzw6t7Le7+cR+7JzdMrnlm7Mfp49Oj2TuSXIWo3g== "@types/yauzl@^2.9.1": version "2.9.1"