From 63fa4bccfb8f39631f049da482bbe91ec81228d3 Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Mon, 18 Sep 2023 18:01:25 +0200 Subject: [PATCH] Finalize `LanguageConfiguration.autoClosingPairs` (#193197) Finalize LanguageConfiguration.autoClosingPairs --- .../workbench/api/common/extHost.api.impl.ts | 1 + .../api/common/extHostLanguageFeatures.ts | 23 +++++++--- src/vs/workbench/api/common/extHostTypes.ts | 18 ++++++++ .../common/extensionsApiProposals.ts | 1 - src/vscode-dts/vscode.d.ts | 44 +++++++++++++++++++ ...languageConfigurationAutoClosingPairs.d.ts | 17 ------- 6 files changed, 79 insertions(+), 25 deletions(-) delete mode 100644 src/vscode-dts/vscode.proposed.languageConfigurationAutoClosingPairs.d.ts diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index eaa75c565f9..e2a4841815e 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1509,6 +1509,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I TextEditorLineNumbersStyle: extHostTypes.TextEditorLineNumbersStyle, TextEditorRevealType: extHostTypes.TextEditorRevealType, TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind, + SyntaxTokenType: extHostTypes.SyntaxTokenType, TextDocumentChangeReason: extHostTypes.TextDocumentChangeReason, ThemeColor: extHostTypes.ThemeColor, ThemeIcon: extHostTypes.ThemeIcon, diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index ec2fbcebeef..f80c0f8d6b3 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -7,7 +7,7 @@ import { URI, UriComponents } from 'vs/base/common/uri'; import { equals, mixin } from 'vs/base/common/objects'; import type * as vscode from 'vscode'; import * as typeConvert from 'vs/workbench/api/common/extHostTypeConverters'; -import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, DocumentSymbol, SemanticTokensEdits, SemanticTokens, SemanticTokensEdit, Location, InlineCompletionTriggerKind, InternalDataTransferItem, CodeActionTriggerKind } from 'vs/workbench/api/common/extHostTypes'; +import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, DocumentSymbol, SemanticTokensEdits, SemanticTokens, SemanticTokensEdit, Location, InlineCompletionTriggerKind, InternalDataTransferItem, CodeActionTriggerKind, SyntaxTokenType } from 'vs/workbench/api/common/extHostTypes'; import { ISingleEditOperation } from 'vs/editor/common/core/editOperation'; import * as languages from 'vs/editor/common/languages'; import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments'; @@ -33,9 +33,10 @@ import { Cache } from './cache'; import { StopWatch } from 'vs/base/common/stopwatch'; import { isCancellationError, NotImplementedError } from 'vs/base/common/errors'; import { raceCancellationError } from 'vs/base/common/async'; -import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'; +import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'; import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry'; import { localize } from 'vs/nls'; +import { IAutoClosingPairConditional } from 'vs/editor/common/languages/languageConfiguration'; // --- adapter @@ -2564,6 +2565,18 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF return onEnterRules.map(ExtHostLanguageFeatures._serializeOnEnterRule); } + private static _serializeAutoClosingPair(autoClosingPair: vscode.AutoClosingPair): IAutoClosingPairConditional { + return { + open: autoClosingPair.open, + close: autoClosingPair.close, + notIn: autoClosingPair.notIn ? autoClosingPair.notIn.map(v => SyntaxTokenType.toString(v)) : undefined, + }; + } + + private static _serializeAutoClosingPairs(autoClosingPairs: vscode.AutoClosingPair[]): IAutoClosingPairConditional[] { + return autoClosingPairs.map(ExtHostLanguageFeatures._serializeAutoClosingPair); + } + setLanguageConfiguration(extension: IExtensionDescription, languageId: string, configuration: vscode.LanguageConfiguration): vscode.Disposable { const { wordPattern } = configuration; @@ -2589,10 +2602,6 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF `Do not use.`); } - if (configuration.autoClosingPairs) { - checkProposedApiEnabled(extension, 'languageConfigurationAutoClosingPairs'); - } - const handle = this._nextHandle(); const serializedConfiguration: extHostProtocol.ILanguageConfigurationDto = { comments: configuration.comments, @@ -2602,7 +2611,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF onEnterRules: configuration.onEnterRules ? ExtHostLanguageFeatures._serializeOnEnterRules(configuration.onEnterRules) : undefined, __electricCharacterSupport: configuration.__electricCharacterSupport, __characterPairSupport: configuration.__characterPairSupport, - autoClosingPairs: configuration.autoClosingPairs + autoClosingPairs: configuration.autoClosingPairs ? ExtHostLanguageFeatures._serializeAutoClosingPairs(configuration.autoClosingPairs) : undefined, }; this._proxy.$setLanguageConfiguration(handle, languageId, serializedConfiguration); diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 0f4dcb21281..b1ea9b94055 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -1872,6 +1872,24 @@ export namespace TextEditorSelectionChangeKind { } } +export enum SyntaxTokenType { + Other = 0, + Comment = 1, + String = 2, + RegEx = 3 +} +export namespace SyntaxTokenType { + export function toString(v: SyntaxTokenType | unknown): 'other' | 'comment' | 'string' | 'regex' { + switch (v) { + case SyntaxTokenType.Other: return 'other'; + case SyntaxTokenType.Comment: return 'comment'; + case SyntaxTokenType.String: return 'string'; + case SyntaxTokenType.RegEx: return 'regex'; + } + return 'other'; + } +} + @es5ClassCompat export class DocumentLink { diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index e57cd2a81b6..f10d182e0d5 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -55,7 +55,6 @@ export const allApiProposals = Object.freeze({ interactiveUserActions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts', interactiveWindow: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveWindow.d.ts', ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts', - languageConfigurationAutoClosingPairs: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageConfigurationAutoClosingPairs.d.ts', mappedEditsProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.mappedEditsProvider.d.ts', notebookCellExecutionState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookCellExecutionState.d.ts', notebookControllerAffinityHidden: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookControllerAffinityHidden.d.ts', diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index bb5573aac0e..53e139a1671 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -6216,6 +6216,46 @@ declare module 'vscode' { action: EnterAction; } + /** + * Enumeration of commonly encountered syntax token types. + */ + export enum SyntaxTokenType { + /** + * Everything except tokens that are part of comments, string literals and regular expressions. + */ + Other = 0, + /** + * A comment. + */ + Comment = 1, + /** + * A string literal. + */ + String = 2, + /** + * A regular expression. + */ + RegEx = 3 + } + + /** + * Describes pairs of strings where the close string will be automatically inserted when typing the opening string. + */ + export interface AutoClosingPair { + /** + * The string that will trigger the automatic insertion of the closing string. + */ + open: string; + /** + * The closing string that will be automatically inserted when typing the opening string. + */ + close: string; + /** + * A set of tokens where the pair should not be auto closed. + */ + notIn?: SyntaxTokenType[]; + } + /** * The language configuration interfaces defines the contract between extensions * and various editor features, like automatic bracket insertion, automatic indentation etc. @@ -6246,6 +6286,10 @@ declare module 'vscode' { * The language's rules to be evaluated when pressing Enter. */ onEnterRules?: OnEnterRule[]; + /** + * The language's auto closing pairs. + */ + autoClosingPairs?: AutoClosingPair[]; /** * **Deprecated** Do not use. diff --git a/src/vscode-dts/vscode.proposed.languageConfigurationAutoClosingPairs.d.ts b/src/vscode-dts/vscode.proposed.languageConfigurationAutoClosingPairs.d.ts deleted file mode 100644 index 3cea4fdf090..00000000000 --- a/src/vscode-dts/vscode.proposed.languageConfigurationAutoClosingPairs.d.ts +++ /dev/null @@ -1,17 +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/173738 @alexdima - - export interface LanguageConfiguration { - autoClosingPairs?: { - open: string; - close: string; - notIn?: string[]; - }[]; - } -}