mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-02 23:05:15 +01:00
Finalize LanguageConfiguration.autoClosingPairs (#193197)
Finalize LanguageConfiguration.autoClosingPairs
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Vendored
+44
@@ -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.
|
||||
|
||||
@@ -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[];
|
||||
}[];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user