mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
move completion logic to lang service
This commit is contained in:
@@ -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[]) {
|
||||
|
||||
Reference in New Issue
Block a user