rename OnTypeRename -> LinkedEditing (for #109923)

This commit is contained in:
Martin Aeschlimann
2020-11-27 16:31:44 +01:00
parent f13720627f
commit 627ad0b4ee
19 changed files with 286 additions and 269 deletions

View File

@@ -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);
}
}
});

View File

@@ -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`"
}

View File

@@ -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);
}
}
}

View File

@@ -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);
},

View File

@@ -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[]>;