Skip to content

Commit 01e01b1

Browse files
committed
HTML implementation for #88424
1 parent f76ca9f commit 01e01b1

File tree

7 files changed

+26
-278
lines changed

7 files changed

+26
-278
lines changed

extensions/html-language-features/client/src/htmlMain.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
2121
import { activateTagClosing } from './tagClosing';
2222
import TelemetryReporter from 'vscode-extension-telemetry';
2323
import { getCustomDataPathsInAllWorkspaces, getCustomDataPathsFromAllExtensions } from './customData';
24-
import { activateMirrorCursor } from './mirrorCursor';
2524

2625
namespace TagCloseRequest {
2726
export const type: RequestType<TextDocumentPositionParams, string, any, any> = new RequestType('html/tag');
2827
}
29-
namespace MatchingTagPositionRequest {
30-
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
28+
namespace OnTypeRenameRequest {
29+
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/onTypeRename');
3130
}
3231

3332
// experimental: semantic tokens
@@ -131,14 +130,6 @@ export function activate(context: ExtensionContext) {
131130
disposable = activateTagClosing(tagRequestor, { html: true, handlebars: true }, 'html.autoClosingTags');
132131
toDispose.push(disposable);
133132

134-
const matchingTagPositionRequestor = (document: TextDocument, position: Position) => {
135-
let param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
136-
return client.sendRequest(MatchingTagPositionRequest.type, param);
137-
};
138-
139-
disposable = activateMirrorCursor(matchingTagPositionRequestor, { html: true, handlebars: true }, 'html.mirrorCursorOnMatchingTag');
140-
toDispose.push(disposable);
141-
142133
disposable = client.onTelemetry(e => {
143134
if (telemetryReporter) {
144135
telemetryReporter.sendTelemetryEvent(e.key, e.data);
@@ -289,6 +280,15 @@ export function activate(context: ExtensionContext) {
289280
return results;
290281
}
291282
});
283+
284+
languages.registerOnTypeRenameProvider(documentSelector, {
285+
async provideOnTypeRenameRanges(document, position) {
286+
const param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
287+
const response = await client.sendRequest(OnTypeRenameRequest.type, param);
288+
289+
return response || [];
290+
}
291+
});
292292
}
293293

294294
function getPackageInfo(context: ExtensionContext): IPackageInfo | null {

extensions/html-language-features/client/src/mirrorCursor.ts

-259
This file was deleted.

extensions/html-language-features/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@
165165
"type": "boolean",
166166
"scope": "resource",
167167
"default": false,
168-
"description": "%html.mirrorCursorOnMatchingTag%"
168+
"description": "%html.mirrorCursorOnMatchingTag%",
169+
"deprecationMessage": "%html.mirrorCursorOnMatchingTagDeprecationMessage%"
169170
},
170171
"html.trace.server": {
171172
"type": "string",

extensions/html-language-features/package.nls.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"html.validate.scripts": "Controls whether the built-in HTML language support validates embedded scripts.",
2626
"html.validate.styles": "Controls whether the built-in HTML language support validates embedded styles.",
2727
"html.autoClosingTags": "Enable/disable autoclosing of HTML tags.",
28-
"html.mirrorCursorOnMatchingTag": "Enable/disable mirroring cursor on matching HTML tag."
28+
"html.mirrorCursorOnMatchingTag": "Enable/disable mirroring cursor on matching HTML tag.",
29+
"html.mirrorCursorOnMatchingTagDeprecationMessage": "Deprecated in favor of `editor.renameOnType`"
2930
}

extensions/html-language-features/server/src/htmlServerMain.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import { SemanticTokenProvider, newSemanticTokenProvider } from './modes/semanti
2828
namespace TagCloseRequest {
2929
export const type: RequestType<TextDocumentPositionParams, string | null, any, any> = new RequestType('html/tag');
3030
}
31-
namespace MatchingTagPositionRequest {
32-
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
31+
namespace OnTypeRenameRequest {
32+
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/onTypeRename');
3333
}
3434

3535
// experimental: semantic tokens
@@ -499,20 +499,20 @@ connection.onRenameRequest((params, token) => {
499499
}, null, `Error while computing rename for ${params.textDocument.uri}`, token);
500500
});
501501

502-
connection.onRequest(MatchingTagPositionRequest.type, (params, token) => {
502+
connection.onRequest(OnTypeRenameRequest.type, (params, token) => {
503503
return runSafe(() => {
504504
const document = documents.get(params.textDocument.uri);
505505
if (document) {
506506
const pos = params.position;
507507
if (pos.character > 0) {
508508
const mode = languageModes.getModeAtPosition(document, Position.create(pos.line, pos.character - 1));
509-
if (mode && mode.findMatchingTagPosition) {
510-
return mode.findMatchingTagPosition(document, pos);
509+
if (mode && mode.doOnTypeRename) {
510+
return mode.doOnTypeRename(document, pos);
511511
}
512512
}
513513
}
514514
return null;
515-
}, null, `Error while computing matching tag position for ${params.textDocument.uri}`, token);
515+
}, null, `Error while computing synced regions for ${params.textDocument.uri}`, token);
516516
});
517517

518518
let semanticTokensProvider: SemanticTokenProvider | undefined;

extensions/html-language-features/server/src/modes/htmlMode.ts

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
8585
const htmlDocument = htmlDocuments.get(document);
8686
return htmlLanguageService.findMatchingTagPosition(document, position, htmlDocument);
8787
},
88+
doOnTypeRename(document: TextDocument, position: Position) {
89+
const htmlDocument = htmlDocuments.get(document);
90+
return htmlLanguageService.findSyncedRegions(document, position, htmlDocument);
91+
},
8892
dispose() {
8993
htmlDocuments.dispose();
9094
}

extensions/html-language-features/server/src/modes/languageModes.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface LanguageMode {
4747
doHover?: (document: TextDocument, position: Position) => Hover | null;
4848
doSignatureHelp?: (document: TextDocument, position: Position) => SignatureHelp | null;
4949
doRename?: (document: TextDocument, position: Position, newName: string) => WorkspaceEdit | null;
50+
doOnTypeRename?: (document: TextDocument, position: Position) => Range[] | null;
5051
findDocumentHighlight?: (document: TextDocument, position: Position) => DocumentHighlight[];
5152
findDocumentSymbols?: (document: TextDocument) => SymbolInformation[];
5253
findDocumentLinks?: (document: TextDocument, documentContext: DocumentContext) => DocumentLink[];

0 commit comments

Comments
 (0)