mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
HTML selections
This commit is contained in:
@@ -480,6 +480,21 @@ connection.onFoldingRanges((params, token) => {
|
||||
}, null, `Error while computing folding regions for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
connection.onRequest('$/selection', async (params) => {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
const position: Position = params.position;
|
||||
|
||||
if (document) {
|
||||
const htmlMode = languageModes.getMode('html');
|
||||
if (htmlMode && htmlMode.doSelection) {
|
||||
return htmlMode.doSelection(document, position);
|
||||
}
|
||||
|
||||
console.log(position.line, position.character);
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
|
||||
// Listen on the connection
|
||||
connection.listen();
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getLanguageModelCache } from '../languageModelCache';
|
||||
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration } from 'vscode-html-languageservice';
|
||||
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration, Node } from 'vscode-html-languageservice';
|
||||
import { TextDocument, Position, Range, CompletionItem, FoldingRange } from 'vscode-languageserver-types';
|
||||
import { LanguageMode, Workspace } from './languageModes';
|
||||
import { getPathCompletionParticipant } from './pathCompletion';
|
||||
@@ -15,6 +15,21 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
||||
getId() {
|
||||
return 'html';
|
||||
},
|
||||
doSelection(document: TextDocument, position: Position): Range[] {
|
||||
const htmlDocument = htmlDocuments.get(document);
|
||||
let currNode = htmlDocument.findNodeAt(document.offsetAt(position));
|
||||
let getNodeRange = (n: Node) => {
|
||||
return Range.create(document.positionAt(n.start), document.positionAt(n.end));
|
||||
};
|
||||
const result = [getNodeRange(currNode)];
|
||||
|
||||
while (currNode.parent) {
|
||||
currNode = currNode.parent;
|
||||
result.push(getNodeRange(currNode));
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
doComplete(document: TextDocument, position: Position, settings = workspace.settings) {
|
||||
let options = settings && settings.html && settings.html.suggest;
|
||||
let doAutoComplete = settings && settings.html && settings.html.autoClosingTags;
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface Workspace {
|
||||
|
||||
export interface LanguageMode {
|
||||
getId(): string;
|
||||
doSelection?: (document: TextDocument, position: Position) => Range[];
|
||||
doValidation?: (document: TextDocument, settings?: Settings) => Diagnostic[];
|
||||
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList;
|
||||
doResolve?: (document: TextDocument, item: CompletionItem) => CompletionItem;
|
||||
|
||||
Reference in New Issue
Block a user