mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
move completion logic to lang service
This commit is contained in:
parent
9a0b59c55b
commit
0819922f9a
|
@ -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) {
|
||||
|
|
|
@ -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[]) {
|
||||
|
|
Loading…
Reference in a new issue