Get emmet completions from css extension (#41652)

* Get emmet completions from html,css extensions

* Resolve extensionsPath, use emmet results even if empty

* Support css abbr with :

* Refactoring

* Add some basic emmet tests

* Refactoring

* More tests
This commit is contained in:
Ramya Rao
2018-02-12 21:40:10 -08:00
committed by GitHub
parent 4d12201733
commit 00f2d8ed71
26 changed files with 415 additions and 116 deletions

View File

@@ -5,13 +5,14 @@
'use strict';
import { getLanguageModelCache } from '../languageModelCache';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration } from 'vscode-html-languageservice';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration, TokenType } from 'vscode-html-languageservice';
import { TextDocument, Position, Range } from 'vscode-languageserver-types';
import { LanguageMode, Settings } from './languageModes';
export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageMode {
let globalSettings: Settings = {};
let htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));
let completionParticipants = [];
return {
getId() {
return 'html';
@@ -25,7 +26,23 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageM
if (doAutoComplete) {
options.hideAutoCompleteProposals = true;
}
return htmlLanguageService.doComplete(document, position, htmlDocuments.get(document), options);
const htmlDocument = htmlDocuments.get(document);
const offset = document.offsetAt(position);
const node = htmlDocument.findNodeBefore(offset);
const scanner = htmlLanguageService.createScanner(document.getText(), node.start);
let token = scanner.scan();
while (token !== TokenType.EOS && scanner.getTokenOffset() <= offset) {
if (token === TokenType.Content && offset <= scanner.getTokenEnd()) {
completionParticipants.forEach(participant => { if (participant.onHtmlContent) { participant.onHtmlContent(); } });
break;
}
token = scanner.scan();
}
return htmlLanguageService.doComplete(document, position, htmlDocument, options);
},
setCompletionParticipants(registeredCompletionParticipants: any[]) {
completionParticipants = registeredCompletionParticipants;
},
doHover(document: TextDocument, position: Position) {
return htmlLanguageService.doHover(document, position, htmlDocuments.get(document));