2020-03-25 12:01:54 -07:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
|
* ------------------------------------------------------------------------------------------ */
|
|
|
|
|
|
2020-04-08 11:19:02 -07:00
|
|
|
import { getLanguageService } from 'vscode-html-languageservice';
|
|
|
|
|
import { createConnection, InitializeParams, ProposedFeatures, TextDocuments, TextDocumentSyncKind } from 'vscode-languageserver';
|
2020-04-01 11:54:04 -07:00
|
|
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
2020-03-25 12:01:54 -07:00
|
|
|
|
|
|
|
|
// Create a connection for the server. The connection uses Node's IPC as a transport.
|
|
|
|
|
// Also include all preview / proposed LSP features.
|
|
|
|
|
let connection = createConnection(ProposedFeatures.all);
|
|
|
|
|
|
|
|
|
|
// Create a simple text document manager. The text document manager
|
|
|
|
|
// supports full document sync only
|
2020-04-01 11:54:04 -07:00
|
|
|
let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
2020-03-25 12:01:54 -07:00
|
|
|
|
2020-04-08 11:19:02 -07:00
|
|
|
const htmlLanguageService = getLanguageService();
|
2020-03-25 12:01:54 -07:00
|
|
|
|
|
|
|
|
connection.onInitialize((_params: InitializeParams) => {
|
|
|
|
|
return {
|
|
|
|
|
capabilities: {
|
2020-04-01 11:54:04 -07:00
|
|
|
textDocumentSync: TextDocumentSyncKind.Full,
|
2020-03-25 12:01:54 -07:00
|
|
|
// Tell the client that the server supports code completion
|
|
|
|
|
completionProvider: {
|
|
|
|
|
resolveProvider: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-08 11:19:02 -07:00
|
|
|
connection.onInitialized(() => { });
|
2020-03-25 12:01:54 -07:00
|
|
|
|
|
|
|
|
connection.onCompletion(async (textDocumentPosition, token) => {
|
|
|
|
|
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 11:19:02 -07:00
|
|
|
return htmlLanguageService.doComplete(
|
|
|
|
|
document,
|
|
|
|
|
textDocumentPosition.position,
|
|
|
|
|
htmlLanguageService.parseHTMLDocument(document)
|
|
|
|
|
);
|
2020-03-25 12:01:54 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
documents.listen(connection);
|
|
|
|
|
connection.listen();
|