mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Load html data using new API per Microsoft/vscode-html-languageservice#45
This commit is contained in:
@@ -20,8 +20,8 @@ import uri from 'vscode-uri';
|
||||
import { formatError, runSafe, runSafeAsync } from './utils/runner';
|
||||
|
||||
import { getFoldingRanges } from './modes/htmlFolding';
|
||||
import { parseTagSet, parseAttributes } from './utils/tagDefinitions';
|
||||
import { ITagSet, IAttributeSet } from 'vscode-html-languageservice';
|
||||
import { parseHTMLData } from './utils/tagDefinitions';
|
||||
import { HTMLData } from 'vscode-html-languageservice';
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string | null, any, any> = new RequestType('html/tag');
|
||||
@@ -91,18 +91,24 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
||||
}
|
||||
}
|
||||
|
||||
const tagPaths: string[] = params.initializationOptions.tagPaths;
|
||||
const attributePaths: string[] = params.initializationOptions.attributePaths;
|
||||
const htmlTags: ITagSet = {};
|
||||
const htmlAttributes: IAttributeSet = {};
|
||||
const dataPaths: string[] = params.initializationOptions.dataPaths;
|
||||
|
||||
if (tagPaths) {
|
||||
tagPaths.forEach(path => {
|
||||
let allHtmlData: HTMLData = {
|
||||
tags: [],
|
||||
globalAttributes: [],
|
||||
valueSetMap: {}
|
||||
};
|
||||
|
||||
if (dataPaths) {
|
||||
dataPaths.forEach(path => {
|
||||
try {
|
||||
if (fs.existsSync(path)) {
|
||||
const tagSet = parseTagSet(fs.readFileSync(path, 'utf-8'));
|
||||
for (let tag in tagSet) {
|
||||
htmlTags[tag] = tagSet[tag];
|
||||
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) {
|
||||
@@ -110,27 +116,13 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (htmlAttributes) {
|
||||
attributePaths.forEach(path => {
|
||||
try {
|
||||
if (fs.existsSync(path)) {
|
||||
const attributeSet = parseAttributes(fs.readFileSync(path, 'utf-8'));
|
||||
for (let ga in attributeSet) {
|
||||
htmlAttributes[ga] = attributeSet[ga];
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`Failed to load attributes from ${path}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const workspace = {
|
||||
get settings() { return globalSettings; },
|
||||
get folders() { return workspaceFolders; }
|
||||
};
|
||||
|
||||
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }, workspace, htmlTags, htmlAttributes);
|
||||
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }, workspace, allHtmlData);
|
||||
|
||||
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, ITagSet, IAttributeSet } from 'vscode-html-languageservice';
|
||||
import { getLanguageService as getHTMLLanguageService, DocumentContext, HTMLData } from 'vscode-html-languageservice';
|
||||
import {
|
||||
CompletionItem, Location, SignatureHelp, Definition, TextEdit, TextDocument, Diagnostic, DocumentLink, Range,
|
||||
Hover, DocumentHighlight, CompletionList, Position, FormattingOptions, SymbolInformation, FoldingRange
|
||||
@@ -65,11 +65,10 @@ export interface LanguageModeRange extends Range {
|
||||
attributeValue?: boolean;
|
||||
}
|
||||
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, customTags?: ITagSet, customAttributes?: IAttributeSet): LanguageModes {
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, customData?: HTMLData): LanguageModes {
|
||||
|
||||
const htmlLanguageService = getHTMLLanguageService({
|
||||
customTags,
|
||||
customAttributes
|
||||
customData
|
||||
});
|
||||
|
||||
let documentRegions = getLanguageModelCache<HTMLDocumentRegions>(10, 60, document => getDocumentRegions(htmlLanguageService, document));
|
||||
|
||||
@@ -3,56 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ITagSet, IAttributeSet, HTMLTagSpecification } from 'vscode-html-languageservice';
|
||||
import { HTMLData } from 'vscode-html-languageservice';
|
||||
|
||||
interface Tag {
|
||||
label: string;
|
||||
description: string;
|
||||
attributes: Attribute[];
|
||||
}
|
||||
interface Attribute {
|
||||
label: string;
|
||||
description: string;
|
||||
}
|
||||
interface RawTagSet {
|
||||
tags: Tag[];
|
||||
}
|
||||
interface RawAttributeSet {
|
||||
attributes: Attribute[];
|
||||
}
|
||||
|
||||
export function parseTagSet(source: string): ITagSet {
|
||||
const tagSet: ITagSet = {};
|
||||
|
||||
let rawTagSet: RawTagSet;
|
||||
try {
|
||||
rawTagSet = JSON.parse(source);
|
||||
} catch (err) {
|
||||
return {};
|
||||
}
|
||||
|
||||
rawTagSet.tags.forEach(c => {
|
||||
tagSet[c.label] = new HTMLTagSpecification(c.description, c.attributes.map(a => a.label));
|
||||
});
|
||||
|
||||
return tagSet;
|
||||
}
|
||||
|
||||
export function parseAttributes(source: string): IAttributeSet {
|
||||
const attributeSet: IAttributeSet = {};
|
||||
|
||||
let rawAttributeSet: RawAttributeSet;
|
||||
try {
|
||||
rawAttributeSet = JSON.parse(source);
|
||||
} catch (err) {
|
||||
return {};
|
||||
}
|
||||
|
||||
rawAttributeSet.attributes.forEach(ag => {
|
||||
attributeSet[ag.label] = {
|
||||
...ag
|
||||
};
|
||||
});
|
||||
|
||||
return attributeSet;
|
||||
export function parseHTMLData(source: string): HTMLData {
|
||||
return JSON.parse(source);
|
||||
}
|
||||
Reference in New Issue
Block a user