mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 00:59:03 +01:00
Update service and adopt HTML provider interface
This commit is contained in:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user