mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Update service and adopt HTML provider interface
This commit is contained in:
parent
1b57516818
commit
3815bb15fd
|
@ -1,3 +1,6 @@
|
|||
{
|
||||
"editor.insertSpaces": false
|
||||
"editor.insertSpaces": false,
|
||||
"prettier.semi": true,
|
||||
"prettier.singleQuote": true,
|
||||
"prettier.printWidth": 120,
|
||||
}
|
|
@ -9,8 +9,8 @@
|
|||
},
|
||||
"main": "./out/htmlServerMain",
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.13-next.6",
|
||||
"vscode-html-languageservice": "^2.1.11-next.4",
|
||||
"vscode-css-languageservice": "^3.0.13-next.8",
|
||||
"vscode-html-languageservice": "^2.1.11-next.6",
|
||||
"vscode-languageserver": "^5.1.0",
|
||||
"vscode-languageserver-types": "^3.13.0",
|
||||
"vscode-nls": "^4.0.0",
|
||||
|
|
29
extensions/html-language-features/server/src/customData.ts
Normal file
29
extensions/html-language-features/server/src/customData.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IHTMLDataProvider, HTMLDataProvider } from 'vscode-html-languageservice';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export function getDataProviders(dataPaths?: string[]): IHTMLDataProvider[] {
|
||||
if (!dataPaths) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const providers: IHTMLDataProvider[] = [];
|
||||
|
||||
dataPaths.forEach((path, i) => {
|
||||
try {
|
||||
if (fs.existsSync(path)) {
|
||||
const htmlData = JSON.parse(fs.readFileSync(path, 'utf-8'));
|
||||
|
||||
providers.push(new HTMLDataProvider(`customProvider${i}`, htmlData));
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`Failed to laod tag from ${path}`);
|
||||
}
|
||||
});
|
||||
|
||||
return providers;
|
||||
}
|
|
@ -11,7 +11,6 @@ import {
|
|||
} from 'vscode-languageserver';
|
||||
import { TextDocument, Diagnostic, DocumentLink, SymbolInformation } from 'vscode-languageserver-types';
|
||||
import { getLanguageModes, LanguageModes, Settings } from './modes/languageModes';
|
||||
import * as fs from 'fs';
|
||||
|
||||
import { format } from './modes/formatting';
|
||||
import { pushAll } from './utils/arrays';
|
||||
|
@ -20,8 +19,7 @@ import uri from 'vscode-uri';
|
|||
import { formatError, runSafe, runSafeAsync } from './utils/runner';
|
||||
|
||||
import { getFoldingRanges } from './modes/htmlFolding';
|
||||
import { parseHTMLData } from './utils/tagDefinitions';
|
||||
import { HTMLData } from 'vscode-html-languageservice';
|
||||
import { getDataProviders } from './customData';
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string | null, any, any> = new RequestType('html/tag');
|
||||
|
@ -92,37 +90,14 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
}
|
||||
|
||||
const dataPaths: string[] = params.initializationOptions.dataPaths;
|
||||
|
||||
let allHtmlData: HTMLData = {
|
||||
tags: [],
|
||||
globalAttributes: [],
|
||||
valueSetMap: {}
|
||||
};
|
||||
|
||||
if (dataPaths) {
|
||||
dataPaths.forEach(path => {
|
||||
try {
|
||||
if (fs.existsSync(path)) {
|
||||
const htmlData = parseHTMLData(fs.readFileSync(path, 'utf-8'));
|
||||
if (htmlData.tags) {
|
||||
allHtmlData.tags = allHtmlData.tags!.concat(htmlData.tags);
|
||||
}
|
||||
if (htmlData.globalAttributes) {
|
||||
allHtmlData.globalAttributes = allHtmlData.globalAttributes!.concat(htmlData.globalAttributes);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`Failed to laod tag from ${path}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
const providers = getDataProviders(dataPaths);
|
||||
|
||||
const workspace = {
|
||||
get settings() { return globalSettings; },
|
||||
get folders() { return workspaceFolders; }
|
||||
};
|
||||
|
||||
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }, workspace, allHtmlData);
|
||||
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }, workspace, providers);
|
||||
|
||||
documents.onDidClose(e => {
|
||||
languageModes.onDocumentRemoved(e.document);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getLanguageService as getHTMLLanguageService, DocumentContext, HTMLData } from 'vscode-html-languageservice';
|
||||
import { getLanguageService as getHTMLLanguageService, DocumentContext, IHTMLDataProvider } from 'vscode-html-languageservice';
|
||||
import {
|
||||
CompletionItem, Location, SignatureHelp, Definition, TextEdit, TextDocument, Diagnostic, DocumentLink, Range,
|
||||
Hover, DocumentHighlight, CompletionList, Position, FormattingOptions, SymbolInformation, FoldingRange
|
||||
|
@ -66,9 +66,8 @@ export interface LanguageModeRange extends Range {
|
|||
attributeValue?: boolean;
|
||||
}
|
||||
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, customData?: HTMLData): LanguageModes {
|
||||
const customDataCollections = customData ? [customData] : [];
|
||||
const htmlLanguageService = getHTMLLanguageService({ customDataCollections });
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, customDataProviders?: IHTMLDataProvider[]): LanguageModes {
|
||||
const htmlLanguageService = getHTMLLanguageService({ customDataProviders });
|
||||
|
||||
let documentRegions = getLanguageModelCache<HTMLDocumentRegions>(10, 60, document => getDocumentRegions(htmlLanguageService, document));
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { HTMLData } from 'vscode-html-languageservice';
|
||||
|
||||
export function parseHTMLData(source: string): HTMLData {
|
||||
return JSON.parse(source);
|
||||
}
|
|
@ -229,18 +229,18 @@ supports-color@5.4.0:
|
|||
dependencies:
|
||||
has-flag "^3.0.0"
|
||||
|
||||
vscode-css-languageservice@^3.0.13-next.6:
|
||||
version "3.0.13-next.6"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.13-next.6.tgz#0329ea1da29ca84d1821cd32ee10bca0ee4c50cd"
|
||||
integrity sha512-wC8zaFWHNnqIaOT4LXByy3NyTl916uHxGy3U3cpV7Gw7F8ENylSGM2RAO+l7NohIbP0WZlet441HEwSbb+bZbQ==
|
||||
vscode-css-languageservice@^3.0.13-next.8:
|
||||
version "3.0.13-next.8"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.13-next.8.tgz#3e019c9166914fcbd8b71530ff32b438698206fa"
|
||||
integrity sha512-YjoIMCvZSegs7UOogehQjrfNybBL3MDVN2jx/uxFFw0VKFGAiyZkjfQiipEg36jbKL4LKHiBUoutoHYMF2PGfw==
|
||||
dependencies:
|
||||
vscode-languageserver-types "^3.13.0"
|
||||
vscode-nls "^4.0.0"
|
||||
|
||||
vscode-html-languageservice@^2.1.11-next.4:
|
||||
version "2.1.11-next.4"
|
||||
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.1.11-next.4.tgz#bcfe68ca17300d7f845889be3cb947af95dab409"
|
||||
integrity sha512-dQOcdqLhMZuAWhSoe/AqqvVo2klkWpCHwp14dWvgrAfUyKM7l0e0kk9lbf8kt1Kn2J9ukDTySIcOkbHaVSwcHA==
|
||||
vscode-html-languageservice@^2.1.11-next.6:
|
||||
version "2.1.11-next.6"
|
||||
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.1.11-next.6.tgz#66eb7a10d84ac91d5985b45cfa704ce05fe3e638"
|
||||
integrity sha512-BCShNFqflm1XpjMJrxAz4tWSAdA1cqJi2XrI3/eHzqcHzw4kO/l3ApaZPdci77CAcOdWKyDmmzSau0UwR+CkYQ==
|
||||
dependencies:
|
||||
vscode-languageserver-types "^3.13.0"
|
||||
vscode-nls "^4.0.0"
|
||||
|
|
Loading…
Reference in a new issue