move completion logic to lang service

This commit is contained in:
Pine Wu 2018-02-21 14:10:57 -08:00
parent 9a0b59c55b
commit 0819922f9a
2 changed files with 5 additions and 25 deletions

View file

@ -271,11 +271,11 @@ connection.onCompletion(async textDocumentPosition => {
cachedCompletionList = null;
let emmetCompletionList: CompletionList = {
isIncomplete: true,
items: undefined
items: []
};
let pathCompletionList: CompletionList = {
isIncomplete: false,
items: undefined
items: []
};
if (mode.setCompletionParticipants) {

View file

@ -5,7 +5,7 @@
'use strict';
import { getLanguageModelCache } from '../languageModelCache';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration, TokenType } from 'vscode-html-languageservice';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration } from 'vscode-html-languageservice';
import { TextDocument, Position, Range } from 'vscode-languageserver-types';
import { LanguageMode, Settings } from './languageModes';
@ -28,28 +28,8 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageM
}
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();
let prevTag, prevAttributeName;
while (token !== TokenType.EOS && scanner.getTokenOffset() <= offset) {
if (token === TokenType.Content && offset <= scanner.getTokenEnd()) {
completionParticipants.forEach(participant => { if (participant.onHtmlContent) { participant.onHtmlContent(); } });
break;
} else if (token === TokenType.AttributeName) {
prevAttributeName = scanner.getTokenText();
} else if (token === TokenType.StartTag) {
prevTag = scanner.getTokenText();
} else if (token === TokenType.AttributeValue && offset <= scanner.getTokenEnd()) {
completionParticipants.forEach(participant => {
if (participant.onHtmlAttributeValue) {
participant.onHtmlAttributeValue(prevTag, prevAttributeName, scanner.getTokenText());
}
});
}
token = scanner.scan();
}
htmlLanguageService.setCompletionParticipants(completionParticipants);
return htmlLanguageService.doComplete(document, position, htmlDocument, options);
},
setCompletionParticipants(registeredCompletionParticipants: any[]) {