Skip to content

Commit 4773ebb

Browse files
committed
Refactor custom data support.
Changes: - Feature: HTML attribute completion documentation - Rename: tagProvider -> dataProvider - API: Now in sync with CSS LS API - HTMLTagSpecification converted to serializable plain data structure so does attributes and attribute values - Remove Angular1/Ionic1 support - Remove i18n for HTML tags, and manage them in a plain JSON-like file because - We don't have i18n support in LSP yet - There's no translation yet - The JSON-like file is typed and can be easily mainaintaed - We'll start pulling data from W3C HTML spec and MDN to do features such as short descriptions, browser support table adn syntax. Such plain JSON-like files are easy to auto-generate. - Unblocks #12, #30, #44 Fixes: - Fix microsoft/vscode#2784 - Part of microsoft/vscode#63955 (no CompletionItem.documentation for attr value yet)
1 parent cf89bd3 commit 4773ebb

16 files changed

+2055
-816
lines changed

src/htmlLanguageService.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { findDocumentSymbols } from './services/htmlSymbolsProvider';
1515
import { TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, TextEdit, DocumentHighlight, DocumentLink, FoldingRange } from 'vscode-languageserver-types';
1616
import { Scanner, HTMLDocument, CompletionConfiguration, ICompletionParticipant, HTMLFormatConfiguration, DocumentContext } from './htmlLanguageTypes';
1717
import { getFoldingRanges } from './services/htmlFolding';
18-
import { addTags, addAttributes } from './services/tagProviders';
19-
import { ITagSet, IAttributeSet } from './parser/htmlTags';
18+
import { addCustomData } from './languageFacts';
19+
import { HTMLData } from './languageFacts';
2020

21-
export { HTMLTagSpecification, ITagSet, IAttributeSet } from './parser/htmlTags';
2221
export * from './htmlLanguageTypes';
2322
export * from 'vscode-languageserver-types';
2423

@@ -37,20 +36,14 @@ export interface LanguageService {
3736
}
3837

3938
export interface LanguageServiceOptions {
40-
customTags?: ITagSet;
41-
customAttributes?: IAttributeSet;
39+
customData?: HTMLData;
4240
}
4341

4442
export function getLanguageService(options?: LanguageServiceOptions): LanguageService {
4543
const htmlCompletion = new HTMLCompletion();
4644

47-
if (options) {
48-
if (options.customTags) {
49-
addTags(options.customTags);
50-
}
51-
if (options.customAttributes) {
52-
addAttributes(options.customAttributes);
53-
}
45+
if (options && options.customData) {
46+
addCustomData(options.customData);
5447
}
5548

5649
return {

src/htmlLanguageTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
import { TextDocument, Position, Range } from 'vscode-languageserver-types';
8+
export { IEntryData, ITagEntryData, IAttributeEntryData, HTMLData } from './languageFacts';
89

910
export interface HTMLFormatConfiguration {
1011
tabSize?: number;
@@ -114,4 +115,4 @@ export interface HtmlContentContext {
114115
export interface ICompletionParticipant {
115116
onHtmlAttributeValue?: (context: HtmlAttributeValueContext) => void;
116117
onHtmlContent?: (context: HtmlContentContext) => void;
117-
}
118+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { getRazorDataProvider } from './data/razor';
8+
import { getHTML5DataProvider } from './data/html5';
9+
import { IHTMLDataProvider, HTMLData, HTMLDataProvider } from './dataProvider';
10+
11+
export const builtinDataProviders: IHTMLDataProvider[] = [
12+
getHTML5DataProvider()
13+
];
14+
15+
const customDataProviders: IHTMLDataProvider[] = [
16+
getRazorDataProvider()
17+
];
18+
19+
export function getAllDataProviders(): IHTMLDataProvider[] {
20+
return builtinDataProviders.concat(customDataProviders);
21+
}
22+
23+
export function addCustomData(customData: HTMLData) {
24+
customDataProviders.push(new HTMLDataProvider('customData', customData));
25+
}

0 commit comments

Comments
 (0)