rename OnTypeRename -> LinkedEditing (for #109923)
This commit is contained in:
parent
f13720627f
commit
627ad0b4ee
|
@ -27,8 +27,8 @@ namespace CustomDataChangedNotification {
|
|||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string, any, any> = new RequestType('html/tag');
|
||||
}
|
||||
namespace OnTypeRenameRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, LspRange[] | null, any, any> = new RequestType('html/onTypeRename');
|
||||
namespace LinkedEditingRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, LspRange[] | null, any, any> = new RequestType('html/linkedEditing');
|
||||
}
|
||||
|
||||
// experimental: semantic tokens
|
||||
|
@ -44,7 +44,7 @@ namespace SemanticTokenLegendRequest {
|
|||
}
|
||||
|
||||
namespace SettingIds {
|
||||
export const renameOnType = 'editor.renameOnType';
|
||||
export const linkedRename = 'editor.linkedRename';
|
||||
export const formatEnable = 'html.format.enable';
|
||||
|
||||
}
|
||||
|
@ -169,10 +169,10 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
|||
}
|
||||
});
|
||||
|
||||
disposable = languages.registerOnTypeRenameRangeProvider(documentSelector, {
|
||||
async provideOnTypeRenameRanges(document, position) {
|
||||
disposable = languages.registerLinkedEditingRangeProvider(documentSelector, {
|
||||
async provideLinkedEditingRanges(document, position) {
|
||||
const param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
|
||||
return client.sendRequest(OnTypeRenameRequest.type, param).then(response => {
|
||||
return client.sendRequest(LinkedEditingRequest.type, param).then(response => {
|
||||
if (response) {
|
||||
return {
|
||||
ranges: response.map(r => client.protocol2CodeConverter.asRange(r))
|
||||
|
@ -301,7 +301,7 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
|||
const promptForTypeOnRenameKey = 'html.promptForTypeOnRename';
|
||||
const promptForTypeOnRename = extensions.getExtension('formulahendry.auto-rename-tag') !== undefined &&
|
||||
(context.globalState.get(promptForTypeOnRenameKey) !== false) &&
|
||||
!workspace.getConfiguration('editor', { languageId: 'html' }).get('renameOnType');
|
||||
!workspace.getConfiguration('editor', { languageId: 'html' }).get('linkedRename');
|
||||
|
||||
if (promptForTypeOnRename) {
|
||||
const activeEditorListener = window.onDidChangeActiveTextEditor(async e => {
|
||||
|
@ -309,9 +309,9 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
|||
context.globalState.update(promptForTypeOnRenameKey, false);
|
||||
activeEditorListener.dispose();
|
||||
const configure = localize('configureButton', 'Configure');
|
||||
const res = await window.showInformationMessage(localize('renameOnTypeQuestion', 'VS Code now has built-in support for auto-renaming tags. Do you want to enable it?'), configure);
|
||||
const res = await window.showInformationMessage(localize('linkedRenameQuestion', 'VS Code now has built-in support for auto-renaming tags. Do you want to enable it?'), configure);
|
||||
if (res === configure) {
|
||||
commands.executeCommand('workbench.action.openSettings', SettingIds.renameOnType);
|
||||
commands.executeCommand('workbench.action.openSettings', SettingIds.linkedRename);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -29,5 +29,5 @@
|
|||
"html.validate.styles": "Controls whether the built-in HTML language support validates embedded styles.",
|
||||
"html.autoClosingTags": "Enable/disable autoclosing of HTML tags.",
|
||||
"html.mirrorCursorOnMatchingTag": "Enable/disable mirroring cursor on matching HTML tag.",
|
||||
"html.mirrorCursorOnMatchingTagDeprecationMessage": "Deprecated in favor of `editor.renameOnType`"
|
||||
"html.mirrorCursorOnMatchingTagDeprecationMessage": "Deprecated in favor of `editor.linkedEditing`"
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace CustomDataChangedNotification {
|
|||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string | null, any, any> = new RequestType('html/tag');
|
||||
}
|
||||
namespace OnTypeRenameRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/onTypeRename');
|
||||
namespace LinkedEditingRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/linkedEditing');
|
||||
}
|
||||
|
||||
// experimental: semantic tokens
|
||||
|
@ -508,15 +508,15 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
|||
}, null, `Error while computing rename for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
connection.onRequest(OnTypeRenameRequest.type, (params, token) => {
|
||||
connection.onRequest(LinkedEditingRequest.type, (params, token) => {
|
||||
return runSafe(async () => {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
const pos = params.position;
|
||||
if (pos.character > 0) {
|
||||
const mode = languageModes.getModeAtPosition(document, Position.create(pos.line, pos.character - 1));
|
||||
if (mode && mode.doOnTypeRename) {
|
||||
return mode.doOnTypeRename(document, pos);
|
||||
if (mode && mode.doLinkedEditing) {
|
||||
return mode.doLinkedEditing(document, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
|||
const htmlDocument = htmlDocuments.get(document);
|
||||
return htmlLanguageService.findMatchingTagPosition(document, position, htmlDocument);
|
||||
},
|
||||
async doOnTypeRename(document: TextDocument, position: Position) {
|
||||
async doLinkedEditing(document: TextDocument, position: Position) {
|
||||
const htmlDocument = htmlDocuments.get(document);
|
||||
return htmlLanguageService.findOnTypeRenameRanges(document, position, htmlDocument);
|
||||
},
|
||||
|
|
|
@ -48,7 +48,7 @@ export interface LanguageMode {
|
|||
doHover?: (document: TextDocument, position: Position) => Promise<Hover | null>;
|
||||
doSignatureHelp?: (document: TextDocument, position: Position) => Promise<SignatureHelp | null>;
|
||||
doRename?: (document: TextDocument, position: Position, newName: string) => Promise<WorkspaceEdit | null>;
|
||||
doOnTypeRename?: (document: TextDocument, position: Position) => Promise<Range[] | null>;
|
||||
doLinkedEditing?: (document: TextDocument, position: Position) => Promise<Range[] | null>;
|
||||
findDocumentHighlight?: (document: TextDocument, position: Position) => Promise<DocumentHighlight[]>;
|
||||
findDocumentSymbols?: (document: TextDocument) => Promise<SymbolInformation[]>;
|
||||
findDocumentLinks?: (document: TextDocument, documentContext: DocumentContext) => Promise<DocumentLink[]>;
|
||||
|
|
|
@ -144,9 +144,13 @@ export interface IEditorOptions {
|
|||
*/
|
||||
readOnly?: boolean;
|
||||
/**
|
||||
* Rename matching regions on type.
|
||||
* Enable linked editing.
|
||||
* Defaults to false.
|
||||
*/
|
||||
linkedEditing?: boolean;
|
||||
/**
|
||||
* deprecated, use linkedEditing instead
|
||||
*/
|
||||
renameOnType?: boolean;
|
||||
/**
|
||||
* Should the editor render validation decorations.
|
||||
|
@ -3682,6 +3686,7 @@ export const enum EditorOption {
|
|||
lineHeight,
|
||||
lineNumbers,
|
||||
lineNumbersMinChars,
|
||||
linkedEditing,
|
||||
links,
|
||||
matchBrackets,
|
||||
minimap,
|
||||
|
@ -4033,6 +4038,10 @@ export const EditorOptions = {
|
|||
EditorOption.lineNumbersMinChars, 'lineNumbersMinChars',
|
||||
5, 1, 300
|
||||
)),
|
||||
linkedEditing: register(new EditorBooleanOption(
|
||||
EditorOption.linkedEditing, 'linkedEditing', false,
|
||||
{ description: nls.localize('linkedEditing', "Controls whether the editor has linked editing enabled. Depending on the language, related symbols, e.g. HTML tags, are updated while editing.") }
|
||||
)),
|
||||
links: register(new EditorBooleanOption(
|
||||
EditorOption.links, 'links', true,
|
||||
{ description: nls.localize('links', "Controls whether the editor should detect links and make them clickable.") }
|
||||
|
@ -4134,7 +4143,7 @@ export const EditorOptions = {
|
|||
)),
|
||||
renameOnType: register(new EditorBooleanOption(
|
||||
EditorOption.renameOnType, 'renameOnType', false,
|
||||
{ description: nls.localize('renameOnType', "Controls whether the editor auto renames on type.") }
|
||||
{ description: nls.localize('renameOnType', "Controls whether the editor auto renames on type."), markdownDeprecationMessage: nls.localize('renameOnTypeDeprecate', "Deprecated, use `editor.linkedEditing` instead.") }
|
||||
)),
|
||||
renderControlCharacters: register(new EditorBooleanOption(
|
||||
EditorOption.renderControlCharacters, 'renderControlCharacters', false,
|
||||
|
|
|
@ -819,24 +819,24 @@ export interface DocumentHighlightProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* The rename range provider interface defines the contract between extensions and
|
||||
* the live-rename feature.
|
||||
* The linked editing range provider interface defines the contract between extensions and
|
||||
* the linked editing feature.
|
||||
*/
|
||||
export interface OnTypeRenameRangeProvider {
|
||||
export interface LinkedEditingRangeProvider {
|
||||
|
||||
/**
|
||||
* Provide a list of ranges that can be live-renamed together.
|
||||
* Provide a list of ranges that can be edited together.
|
||||
*/
|
||||
provideOnTypeRenameRanges(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<OnTypeRenameRanges>;
|
||||
provideLinkedEditingRanges(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a list of ranges that can be renamed together along with a word pattern to describe valid range contents.
|
||||
* Represents a list of ranges that can be edited together along with a word pattern to describe valid contents.
|
||||
*/
|
||||
export interface OnTypeRenameRanges {
|
||||
export interface LinkedEditingRanges {
|
||||
/**
|
||||
* A list of ranges that can be renamed together. The ranges must have
|
||||
* identical length and contain identical text content. The ranges cannot overlap
|
||||
* A list of ranges that can be edited together. The ranges must have
|
||||
* identical length and text content. The ranges cannot overlap
|
||||
*/
|
||||
ranges: IRange[];
|
||||
|
||||
|
@ -1737,7 +1737,7 @@ export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<Doc
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const OnTypeRenameRangeProviderRegistry = new LanguageFeatureRegistry<OnTypeRenameRangeProvider>();
|
||||
export const LinkedEditingRangeProviderRegistry = new LanguageFeatureRegistry<LinkedEditingRangeProvider>();
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
|
|
@ -224,72 +224,73 @@ export enum EditorOption {
|
|||
lineHeight = 54,
|
||||
lineNumbers = 55,
|
||||
lineNumbersMinChars = 56,
|
||||
links = 57,
|
||||
matchBrackets = 58,
|
||||
minimap = 59,
|
||||
mouseStyle = 60,
|
||||
mouseWheelScrollSensitivity = 61,
|
||||
mouseWheelZoom = 62,
|
||||
multiCursorMergeOverlapping = 63,
|
||||
multiCursorModifier = 64,
|
||||
multiCursorPaste = 65,
|
||||
occurrencesHighlight = 66,
|
||||
overviewRulerBorder = 67,
|
||||
overviewRulerLanes = 68,
|
||||
padding = 69,
|
||||
parameterHints = 70,
|
||||
peekWidgetDefaultFocus = 71,
|
||||
definitionLinkOpensInPeek = 72,
|
||||
quickSuggestions = 73,
|
||||
quickSuggestionsDelay = 74,
|
||||
readOnly = 75,
|
||||
renameOnType = 76,
|
||||
renderControlCharacters = 77,
|
||||
renderIndentGuides = 78,
|
||||
renderFinalNewline = 79,
|
||||
renderLineHighlight = 80,
|
||||
renderLineHighlightOnlyWhenFocus = 81,
|
||||
renderValidationDecorations = 82,
|
||||
renderWhitespace = 83,
|
||||
revealHorizontalRightPadding = 84,
|
||||
roundedSelection = 85,
|
||||
rulers = 86,
|
||||
scrollbar = 87,
|
||||
scrollBeyondLastColumn = 88,
|
||||
scrollBeyondLastLine = 89,
|
||||
scrollPredominantAxis = 90,
|
||||
selectionClipboard = 91,
|
||||
selectionHighlight = 92,
|
||||
selectOnLineNumbers = 93,
|
||||
showFoldingControls = 94,
|
||||
showUnused = 95,
|
||||
snippetSuggestions = 96,
|
||||
smartSelect = 97,
|
||||
smoothScrolling = 98,
|
||||
stopRenderingLineAfter = 99,
|
||||
suggest = 100,
|
||||
suggestFontSize = 101,
|
||||
suggestLineHeight = 102,
|
||||
suggestOnTriggerCharacters = 103,
|
||||
suggestSelection = 104,
|
||||
tabCompletion = 105,
|
||||
tabIndex = 106,
|
||||
unusualLineTerminators = 107,
|
||||
useTabStops = 108,
|
||||
wordSeparators = 109,
|
||||
wordWrap = 110,
|
||||
wordWrapBreakAfterCharacters = 111,
|
||||
wordWrapBreakBeforeCharacters = 112,
|
||||
wordWrapColumn = 113,
|
||||
wordWrapMinified = 114,
|
||||
wrappingIndent = 115,
|
||||
wrappingStrategy = 116,
|
||||
showDeprecated = 117,
|
||||
editorClassName = 118,
|
||||
pixelRatio = 119,
|
||||
tabFocusMode = 120,
|
||||
layoutInfo = 121,
|
||||
wrappingInfo = 122
|
||||
linkedEditing = 57,
|
||||
links = 58,
|
||||
matchBrackets = 59,
|
||||
minimap = 60,
|
||||
mouseStyle = 61,
|
||||
mouseWheelScrollSensitivity = 62,
|
||||
mouseWheelZoom = 63,
|
||||
multiCursorMergeOverlapping = 64,
|
||||
multiCursorModifier = 65,
|
||||
multiCursorPaste = 66,
|
||||
occurrencesHighlight = 67,
|
||||
overviewRulerBorder = 68,
|
||||
overviewRulerLanes = 69,
|
||||
padding = 70,
|
||||
parameterHints = 71,
|
||||
peekWidgetDefaultFocus = 72,
|
||||
definitionLinkOpensInPeek = 73,
|
||||
quickSuggestions = 74,
|
||||
quickSuggestionsDelay = 75,
|
||||
readOnly = 76,
|
||||
renameOnType = 77,
|
||||
renderControlCharacters = 78,
|
||||
renderIndentGuides = 79,
|
||||
renderFinalNewline = 80,
|
||||
renderLineHighlight = 81,
|
||||
renderLineHighlightOnlyWhenFocus = 82,
|
||||
renderValidationDecorations = 83,
|
||||
renderWhitespace = 84,
|
||||
revealHorizontalRightPadding = 85,
|
||||
roundedSelection = 86,
|
||||
rulers = 87,
|
||||
scrollbar = 88,
|
||||
scrollBeyondLastColumn = 89,
|
||||
scrollBeyondLastLine = 90,
|
||||
scrollPredominantAxis = 91,
|
||||
selectionClipboard = 92,
|
||||
selectionHighlight = 93,
|
||||
selectOnLineNumbers = 94,
|
||||
showFoldingControls = 95,
|
||||
showUnused = 96,
|
||||
snippetSuggestions = 97,
|
||||
smartSelect = 98,
|
||||
smoothScrolling = 99,
|
||||
stopRenderingLineAfter = 100,
|
||||
suggest = 101,
|
||||
suggestFontSize = 102,
|
||||
suggestLineHeight = 103,
|
||||
suggestOnTriggerCharacters = 104,
|
||||
suggestSelection = 105,
|
||||
tabCompletion = 106,
|
||||
tabIndex = 107,
|
||||
unusualLineTerminators = 108,
|
||||
useTabStops = 109,
|
||||
wordSeparators = 110,
|
||||
wordWrap = 111,
|
||||
wordWrapBreakAfterCharacters = 112,
|
||||
wordWrapBreakBeforeCharacters = 113,
|
||||
wordWrapColumn = 114,
|
||||
wordWrapMinified = 115,
|
||||
wrappingIndent = 116,
|
||||
wrappingStrategy = 117,
|
||||
showDeprecated = 118,
|
||||
editorClassName = 119,
|
||||
pixelRatio = 120,
|
||||
tabFocusMode = 121,
|
||||
layoutInfo = 122,
|
||||
wrappingInfo = 123
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,7 +14,7 @@ import { Position, IPosition } from 'vs/editor/common/core/position';
|
|||
import { ITextModel, IModelDeltaDecoration, TrackedRangeStickiness, IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { OnTypeRenameRangeProviderRegistry, OnTypeRenameRanges } from 'vs/editor/common/modes';
|
||||
import { LinkedEditingRangeProviderRegistry, LinkedEditingRanges } from 'vs/editor/common/modes';
|
||||
import { first, createCancelablePromise, CancelablePromise, Delayer } from 'vs/base/common/async';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { ContextKeyExpr, RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
@ -30,19 +30,21 @@ import { registerThemingParticipant } from 'vs/platform/theme/common/themeServic
|
|||
import { Color } from 'vs/base/common/color';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
|
||||
export const CONTEXT_ONTYPE_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('onTypeRenameInputVisible', false);
|
||||
export const CONTEXT_ONTYPE_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('LinkedEditingInputVisible', false);
|
||||
|
||||
export class OnTypeRenameContribution extends Disposable implements IEditorContribution {
|
||||
const DECORATION_CLASS_NAME = 'linked-editing-decoration';
|
||||
|
||||
public static readonly ID = 'editor.contrib.onTypeRename';
|
||||
export class LinkedEditingContribution extends Disposable implements IEditorContribution {
|
||||
|
||||
public static readonly ID = 'editor.contrib.linkedEditing';
|
||||
|
||||
private static readonly DECORATION = ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges,
|
||||
className: 'on-type-rename-decoration'
|
||||
className: DECORATION_CLASS_NAME
|
||||
});
|
||||
|
||||
static get(editor: ICodeEditor): OnTypeRenameContribution {
|
||||
return editor.getContribution<OnTypeRenameContribution>(OnTypeRenameContribution.ID);
|
||||
static get(editor: ICodeEditor): LinkedEditingContribution {
|
||||
return editor.getContribution<LinkedEditingContribution>(LinkedEditingContribution.ID);
|
||||
}
|
||||
|
||||
private _debounceDuration = 200;
|
||||
|
@ -91,11 +93,11 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
this._register(this._editor.onDidChangeModel(() => this.reinitialize()));
|
||||
|
||||
this._register(this._editor.onDidChangeConfiguration(e => {
|
||||
if (e.hasChanged(EditorOption.renameOnType)) {
|
||||
if (e.hasChanged(EditorOption.linkedEditing) || e.hasChanged(EditorOption.renameOnType)) {
|
||||
this.reinitialize();
|
||||
}
|
||||
}));
|
||||
this._register(OnTypeRenameRangeProviderRegistry.onDidChange(() => this.reinitialize()));
|
||||
this._register(LinkedEditingRangeProviderRegistry.onDidChange(() => this.reinitialize()));
|
||||
this._register(this._editor.onDidChangeModelLanguage(() => this.reinitialize()));
|
||||
|
||||
this.reinitialize();
|
||||
|
@ -103,7 +105,7 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
|
||||
private reinitialize() {
|
||||
const model = this._editor.getModel();
|
||||
const isEnabled = model !== null && this._editor.getOption(EditorOption.renameOnType) && OnTypeRenameRangeProviderRegistry.has(model);
|
||||
const isEnabled = model !== null && (this._editor.getOption(EditorOption.linkedEditing) || this._editor.getOption(EditorOption.renameOnType)) && LinkedEditingRangeProviderRegistry.has(model);
|
||||
if (isEnabled === this._enabled) {
|
||||
return;
|
||||
}
|
||||
|
@ -220,7 +222,7 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
try {
|
||||
this._ignoreChangeEvent = true;
|
||||
const prevEditOperationType = this._editor._getViewModel().getPrevEditOperationType();
|
||||
this._editor.executeEdits('onTypeRename', edits);
|
||||
this._editor.executeEdits('linkedEditing', edits);
|
||||
this._editor._getViewModel().setPrevEditOperationType(prevEditOperationType);
|
||||
} finally {
|
||||
this._ignoreChangeEvent = false;
|
||||
|
@ -281,7 +283,7 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
this._currentRequestModelVersion = modelVersionId;
|
||||
const request = createCancelablePromise(async token => {
|
||||
try {
|
||||
const response = await getOnTypeRenameRanges(model, position, token);
|
||||
const response = await getLinkedEditingRanges(model, position, token);
|
||||
if (request !== this._currentRequest) {
|
||||
return;
|
||||
}
|
||||
|
@ -311,12 +313,12 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
}
|
||||
|
||||
if (!foundReferenceRange) {
|
||||
// Cannot do on type rename if the ranges are not where the cursor is...
|
||||
// Cannot do linked editing if the ranges are not where the cursor is...
|
||||
this.clearRanges();
|
||||
return;
|
||||
}
|
||||
|
||||
const decorations: IModelDeltaDecoration[] = ranges.map(range => ({ range: range, options: OnTypeRenameContribution.DECORATION }));
|
||||
const decorations: IModelDeltaDecoration[] = ranges.map(range => ({ range: range, options: LinkedEditingContribution.DECORATION }));
|
||||
this._visibleContextKey.set(true);
|
||||
this._currentDecorations = this._editor.deltaDecorations(this._currentDecorations, decorations);
|
||||
} catch (err) {
|
||||
|
@ -360,12 +362,12 @@ export class OnTypeRenameContribution extends Disposable implements IEditorContr
|
|||
// }
|
||||
}
|
||||
|
||||
export class OnTypeRenameAction extends EditorAction {
|
||||
export class LinkedEditingAction extends EditorAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.onTypeRename',
|
||||
label: nls.localize('onTypeRename.label', "On Type Rename Symbol"),
|
||||
alias: 'On Type Rename Symbol',
|
||||
id: 'editor.action.linkedEditing',
|
||||
label: nls.localize('linkedEditing.label', "Start Linked Editing"),
|
||||
alias: 'Start Linked Editing',
|
||||
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasRenameProvider),
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.editorTextFocus,
|
||||
|
@ -396,7 +398,7 @@ export class OnTypeRenameAction extends EditorAction {
|
|||
}
|
||||
|
||||
run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
|
||||
const controller = OnTypeRenameContribution.get(editor);
|
||||
const controller = LinkedEditingContribution.get(editor);
|
||||
if (controller) {
|
||||
return Promise.resolve(controller.updateRanges(true));
|
||||
}
|
||||
|
@ -404,9 +406,9 @@ export class OnTypeRenameAction extends EditorAction {
|
|||
}
|
||||
}
|
||||
|
||||
const OnTypeRenameCommand = EditorCommand.bindToContribution<OnTypeRenameContribution>(OnTypeRenameContribution.get);
|
||||
registerEditorCommand(new OnTypeRenameCommand({
|
||||
id: 'cancelOnTypeRenameInput',
|
||||
const LinkedEditingCommand = EditorCommand.bindToContribution<LinkedEditingContribution>(LinkedEditingContribution.get);
|
||||
registerEditorCommand(new LinkedEditingCommand({
|
||||
id: 'cancelLinkedEditingInput',
|
||||
precondition: CONTEXT_ONTYPE_RENAME_INPUT_VISIBLE,
|
||||
handler: x => x.clearRanges(),
|
||||
kbOpts: {
|
||||
|
@ -418,15 +420,15 @@ registerEditorCommand(new OnTypeRenameCommand({
|
|||
}));
|
||||
|
||||
|
||||
function getOnTypeRenameRanges(model: ITextModel, position: Position, token: CancellationToken): Promise<OnTypeRenameRanges | undefined | null> {
|
||||
const orderedByScore = OnTypeRenameRangeProviderRegistry.ordered(model);
|
||||
function getLinkedEditingRanges(model: ITextModel, position: Position, token: CancellationToken): Promise<LinkedEditingRanges | undefined | null> {
|
||||
const orderedByScore = LinkedEditingRangeProviderRegistry.ordered(model);
|
||||
|
||||
// in order of score ask the on type rename provider
|
||||
// in order of score ask the linked editing range provider
|
||||
// until someone response with a good result
|
||||
// (good = not null)
|
||||
return first<OnTypeRenameRanges | undefined | null>(orderedByScore.map(provider => async () => {
|
||||
return first<LinkedEditingRanges | undefined | null>(orderedByScore.map(provider => async () => {
|
||||
try {
|
||||
return await provider.provideOnTypeRenameRanges(model, position, token);
|
||||
return await provider.provideLinkedEditingRanges(model, position, token);
|
||||
} catch (e) {
|
||||
onUnexpectedExternalError(e);
|
||||
return undefined;
|
||||
|
@ -434,15 +436,15 @@ function getOnTypeRenameRanges(model: ITextModel, position: Position, token: Can
|
|||
}), result => !!result && arrays.isNonEmptyArray(result?.ranges));
|
||||
}
|
||||
|
||||
export const editorOnTypeRenameBackground = registerColor('editor.onTypeRenameBackground', { dark: Color.fromHex('#f00').transparent(0.3), light: Color.fromHex('#f00').transparent(0.3), hc: Color.fromHex('#f00').transparent(0.3) }, nls.localize('editorOnTypeRenameBackground', 'Background color when the editor auto renames on type.'));
|
||||
export const editorLinkedEditingBackground = registerColor('editor.linkedEditingBackground', { dark: Color.fromHex('#f00').transparent(0.3), light: Color.fromHex('#f00').transparent(0.3), hc: Color.fromHex('#f00').transparent(0.3) }, nls.localize('editorLinkedEditingBackground', 'Background color when the editor auto renames on type.'));
|
||||
registerThemingParticipant((theme, collector) => {
|
||||
const editorOnTypeRenameBackgroundColor = theme.getColor(editorOnTypeRenameBackground);
|
||||
if (editorOnTypeRenameBackgroundColor) {
|
||||
collector.addRule(`.monaco-editor .on-type-rename-decoration { background: ${editorOnTypeRenameBackgroundColor}; border-left-color: ${editorOnTypeRenameBackgroundColor}; }`);
|
||||
const editorLinkedEditingBackgroundColor = theme.getColor(editorLinkedEditingBackground);
|
||||
if (editorLinkedEditingBackgroundColor) {
|
||||
collector.addRule(`.monaco-editor .${DECORATION_CLASS_NAME} { background: ${editorLinkedEditingBackgroundColor}; border-left-color: ${editorLinkedEditingBackgroundColor}; }`);
|
||||
}
|
||||
});
|
||||
|
||||
registerModelAndPositionCommand('_executeRenameOnTypeProvider', (model, position) => getOnTypeRenameRanges(model, position, CancellationToken.None));
|
||||
registerModelAndPositionCommand('_executeLinkedEditingProvider', (model, position) => getLinkedEditingRanges(model, position, CancellationToken.None));
|
||||
|
||||
registerEditorContribution(OnTypeRenameContribution.ID, OnTypeRenameContribution);
|
||||
registerEditorAction(OnTypeRenameAction);
|
||||
registerEditorContribution(LinkedEditingContribution.ID, LinkedEditingContribution);
|
||||
registerEditorAction(LinkedEditingAction);
|
|
@ -10,7 +10,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
|
|||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { OnTypeRenameContribution } from 'vs/editor/contrib/rename/onTypeRename';
|
||||
import { LinkedEditingContribution } from 'vs/editor/contrib/linkedEditing/linkedEditing';
|
||||
import { createTestCodeEditor, ITestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
|
@ -30,12 +30,12 @@ interface TestEditor {
|
|||
redo(): void;
|
||||
}
|
||||
|
||||
const languageIdentifier = new modes.LanguageIdentifier('onTypeRenameTestLangage', 74);
|
||||
const languageIdentifier = new modes.LanguageIdentifier('linkedEditingTestLangage', 74);
|
||||
LanguageConfigurationRegistry.register(languageIdentifier, {
|
||||
wordPattern: /[a-zA-Z]+/
|
||||
});
|
||||
|
||||
suite('On type rename', () => {
|
||||
suite('linked editing', () => {
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
setup(() => {
|
||||
|
@ -66,8 +66,8 @@ suite('On type rename', () => {
|
|||
expectedEndText: string | string[]
|
||||
) {
|
||||
test(name, async () => {
|
||||
disposables.add(modes.OnTypeRenameRangeProviderRegistry.register(mockFileSelector, {
|
||||
provideOnTypeRenameRanges(model: ITextModel, pos: IPosition) {
|
||||
disposables.add(modes.LinkedEditingRangeProviderRegistry.register(mockFileSelector, {
|
||||
provideLinkedEditingRanges(model: ITextModel, pos: IPosition) {
|
||||
const wordAtPos = model.getWordAtPosition(pos);
|
||||
if (wordAtPos) {
|
||||
const matches = model.findMatches(wordAtPos.word, false, false, true, USUAL_WORD_SEPARATORS, false);
|
||||
|
@ -78,25 +78,25 @@ suite('On type rename', () => {
|
|||
}));
|
||||
|
||||
const editor = createMockEditor(initialState.text);
|
||||
editor.updateOptions({ renameOnType: true });
|
||||
const ontypeRenameContribution = editor.registerAndInstantiateContribution(
|
||||
OnTypeRenameContribution.ID,
|
||||
OnTypeRenameContribution
|
||||
editor.updateOptions({ linkedEditing: true });
|
||||
const linkedEditingContribution = editor.registerAndInstantiateContribution(
|
||||
LinkedEditingContribution.ID,
|
||||
LinkedEditingContribution
|
||||
);
|
||||
ontypeRenameContribution.setDebounceDuration(0);
|
||||
linkedEditingContribution.setDebounceDuration(0);
|
||||
|
||||
const testEditor: TestEditor = {
|
||||
setPosition(pos: Position) {
|
||||
editor.setPosition(pos);
|
||||
return ontypeRenameContribution.currentUpdateTriggerPromise;
|
||||
return linkedEditingContribution.currentUpdateTriggerPromise;
|
||||
},
|
||||
setSelection(sel: IRange) {
|
||||
editor.setSelection(sel);
|
||||
return ontypeRenameContribution.currentUpdateTriggerPromise;
|
||||
return linkedEditingContribution.currentUpdateTriggerPromise;
|
||||
},
|
||||
trigger(source: string | null | undefined, handlerId: string, payload: any) {
|
||||
editor.trigger(source, handlerId, payload);
|
||||
return ontypeRenameContribution.currentSyncTriggerPromise;
|
||||
return linkedEditingContribution.currentSyncTriggerPromise;
|
||||
},
|
||||
undo() {
|
||||
CoreEditingCommands.Undo.runEditorCommand(null, editor, null);
|
||||
|
@ -251,7 +251,7 @@ suite('On type rename', () => {
|
|||
// testCase('Selection insert - across two boundary', state, async (editor) => {
|
||||
// const pos = new Position(1, 2);
|
||||
// await editor.setPosition(pos);
|
||||
// await ontypeRenameContribution.updateLinkedUI(pos);
|
||||
// await linkedEditingContribution.updateLinkedUI(pos);
|
||||
// await editor.setSelection(new Range(1, 4, 1, 9));
|
||||
// await editor.trigger('keyboard', Handler.Type, { text: 'i' });
|
||||
// }, '<ooioo>');
|
||||
|
@ -383,7 +383,7 @@ suite('On type rename', () => {
|
|||
// testCase('Delete - left all', state, async (editor) => {
|
||||
// const pos = new Position(1, 3);
|
||||
// await editor.setPosition(pos);
|
||||
// await ontypeRenameContribution.updateLinkedUI(pos);
|
||||
// await linkedEditingContribution.updateLinkedUI(pos);
|
||||
// await editor.trigger('keyboard', 'deleteAllLeft', {});
|
||||
// }, '></>');
|
||||
|
||||
|
@ -393,7 +393,7 @@ suite('On type rename', () => {
|
|||
// testCase('Delete - left all then undo', state, async (editor) => {
|
||||
// const pos = new Position(1, 5);
|
||||
// await editor.setPosition(pos);
|
||||
// await ontypeRenameContribution.updateLinkedUI(pos);
|
||||
// await linkedEditingContribution.updateLinkedUI(pos);
|
||||
// await editor.trigger('keyboard', 'deleteAllLeft', {});
|
||||
// editor.undo();
|
||||
// }, '></ooo>');
|
|
@ -31,10 +31,10 @@ import 'vs/editor/contrib/hover/hover';
|
|||
import 'vs/editor/contrib/indentation/indentation';
|
||||
import 'vs/editor/contrib/inPlaceReplace/inPlaceReplace';
|
||||
import 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import 'vs/editor/contrib/linkedEditing/linkedEditing';
|
||||
import 'vs/editor/contrib/links/links';
|
||||
import 'vs/editor/contrib/multicursor/multicursor';
|
||||
import 'vs/editor/contrib/parameterHints/parameterHints';
|
||||
import 'vs/editor/contrib/rename/onTypeRename';
|
||||
import 'vs/editor/contrib/rename/rename';
|
||||
import 'vs/editor/contrib/smartSelect/smartSelect';
|
||||
import 'vs/editor/contrib/snippet/snippetController2';
|
||||
|
|
|
@ -392,10 +392,10 @@ export function registerDocumentHighlightProvider(languageId: string, provider:
|
|||
}
|
||||
|
||||
/**
|
||||
* Register an on type rename range provider.
|
||||
* Register an linked editing range provider.
|
||||
*/
|
||||
export function registerOnTypeRenameRangeProvider(languageId: string, provider: modes.OnTypeRenameRangeProvider): IDisposable {
|
||||
return modes.OnTypeRenameRangeProviderRegistry.register(languageId, provider);
|
||||
export function registerLinkedEditingRangeProvider(languageId: string, provider: modes.LinkedEditingRangeProvider): IDisposable {
|
||||
return modes.LinkedEditingRangeProviderRegistry.register(languageId, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -566,7 +566,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
|
|||
registerHoverProvider: <any>registerHoverProvider,
|
||||
registerDocumentSymbolProvider: <any>registerDocumentSymbolProvider,
|
||||
registerDocumentHighlightProvider: <any>registerDocumentHighlightProvider,
|
||||
registerOnTypeRenameRangeProvider: <any>registerOnTypeRenameRangeProvider,
|
||||
registerLinkedEditingRangeProvider: <any>registerLinkedEditingRangeProvider,
|
||||
registerDefinitionProvider: <any>registerDefinitionProvider,
|
||||
registerImplementationProvider: <any>registerImplementationProvider,
|
||||
registerTypeDefinitionProvider: <any>registerTypeDefinitionProvider,
|
||||
|
|
162
src/vs/monaco.d.ts
vendored
162
src/vs/monaco.d.ts
vendored
|
@ -2691,9 +2691,13 @@ declare namespace monaco.editor {
|
|||
*/
|
||||
readOnly?: boolean;
|
||||
/**
|
||||
* Rename matching regions on type.
|
||||
* Enable linked editing.
|
||||
* Defaults to false.
|
||||
*/
|
||||
linkedEditing?: boolean;
|
||||
/**
|
||||
* deprecated, use linkedEditing instead
|
||||
*/
|
||||
renameOnType?: boolean;
|
||||
/**
|
||||
* Should the editor render validation decorations.
|
||||
|
@ -3949,72 +3953,73 @@ declare namespace monaco.editor {
|
|||
lineHeight = 54,
|
||||
lineNumbers = 55,
|
||||
lineNumbersMinChars = 56,
|
||||
links = 57,
|
||||
matchBrackets = 58,
|
||||
minimap = 59,
|
||||
mouseStyle = 60,
|
||||
mouseWheelScrollSensitivity = 61,
|
||||
mouseWheelZoom = 62,
|
||||
multiCursorMergeOverlapping = 63,
|
||||
multiCursorModifier = 64,
|
||||
multiCursorPaste = 65,
|
||||
occurrencesHighlight = 66,
|
||||
overviewRulerBorder = 67,
|
||||
overviewRulerLanes = 68,
|
||||
padding = 69,
|
||||
parameterHints = 70,
|
||||
peekWidgetDefaultFocus = 71,
|
||||
definitionLinkOpensInPeek = 72,
|
||||
quickSuggestions = 73,
|
||||
quickSuggestionsDelay = 74,
|
||||
readOnly = 75,
|
||||
renameOnType = 76,
|
||||
renderControlCharacters = 77,
|
||||
renderIndentGuides = 78,
|
||||
renderFinalNewline = 79,
|
||||
renderLineHighlight = 80,
|
||||
renderLineHighlightOnlyWhenFocus = 81,
|
||||
renderValidationDecorations = 82,
|
||||
renderWhitespace = 83,
|
||||
revealHorizontalRightPadding = 84,
|
||||
roundedSelection = 85,
|
||||
rulers = 86,
|
||||
scrollbar = 87,
|
||||
scrollBeyondLastColumn = 88,
|
||||
scrollBeyondLastLine = 89,
|
||||
scrollPredominantAxis = 90,
|
||||
selectionClipboard = 91,
|
||||
selectionHighlight = 92,
|
||||
selectOnLineNumbers = 93,
|
||||
showFoldingControls = 94,
|
||||
showUnused = 95,
|
||||
snippetSuggestions = 96,
|
||||
smartSelect = 97,
|
||||
smoothScrolling = 98,
|
||||
stopRenderingLineAfter = 99,
|
||||
suggest = 100,
|
||||
suggestFontSize = 101,
|
||||
suggestLineHeight = 102,
|
||||
suggestOnTriggerCharacters = 103,
|
||||
suggestSelection = 104,
|
||||
tabCompletion = 105,
|
||||
tabIndex = 106,
|
||||
unusualLineTerminators = 107,
|
||||
useTabStops = 108,
|
||||
wordSeparators = 109,
|
||||
wordWrap = 110,
|
||||
wordWrapBreakAfterCharacters = 111,
|
||||
wordWrapBreakBeforeCharacters = 112,
|
||||
wordWrapColumn = 113,
|
||||
wordWrapMinified = 114,
|
||||
wrappingIndent = 115,
|
||||
wrappingStrategy = 116,
|
||||
showDeprecated = 117,
|
||||
editorClassName = 118,
|
||||
pixelRatio = 119,
|
||||
tabFocusMode = 120,
|
||||
layoutInfo = 121,
|
||||
wrappingInfo = 122
|
||||
linkedEditing = 57,
|
||||
links = 58,
|
||||
matchBrackets = 59,
|
||||
minimap = 60,
|
||||
mouseStyle = 61,
|
||||
mouseWheelScrollSensitivity = 62,
|
||||
mouseWheelZoom = 63,
|
||||
multiCursorMergeOverlapping = 64,
|
||||
multiCursorModifier = 65,
|
||||
multiCursorPaste = 66,
|
||||
occurrencesHighlight = 67,
|
||||
overviewRulerBorder = 68,
|
||||
overviewRulerLanes = 69,
|
||||
padding = 70,
|
||||
parameterHints = 71,
|
||||
peekWidgetDefaultFocus = 72,
|
||||
definitionLinkOpensInPeek = 73,
|
||||
quickSuggestions = 74,
|
||||
quickSuggestionsDelay = 75,
|
||||
readOnly = 76,
|
||||
renameOnType = 77,
|
||||
renderControlCharacters = 78,
|
||||
renderIndentGuides = 79,
|
||||
renderFinalNewline = 80,
|
||||
renderLineHighlight = 81,
|
||||
renderLineHighlightOnlyWhenFocus = 82,
|
||||
renderValidationDecorations = 83,
|
||||
renderWhitespace = 84,
|
||||
revealHorizontalRightPadding = 85,
|
||||
roundedSelection = 86,
|
||||
rulers = 87,
|
||||
scrollbar = 88,
|
||||
scrollBeyondLastColumn = 89,
|
||||
scrollBeyondLastLine = 90,
|
||||
scrollPredominantAxis = 91,
|
||||
selectionClipboard = 92,
|
||||
selectionHighlight = 93,
|
||||
selectOnLineNumbers = 94,
|
||||
showFoldingControls = 95,
|
||||
showUnused = 96,
|
||||
snippetSuggestions = 97,
|
||||
smartSelect = 98,
|
||||
smoothScrolling = 99,
|
||||
stopRenderingLineAfter = 100,
|
||||
suggest = 101,
|
||||
suggestFontSize = 102,
|
||||
suggestLineHeight = 103,
|
||||
suggestOnTriggerCharacters = 104,
|
||||
suggestSelection = 105,
|
||||
tabCompletion = 106,
|
||||
tabIndex = 107,
|
||||
unusualLineTerminators = 108,
|
||||
useTabStops = 109,
|
||||
wordSeparators = 110,
|
||||
wordWrap = 111,
|
||||
wordWrapBreakAfterCharacters = 112,
|
||||
wordWrapBreakBeforeCharacters = 113,
|
||||
wordWrapColumn = 114,
|
||||
wordWrapMinified = 115,
|
||||
wrappingIndent = 116,
|
||||
wrappingStrategy = 117,
|
||||
showDeprecated = 118,
|
||||
editorClassName = 119,
|
||||
pixelRatio = 120,
|
||||
tabFocusMode = 121,
|
||||
layoutInfo = 122,
|
||||
wrappingInfo = 123
|
||||
}
|
||||
export const EditorOptions: {
|
||||
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
|
||||
|
@ -4074,6 +4079,7 @@ declare namespace monaco.editor {
|
|||
lineHeight: IEditorOption<EditorOption.lineHeight, number>;
|
||||
lineNumbers: IEditorOption<EditorOption.lineNumbers, InternalEditorRenderLineNumbersOptions>;
|
||||
lineNumbersMinChars: IEditorOption<EditorOption.lineNumbersMinChars, number>;
|
||||
linkedEditing: IEditorOption<EditorOption.linkedEditing, boolean>;
|
||||
links: IEditorOption<EditorOption.links, boolean>;
|
||||
matchBrackets: IEditorOption<EditorOption.matchBrackets, 'always' | 'never' | 'near'>;
|
||||
minimap: IEditorOption<EditorOption.minimap, EditorMinimapOptions>;
|
||||
|
@ -5093,9 +5099,9 @@ declare namespace monaco.languages {
|
|||
export function registerDocumentHighlightProvider(languageId: string, provider: DocumentHighlightProvider): IDisposable;
|
||||
|
||||
/**
|
||||
* Register an on type rename range provider.
|
||||
* Register an linked editing range provider.
|
||||
*/
|
||||
export function registerOnTypeRenameRangeProvider(languageId: string, provider: OnTypeRenameRangeProvider): IDisposable;
|
||||
export function registerLinkedEditingRangeProvider(languageId: string, provider: LinkedEditingRangeProvider): IDisposable;
|
||||
|
||||
/**
|
||||
* Register a definition provider (used by e.g. go to definition).
|
||||
|
@ -5839,23 +5845,23 @@ declare namespace monaco.languages {
|
|||
}
|
||||
|
||||
/**
|
||||
* The rename range provider interface defines the contract between extensions and
|
||||
* the live-rename feature.
|
||||
* The linked editing range provider interface defines the contract between extensions and
|
||||
* the linked editing feature.
|
||||
*/
|
||||
export interface OnTypeRenameRangeProvider {
|
||||
export interface LinkedEditingRangeProvider {
|
||||
/**
|
||||
* Provide a list of ranges that can be live-renamed together.
|
||||
* Provide a list of ranges that can be edited together.
|
||||
*/
|
||||
provideOnTypeRenameRanges(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<OnTypeRenameRanges>;
|
||||
provideLinkedEditingRanges(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a list of ranges that can be renamed together along with a word pattern to describe valid range contents.
|
||||
* Represents a list of ranges that can be edited together along with a word pattern to describe valid contents.
|
||||
*/
|
||||
export interface OnTypeRenameRanges {
|
||||
export interface LinkedEditingRanges {
|
||||
/**
|
||||
* A list of ranges that can be renamed together. The ranges must have
|
||||
* identical length and contain identical text content. The ranges cannot overlap
|
||||
* A list of ranges that can be edited together. The ranges must have
|
||||
* identical length and text content. The ranges cannot overlap
|
||||
*/
|
||||
ranges: IRange[];
|
||||
/**
|
||||
|
|
31
src/vs/vscode.proposed.d.ts
vendored
31
src/vs/vscode.proposed.d.ts
vendored
|
@ -983,52 +983,51 @@ declare module 'vscode' {
|
|||
|
||||
//#endregion
|
||||
|
||||
//#region OnTypeRename: https://github.com/microsoft/vscode/issues/109923 @aeschli
|
||||
//#region LinkedEditing: https://github.com/microsoft/vscode/issues/109923 @aeschli
|
||||
|
||||
/**
|
||||
* The 'on type' rename range provider interface defines the contract between extensions and
|
||||
* the 'on type' rename feature.
|
||||
* The linked editing range provider interface defines the contract between extensions and
|
||||
* the linked editing feature.
|
||||
*/
|
||||
export interface OnTypeRenameRangeProvider {
|
||||
export interface LinkedEditingRangeProvider {
|
||||
/**
|
||||
* For a given position in a document, returns the range of the symbol at the position and all ranges
|
||||
* that have the same content and can be renamed together. Optionally a word pattern can be returned
|
||||
* to describe valid contents. A rename to one of the ranges can be applied to all other ranges if the new content
|
||||
* is valid.
|
||||
* that have the same content. A change to one of the ranges can be applied to all other ranges if the new content
|
||||
* is valid. An optional word pattern can be returned with the result to describe valid contents.
|
||||
* If no result-specific word pattern is provided, the word pattern from the language configuration is used.
|
||||
*
|
||||
* @param document The document in which the provider was invoked.
|
||||
* @param position The position at which the provider was invoked.
|
||||
* @param token A cancellation token.
|
||||
* @return A list of ranges that can be renamed together
|
||||
* @return A list of ranges that can be edited together
|
||||
*/
|
||||
provideOnTypeRenameRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<OnTypeRenameRanges>;
|
||||
provideLinkedEditingRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>;
|
||||
}
|
||||
|
||||
namespace languages {
|
||||
/**
|
||||
* Register a 'on type' rename range provider.
|
||||
* Register a linked editing range provider.
|
||||
*
|
||||
* Multiple providers can be registered for a language. In that case providers are sorted
|
||||
* by their [score](#languages.match) and the best-matching provider that has a result is used. Failure
|
||||
* of the selected provider will cause a failure of the whole operation.
|
||||
*
|
||||
* @param selector A selector that defines the documents this provider is applicable to.
|
||||
* @param provider An 'on type' rename range provider.
|
||||
* @param provider A linked editing range provider.
|
||||
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
|
||||
*/
|
||||
export function registerOnTypeRenameRangeProvider(selector: DocumentSelector, provider: OnTypeRenameRangeProvider): Disposable;
|
||||
export function registerLinkedEditingRangeProvider(selector: DocumentSelector, provider: LinkedEditingRangeProvider): Disposable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a list of ranges that can be renamed together along with a word pattern to describe valid range contents.
|
||||
* Represents a list of ranges that can be edited together along with a word pattern to describe valid range contents.
|
||||
*/
|
||||
export class OnTypeRenameRanges {
|
||||
export class LinkedEditingRanges {
|
||||
constructor(ranges: Range[], wordPattern?: RegExp);
|
||||
|
||||
/**
|
||||
* A list of ranges that can be renamed together. The ranges must have
|
||||
* identical length and contain identical text content. The ranges cannot overlap.
|
||||
* A list of ranges that can be edited together. The ranges must have
|
||||
* identical length and text content. The ranges cannot overlap.
|
||||
*/
|
||||
readonly ranges: Range[];
|
||||
|
||||
|
|
|
@ -260,12 +260,12 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
|
|||
}));
|
||||
}
|
||||
|
||||
// --- on type rename
|
||||
// --- linked editing
|
||||
|
||||
$registerOnTypeRenameRangeProvider(handle: number, selector: IDocumentFilterDto[]): void {
|
||||
this._registrations.set(handle, modes.OnTypeRenameRangeProviderRegistry.register(selector, <modes.OnTypeRenameRangeProvider>{
|
||||
provideOnTypeRenameRanges: async (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.OnTypeRenameRanges | undefined> => {
|
||||
const res = await this._proxy.$provideOnTypeRenameRanges(handle, model.uri, position, token);
|
||||
$registerLinkedEditingRangeProvider(handle: number, selector: IDocumentFilterDto[]): void {
|
||||
this._registrations.set(handle, modes.LinkedEditingRangeProviderRegistry.register(selector, <modes.LinkedEditingRangeProvider>{
|
||||
provideLinkedEditingRanges: async (model: ITextModel, position: EditorPosition, token: CancellationToken): Promise<modes.LinkedEditingRanges | undefined> => {
|
||||
const res = await this._proxy.$provideLinkedEditingRanges(handle, model.uri, position, token);
|
||||
if (res) {
|
||||
return {
|
||||
ranges: res.ranges,
|
||||
|
|
|
@ -420,9 +420,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerDocumentHighlightProvider(extension, checkSelector(selector), provider);
|
||||
},
|
||||
registerOnTypeRenameRangeProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeRenameRangeProvider): vscode.Disposable {
|
||||
registerLinkedEditingRangeProvider(selector: vscode.DocumentSelector, provider: vscode.LinkedEditingRangeProvider): vscode.Disposable {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostLanguageFeatures.registerOnTypeRenameRangeProvider(extension, checkSelector(selector), provider);
|
||||
return extHostLanguageFeatures.registerLinkedEditingRangeProvider(extension, checkSelector(selector), provider);
|
||||
},
|
||||
registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
|
||||
return extHostLanguageFeatures.registerReferenceProvider(extension, checkSelector(selector), provider);
|
||||
|
@ -1259,9 +1259,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
checkProposedApiEnabled(extension);
|
||||
return extHostTypes.NotebookCellOutputItem;
|
||||
},
|
||||
get OnTypeRenameRanges() {
|
||||
get LinkedEditingRanges() {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostTypes.OnTypeRenameRanges;
|
||||
return extHostTypes.LinkedEditingRanges;
|
||||
},
|
||||
get TestRunState() {
|
||||
checkProposedApiEnabled(extension);
|
||||
|
|
|
@ -384,7 +384,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
|
|||
$registerHoverProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerEvaluatableExpressionProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerDocumentHighlightProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerOnTypeRenameRangeProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerLinkedEditingRangeProvider(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerReferenceSupport(handle: number, selector: IDocumentFilterDto[]): void;
|
||||
$registerQuickFixSupport(handle: number, selector: IDocumentFilterDto[], metadata: ICodeActionProviderMetadataDto, displayName: string, supportsResolve: boolean): void;
|
||||
$registerDocumentFormattingSupport(handle: number, selector: IDocumentFilterDto[], extensionId: ExtensionIdentifier, displayName: string): void;
|
||||
|
@ -1403,7 +1403,7 @@ export interface ILanguageWordDefinitionDto {
|
|||
regexFlags: string
|
||||
}
|
||||
|
||||
export interface IOnTypeRenameRangesDto {
|
||||
export interface ILinkedEditingRangesDto {
|
||||
ranges: IRange[];
|
||||
wordPattern?: IRegExpDto;
|
||||
}
|
||||
|
@ -1420,7 +1420,7 @@ export interface ExtHostLanguageFeaturesShape {
|
|||
$provideHover(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.Hover | undefined>;
|
||||
$provideEvaluatableExpression(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.EvaluatableExpression | undefined>;
|
||||
$provideDocumentHighlights(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.DocumentHighlight[] | undefined>;
|
||||
$provideOnTypeRenameRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IOnTypeRenameRangesDto | undefined>;
|
||||
$provideLinkedEditingRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<ILinkedEditingRangesDto | undefined>;
|
||||
$provideReferences(handle: number, resource: UriComponents, position: IPosition, context: modes.ReferenceContext, token: CancellationToken): Promise<ILocationDto[] | undefined>;
|
||||
$provideCodeActions(handle: number, resource: UriComponents, rangeOrSelection: IRange | ISelection, context: modes.CodeActionContext, token: CancellationToken): Promise<ICodeActionListDto | undefined>;
|
||||
$resolveCodeAction(handle: number, id: ChainedCacheId, token: CancellationToken): Promise<IWorkspaceEditDto | undefined>;
|
||||
|
|
|
@ -311,18 +311,18 @@ class DocumentHighlightAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
class OnTypeRenameRangeAdapter {
|
||||
class LinkedEditingRangeAdapter {
|
||||
constructor(
|
||||
private readonly _documents: ExtHostDocuments,
|
||||
private readonly _provider: vscode.OnTypeRenameRangeProvider
|
||||
private readonly _provider: vscode.LinkedEditingRangeProvider
|
||||
) { }
|
||||
|
||||
provideOnTypeRenameRanges(resource: URI, position: IPosition, token: CancellationToken): Promise<modes.OnTypeRenameRanges | undefined> {
|
||||
provideLinkedEditingRanges(resource: URI, position: IPosition, token: CancellationToken): Promise<modes.LinkedEditingRanges | undefined> {
|
||||
|
||||
const doc = this._documents.getDocument(resource);
|
||||
const pos = typeConvert.Position.to(position);
|
||||
|
||||
return asPromise(() => this._provider.provideOnTypeRenameRanges(doc, pos, token)).then(value => {
|
||||
return asPromise(() => this._provider.provideLinkedEditingRanges(doc, pos, token)).then(value => {
|
||||
if (value && Array.isArray(value.ranges)) {
|
||||
return {
|
||||
ranges: coalesce(value.ranges.map(typeConvert.Range.from)),
|
||||
|
@ -1320,7 +1320,7 @@ type Adapter = DocumentSymbolAdapter | CodeLensAdapter | DefinitionAdapter | Hov
|
|||
| SuggestAdapter | SignatureHelpAdapter | LinkProviderAdapter | ImplementationAdapter
|
||||
| TypeDefinitionAdapter | ColorProviderAdapter | FoldingProviderAdapter | DeclarationAdapter
|
||||
| SelectionRangeAdapter | CallHierarchyAdapter | DocumentSemanticTokensAdapter | DocumentRangeSemanticTokensAdapter | EvaluatableExpressionAdapter
|
||||
| OnTypeRenameRangeAdapter;
|
||||
| LinkedEditingRangeAdapter;
|
||||
|
||||
class AdapterData {
|
||||
constructor(
|
||||
|
@ -1562,17 +1562,17 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
|||
return this._withAdapter(handle, DocumentHighlightAdapter, adapter => adapter.provideDocumentHighlights(URI.revive(resource), position, token), undefined);
|
||||
}
|
||||
|
||||
// --- on type rename
|
||||
// --- linked editing
|
||||
|
||||
registerOnTypeRenameRangeProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.OnTypeRenameRangeProvider): vscode.Disposable {
|
||||
const handle = this._addNewAdapter(new OnTypeRenameRangeAdapter(this._documents, provider), extension);
|
||||
this._proxy.$registerOnTypeRenameRangeProvider(handle, this._transformDocumentSelector(selector));
|
||||
registerLinkedEditingRangeProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.LinkedEditingRangeProvider): vscode.Disposable {
|
||||
const handle = this._addNewAdapter(new LinkedEditingRangeAdapter(this._documents, provider), extension);
|
||||
this._proxy.$registerLinkedEditingRangeProvider(handle, this._transformDocumentSelector(selector));
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideOnTypeRenameRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<extHostProtocol.IOnTypeRenameRangesDto | undefined> {
|
||||
return this._withAdapter(handle, OnTypeRenameRangeAdapter, async adapter => {
|
||||
const res = await adapter.provideOnTypeRenameRanges(URI.revive(resource), position, token);
|
||||
$provideLinkedEditingRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<extHostProtocol.ILinkedEditingRangesDto | undefined> {
|
||||
return this._withAdapter(handle, LinkedEditingRangeAdapter, async adapter => {
|
||||
const res = await adapter.provideLinkedEditingRanges(URI.revive(resource), position, token);
|
||||
if (res) {
|
||||
return {
|
||||
ranges: res.ranges,
|
||||
|
|
|
@ -2879,7 +2879,7 @@ export enum StandardTokenType {
|
|||
}
|
||||
|
||||
|
||||
export class OnTypeRenameRanges {
|
||||
export class LinkedEditingRanges {
|
||||
constructor(public readonly ranges: Range[], public readonly wordPattern?: RegExp) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue