Skip to content

Commit

Permalink
CSS semantic selection. Fix microsoft#65925
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jan 24, 2019
1 parent 75c7e86 commit f053101
Show file tree
Hide file tree
Showing 6 changed files with 1,183 additions and 8 deletions.
22 changes: 20 additions & 2 deletions extensions/css-language-features/client/src/cssMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*)?)?)?$/;

Expand Down
Loading

0 comments on commit f053101

Please sign in to comment.