Skip to content

Commit f19bc0b

Browse files
authored
Merge pull request #125 from hahn-kev/main
Allow void elements to be specified in data provider
2 parents e7ae8a7 + dd79847 commit f19bc0b

File tree

11 files changed

+448
-402
lines changed

11 files changed

+448
-402
lines changed

src/htmlLanguageService.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { createScanner } from './parser/htmlScanner';
7-
import { parse } from './parser/htmlParser';
7+
import { HTMLParser } from './parser/htmlParser';
88
import { HTMLCompletion } from './services/htmlCompletion';
99
import { HTMLHover } from './services/htmlHover';
1010
import { format } from './services/htmlFormatter';
@@ -19,8 +19,8 @@ import {
1919
IHTMLDataProvider, HTMLDataV1, LanguageServiceOptions, TextDocument, SelectionRange, WorkspaceEdit,
2020
Position, CompletionList, Hover, Range, SymbolInformation, TextEdit, DocumentHighlight, DocumentLink, FoldingRange, HoverSettings
2121
} from './htmlLanguageTypes';
22-
import { getFoldingRanges } from './services/htmlFolding';
23-
import { getSelectionRanges } from './services/htmlSelectionRange';
22+
import { HTMLFolding } from './services/htmlFolding';
23+
import { HTMLSelectionRange } from './services/htmlSelectionRange';
2424
import { HTMLDataProvider } from './languageFacts/dataProvider';
2525
import { HTMLDataManager } from './languageFacts/dataManager';
2626
import { htmlData } from './languageFacts/data/webCustomData';
@@ -57,11 +57,14 @@ export function getLanguageService(options: LanguageServiceOptions = defaultLang
5757

5858
const htmlHover = new HTMLHover(options, dataManager);
5959
const htmlCompletion = new HTMLCompletion(options, dataManager);
60+
const htmlParser = new HTMLParser(dataManager);
61+
const htmlSelectionRange = new HTMLSelectionRange(htmlParser);
62+
const htmlFolding = new HTMLFolding(dataManager);
6063

6164
return {
6265
setDataProviders: dataManager.setDataProviders.bind(dataManager),
6366
createScanner,
64-
parseHTMLDocument: document => parse(document.getText()),
67+
parseHTMLDocument: htmlParser.parseDocument.bind(htmlParser),
6568
doComplete: htmlCompletion.doComplete.bind(htmlCompletion),
6669
doComplete2: htmlCompletion.doComplete2.bind(htmlCompletion),
6770
setCompletionParticipants: htmlCompletion.setCompletionParticipants.bind(htmlCompletion),
@@ -70,8 +73,8 @@ export function getLanguageService(options: LanguageServiceOptions = defaultLang
7073
findDocumentHighlights,
7174
findDocumentLinks,
7275
findDocumentSymbols,
73-
getFoldingRanges,
74-
getSelectionRanges,
76+
getFoldingRanges: htmlFolding.getFoldingRanges.bind(htmlFolding),
77+
getSelectionRanges: htmlSelectionRange.getSelectionRanges.bind(htmlSelectionRange),
7578
doQuoteComplete: htmlCompletion.doQuoteComplete.bind(htmlCompletion),
7679
doTagComplete: htmlCompletion.doTagComplete.bind(htmlCompletion),
7780
doRename,

src/htmlLanguageTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export interface ITagData {
160160
description?: string | MarkupContent;
161161
attributes: IAttributeData[];
162162
references?: IReference[];
163+
void?: boolean
163164
}
164165

165166
export interface IAttributeData {

src/languageFacts/data/webCustomData.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const htmlData : HTMLDataV1 = {
7878
"kind": "markdown",
7979
"value": "The base element allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information."
8080
},
81+
"void": true,
8182
"attributes": [
8283
{
8384
"name": "href",
@@ -108,6 +109,7 @@ export const htmlData : HTMLDataV1 = {
108109
"kind": "markdown",
109110
"value": "The link element allows authors to link their document to other resources."
110111
},
112+
"void": true,
111113
"attributes": [
112114
{
113115
"name": "href",
@@ -197,6 +199,7 @@ export const htmlData : HTMLDataV1 = {
197199
"kind": "markdown",
198200
"value": "The meta element represents various kinds of metadata that cannot be expressed using the title, base, link, style, and script elements."
199201
},
202+
"void": true,
200203
"attributes": [
201204
{
202205
"name": "name",
@@ -650,6 +653,7 @@ export const htmlData : HTMLDataV1 = {
650653
"kind": "markdown",
651654
"value": "The hr element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book."
652655
},
656+
"void": true,
653657
"attributes": [
654658
{
655659
"name": "align",
@@ -1378,6 +1382,7 @@ export const htmlData : HTMLDataV1 = {
13781382
"kind": "markdown",
13791383
"value": "The br element represents a line break."
13801384
},
1385+
"void": true,
13811386
"attributes": [
13821387
{
13831388
"name": "clear",
@@ -1397,6 +1402,7 @@ export const htmlData : HTMLDataV1 = {
13971402
"kind": "markdown",
13981403
"value": "The wbr element represents a line break opportunity."
13991404
},
1405+
"void": true,
14001406
"attributes": [],
14011407
"references": [
14021408
{
@@ -1477,6 +1483,7 @@ export const htmlData : HTMLDataV1 = {
14771483
"kind": "markdown",
14781484
"value": "An img element represents an image."
14791485
},
1486+
"void": true,
14801487
"attributes": [
14811488
{
14821489
"name": "alt",
@@ -1672,6 +1679,7 @@ export const htmlData : HTMLDataV1 = {
16721679
"kind": "markdown",
16731680
"value": "The embed element provides an integration point for an external (typically non-HTML) application or interactive content."
16741681
},
1682+
"void": true,
16751683
"attributes": [
16761684
{
16771685
"name": "src",
@@ -1819,6 +1827,7 @@ export const htmlData : HTMLDataV1 = {
18191827
"kind": "markdown",
18201828
"value": "The param element defines parameters for plugins invoked by object elements. It does not represent anything on its own."
18211829
},
1830+
"void": true,
18221831
"attributes": [
18231832
{
18241833
"name": "name",
@@ -1987,6 +1996,7 @@ export const htmlData : HTMLDataV1 = {
19871996
"kind": "markdown",
19881997
"value": "The source element allows authors to specify multiple alternative media resources for media elements. It does not represent anything on its own."
19891998
},
1999+
"void": true,
19902000
"attributes": [
19912001
{
19922002
"name": "src",
@@ -2028,6 +2038,7 @@ export const htmlData : HTMLDataV1 = {
20282038
"kind": "markdown",
20292039
"value": "The track element allows authors to specify explicit external timed text tracks for media elements. It does not represent anything on its own."
20302040
},
2041+
"void": true,
20312042
"attributes": [
20322043
{
20332044
"name": "default",
@@ -2102,6 +2113,7 @@ export const htmlData : HTMLDataV1 = {
21022113
"kind": "markdown",
21032114
"value": "The area element represents either a hyperlink with some text and a corresponding area on an image map, or a dead area on an image map."
21042115
},
2116+
"void": true,
21052117
"attributes": [
21062118
{
21072119
"name": "alt"
@@ -2216,6 +2228,7 @@ export const htmlData : HTMLDataV1 = {
22162228
"kind": "markdown",
22172229
"value": "If a col element has a parent and that is a colgroup element that itself has a parent that is a table element, then the col element represents one or more columns in the column group represented by that colgroup."
22182230
},
2231+
"void": true,
22192232
"attributes": [
22202233
{
22212234
"name": "span"
@@ -2517,6 +2530,7 @@ export const htmlData : HTMLDataV1 = {
25172530
"kind": "markdown",
25182531
"value": "The input element represents a typed data field, usually with a form control to allow the user to edit the data."
25192532
},
2533+
"void": true,
25202534
"attributes": [
25212535
{
25222536
"name": "accept"
@@ -6049,4 +6063,4 @@ export const htmlData : HTMLDataV1 = {
60496063
]
60506064
}
60516065
]
6052-
};
6066+
};

src/languageFacts/dataManager.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { IHTMLDataProvider } from '../htmlLanguageTypes';
77
import { HTMLDataProvider } from './dataProvider';
88
import { htmlData } from './data/webCustomData';
9+
import * as arrays from '../utils/arrays';
910

1011
export class HTMLDataManager {
1112
private dataProviders: IHTMLDataProvider[] = [];
@@ -24,4 +25,19 @@ export class HTMLDataManager {
2425
getDataProviders() {
2526
return this.dataProviders;
2627
}
27-
}
28+
29+
isVoidElement(e: string, voidElements: string[]) {
30+
return !!e && arrays.binarySearch(voidElements, e.toLowerCase(), (s1: string, s2: string) => s1.localeCompare(s2)) >= 0;
31+
}
32+
33+
getVoidElements(languageId: string):string[];
34+
getVoidElements(dataProviders: IHTMLDataProvider[]): string[];
35+
getVoidElements(languageOrProviders: string| IHTMLDataProvider[]): string[] {
36+
const dataProviders = Array.isArray(languageOrProviders) ? languageOrProviders : this.getDataProviders().filter(p => p.isApplicable(languageOrProviders!));
37+
const voidTags: string[] = [];
38+
dataProviders.forEach((provider) => {
39+
provider.provideTags().filter(tag => tag.void).forEach(tag => voidTags.push(tag.name));
40+
});
41+
return voidTags.sort();
42+
}
43+
}

src/languageFacts/fact.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)