Skip to content

Commit

Permalink
Move logic to service
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jan 23, 2019
1 parent d1690ad commit d3c14cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function activate(context: ExtensionContext) {
languages.registerSelectionRangeProvider('html', {
async provideSelectionRanges(document: TextDocument, position: Position): Promise<SelectionRange[]> {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
});
Expand Down
23 changes: 2 additions & 21 deletions extensions/html-language-features/server/src/modes/htmlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit d3c14cf

Please sign in to comment.