Skip to content

Commit

Permalink
HTML implementation for #88424
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Mar 18, 2020
1 parent f76ca9f commit 01e01b1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 278 deletions.
22 changes: 11 additions & 11 deletions extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
import { activateTagClosing } from './tagClosing';
import TelemetryReporter from 'vscode-extension-telemetry';
import { getCustomDataPathsInAllWorkspaces, getCustomDataPathsFromAllExtensions } from './customData';
import { activateMirrorCursor } from './mirrorCursor';

namespace TagCloseRequest {
export const type: RequestType<TextDocumentPositionParams, string, any, any> = new RequestType('html/tag');
}
namespace MatchingTagPositionRequest {
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
namespace OnTypeRenameRequest {
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/onTypeRename');
}

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

const matchingTagPositionRequestor = (document: TextDocument, position: Position) => {
let param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
return client.sendRequest(MatchingTagPositionRequest.type, param);
};

disposable = activateMirrorCursor(matchingTagPositionRequestor, { html: true, handlebars: true }, 'html.mirrorCursorOnMatchingTag');
toDispose.push(disposable);

disposable = client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
Expand Down Expand Up @@ -289,6 +280,15 @@ export function activate(context: ExtensionContext) {
return results;
}
});

languages.registerOnTypeRenameProvider(documentSelector, {
async provideOnTypeRenameRanges(document, position) {
const param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
const response = await client.sendRequest(OnTypeRenameRequest.type, param);

return response || [];
}
});
}

function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
Expand Down
259 changes: 0 additions & 259 deletions extensions/html-language-features/client/src/mirrorCursor.ts

This file was deleted.

3 changes: 2 additions & 1 deletion extensions/html-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"type": "boolean",
"scope": "resource",
"default": false,
"description": "%html.mirrorCursorOnMatchingTag%"
"description": "%html.mirrorCursorOnMatchingTag%",
"deprecationMessage": "%html.mirrorCursorOnMatchingTagDeprecationMessage%"
},
"html.trace.server": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion extensions/html-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"html.validate.scripts": "Controls whether the built-in HTML language support validates embedded scripts.",
"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.mirrorCursorOnMatchingTag": "Enable/disable mirroring cursor on matching HTML tag.",
"html.mirrorCursorOnMatchingTagDeprecationMessage": "Deprecated in favor of `editor.renameOnType`"
}
12 changes: 6 additions & 6 deletions extensions/html-language-features/server/src/htmlServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { SemanticTokenProvider, newSemanticTokenProvider } from './modes/semanti
namespace TagCloseRequest {
export const type: RequestType<TextDocumentPositionParams, string | null, any, any> = new RequestType('html/tag');
}
namespace MatchingTagPositionRequest {
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
namespace OnTypeRenameRequest {
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/onTypeRename');
}

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

connection.onRequest(MatchingTagPositionRequest.type, (params, token) => {
connection.onRequest(OnTypeRenameRequest.type, (params, token) => {
return runSafe(() => {
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.findMatchingTagPosition) {
return mode.findMatchingTagPosition(document, pos);
if (mode && mode.doOnTypeRename) {
return mode.doOnTypeRename(document, pos);
}
}
}
return null;
}, null, `Error while computing matching tag position for ${params.textDocument.uri}`, token);
}, null, `Error while computing synced regions for ${params.textDocument.uri}`, token);
});

let semanticTokensProvider: SemanticTokenProvider | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
const htmlDocument = htmlDocuments.get(document);
return htmlLanguageService.findMatchingTagPosition(document, position, htmlDocument);
},
doOnTypeRename(document: TextDocument, position: Position) {
const htmlDocument = htmlDocuments.get(document);
return htmlLanguageService.findSyncedRegions(document, position, htmlDocument);
},
dispose() {
htmlDocuments.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface LanguageMode {
doHover?: (document: TextDocument, position: Position) => Hover | null;
doSignatureHelp?: (document: TextDocument, position: Position) => SignatureHelp | null;
doRename?: (document: TextDocument, position: Position, newName: string) => WorkspaceEdit | null;
doOnTypeRename?: (document: TextDocument, position: Position) => Range[] | null;
findDocumentHighlight?: (document: TextDocument, position: Position) => DocumentHighlight[];
findDocumentSymbols?: (document: TextDocument) => SymbolInformation[];
findDocumentLinks?: (document: TextDocument, documentContext: DocumentContext) => DocumentLink[];
Expand Down

0 comments on commit 01e01b1

Please sign in to comment.