From d3c14cf0af9dab84ad68df74659ed0cdd9b83f57 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Wed, 23 Jan 2019 12:11:29 -0800 Subject: [PATCH] Move logic to service --- .../client/src/htmlMain.ts | 2 +- .../server/src/htmlServerMain.ts | 4 +--- .../server/src/modes/htmlMode.ts | 23 ++----------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/extensions/html-language-features/client/src/htmlMain.ts b/extensions/html-language-features/client/src/htmlMain.ts index 40825b841310e..b9d3978b30432 100644 --- a/extensions/html-language-features/client/src/htmlMain.ts +++ b/extensions/html-language-features/client/src/htmlMain.ts @@ -89,7 +89,7 @@ export function activate(context: ExtensionContext) { languages.registerSelectionRangeProvider('html', { async provideSelectionRanges(document: TextDocument, position: Position): Promise { const textDocument = TextDocumentIdentifier.create(document.uri.toString()); - const rawRanges: Range[] = await client.sendRequest('$/selection', { textDocument, position }); + const rawRanges: Range[] = await client.sendRequest('$/textDocument/selectionRange', { textDocument, position }); return rawRanges.map(r => { const actualRange = new Range(new Position(r.start.line, r.start.character), new Position(r.end.line, r.end.character)); diff --git a/extensions/html-language-features/server/src/htmlServerMain.ts b/extensions/html-language-features/server/src/htmlServerMain.ts index 06921362d85f6..2ccb26c3f60f0 100644 --- a/extensions/html-language-features/server/src/htmlServerMain.ts +++ b/extensions/html-language-features/server/src/htmlServerMain.ts @@ -480,7 +480,7 @@ connection.onFoldingRanges((params, token) => { }, null, `Error while computing folding regions for ${params.textDocument.uri}`, token); }); -connection.onRequest('$/selection', async (params) => { +connection.onRequest('$/textDocument/selectionRange', async (params) => { const document = documents.get(params.textDocument.uri); const position: Position = params.position; @@ -489,8 +489,6 @@ connection.onRequest('$/selection', async (params) => { if (htmlMode && htmlMode.doSelection) { return htmlMode.doSelection(document, position); } - - console.log(position.line, position.character); } return Promise.resolve(null); }); diff --git a/extensions/html-language-features/server/src/modes/htmlMode.ts b/extensions/html-language-features/server/src/modes/htmlMode.ts index 00dc9313a37aa..00a690f56eb74 100644 --- a/extensions/html-language-features/server/src/modes/htmlMode.ts +++ b/extensions/html-language-features/server/src/modes/htmlMode.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { getLanguageModelCache } from '../languageModelCache'; -import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration, Node } from 'vscode-html-languageservice'; +import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration } from 'vscode-html-languageservice'; import { TextDocument, Position, Range, CompletionItem, FoldingRange } from 'vscode-languageserver-types'; import { LanguageMode, Workspace } from './languageModes'; import { getPathCompletionParticipant } from './pathCompletion'; @@ -16,26 +16,7 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace: return 'html'; }, doSelection(document: TextDocument, position: Position): Range[] { - const htmlDocument = htmlDocuments.get(document); - let currNode = htmlDocument.findNodeAt(document.offsetAt(position)); - let getNodeRanges = (n: Node) => { - if (n.startTagEnd && n.endTagStart && n.startTagEnd < n.endTagStart) { - return [ - Range.create(document.positionAt(n.startTagEnd), document.positionAt(n.endTagStart)), - Range.create(document.positionAt(n.start), document.positionAt(n.end)), - ]; - } - - return [Range.create(document.positionAt(n.start), document.positionAt(n.end))]; - }; - const result = [...getNodeRanges(currNode)]; - - while (currNode.parent) { - currNode = currNode.parent; - getNodeRanges(currNode).forEach(r => result.push(r)); - } - - return result; + return htmlLanguageService.getSelectionRanges(document, position); }, doComplete(document: TextDocument, position: Position, settings = workspace.settings) { let options = settings && settings.html && settings.html.suggest;