mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
CSS semantic selection. Fix #65925
This commit is contained in:
@@ -9,8 +9,8 @@ import * as fs from 'fs';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { languages, window, commands, ExtensionContext, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString, workspace } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable } from 'vscode-languageclient';
|
||||
import { languages, window, commands, ExtensionContext, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString, workspace, TextDocument, SelectionRange, SelectionRangeKind } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable, TextDocumentIdentifier } from 'vscode-languageclient';
|
||||
import { getCustomDataPathsInAllWorkspaces, getCustomDataPathsFromAllExtensions } from './customData';
|
||||
|
||||
// this method is called when vs code is activated
|
||||
@@ -80,6 +80,24 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(initCompletionProvider());
|
||||
});
|
||||
|
||||
const selectionRangeProvider = {
|
||||
async provideSelectionRanges(document: TextDocument, position: Position): Promise<SelectionRange[]> {
|
||||
const textDocument = TextDocumentIdentifier.create(document.uri.toString());
|
||||
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));
|
||||
return {
|
||||
range: actualRange,
|
||||
kind: SelectionRangeKind.Declaration
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
languages.registerSelectionRangeProvider('css', selectionRangeProvider);
|
||||
languages.registerSelectionRangeProvider('less', selectionRangeProvider);
|
||||
languages.registerSelectionRangeProvider('scss', selectionRangeProvider);
|
||||
|
||||
function initCompletionProvider(): Disposable {
|
||||
const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;
|
||||
|
||||
|
||||
1142
extensions/css-language-features/client/src/vscode.proposed.d.ts
vendored
Normal file
1142
extensions/css-language-features/client/src/vscode.proposed.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"enableProposedApi": true,
|
||||
"name": "css-language-features",
|
||||
"displayName": "%displayName%",
|
||||
"description": "%description%",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"main": "./out/cssServerMain",
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.13-next.6",
|
||||
"vscode-css-languageservice": "^3.0.13-next.7",
|
||||
"vscode-languageserver": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from 'vscode-languageserver';
|
||||
import URI from 'vscode-uri';
|
||||
import * as fs from 'fs';
|
||||
import { TextDocument, CompletionList } from 'vscode-languageserver-types';
|
||||
import { TextDocument, CompletionList, Position } from 'vscode-languageserver-types';
|
||||
|
||||
import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet, CSSData } from 'vscode-css-languageservice';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
@@ -346,5 +346,19 @@ connection.onFoldingRanges((params, token) => {
|
||||
}, null, `Error while computing folding ranges for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
connection.onRequest('$/textDocument/selectionRange', async (params, token) => {
|
||||
return runSafe(() => {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
const position: Position = params.position;
|
||||
|
||||
if (document) {
|
||||
const stylesheet = stylesheets.get(document);
|
||||
return getLanguageService(document).getSelectionRanges(document, position, stylesheet);
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
}, null, `Error while computing selection ranges for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
|
||||
// Listen on the connection
|
||||
connection.listen();
|
||||
@@ -229,10 +229,10 @@ supports-color@5.4.0:
|
||||
dependencies:
|
||||
has-flag "^3.0.0"
|
||||
|
||||
vscode-css-languageservice@^3.0.13-next.6:
|
||||
version "3.0.13-next.6"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.13-next.6.tgz#0329ea1da29ca84d1821cd32ee10bca0ee4c50cd"
|
||||
integrity sha512-wC8zaFWHNnqIaOT4LXByy3NyTl916uHxGy3U3cpV7Gw7F8ENylSGM2RAO+l7NohIbP0WZlet441HEwSbb+bZbQ==
|
||||
vscode-css-languageservice@^3.0.13-next.7:
|
||||
version "3.0.13-next.7"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.13-next.7.tgz#48392edbf35ce60c54aeaf8d3e83c994d6c4c84e"
|
||||
integrity sha512-2Z28n0CVwwNpdDmoIbjUMJPnchm+eRJE/PhhjXss/p0CnSJfXzbll3Ay1V+nDLW2NIGap0CJFbbfT+cilyivIA==
|
||||
dependencies:
|
||||
vscode-languageserver-types "^3.13.0"
|
||||
vscode-nls "^4.0.0"
|
||||
|
||||
Reference in New Issue
Block a user