mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user