Skip to content

Commit

Permalink
HTML selections
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jan 22, 2019
1 parent 23f534b commit 82aab5a
Show file tree
Hide file tree
Showing 6 changed files with 1,192 additions and 3 deletions.
19 changes: 17 additions & 2 deletions extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as fs from 'fs';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

import { languages, ExtensionContext, IndentAction, Position, TextDocument, Range, CompletionItem, CompletionItemKind, SnippetString, workspace } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, TextDocumentPositionParams } from 'vscode-languageclient';
import { languages, ExtensionContext, IndentAction, Position, TextDocument, Range, CompletionItem, CompletionItemKind, SnippetString, workspace, SelectionRange, SelectionRangeKind } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, TextDocumentPositionParams, TextDocumentIdentifier } from 'vscode-languageclient';
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
import { activateTagClosing } from './tagClosing';
import TelemetryReporter from 'vscode-extension-telemetry';
Expand Down Expand Up @@ -86,6 +86,21 @@ export function activate(context: ExtensionContext) {
toDispose.push(disposable);
});

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 });

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.setLanguageConfiguration('html', {
indentationRules: {
increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/,
Expand Down
Loading

0 comments on commit 82aab5a

Please sign in to comment.