-
Notifications
You must be signed in to change notification settings - Fork 109
/
htmlLanguageService.ts
131 lines (118 loc) · 3.8 KB
/
htmlLanguageService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {createScanner} from './parser/htmlScanner';
import {parse} from './parser/htmlParser';
import {doComplete} from './services/htmlCompletion';
import {doHover} from './services/htmlHover';
import {format} from './services/htmlFormatter';
import {findDocumentLinks} from './services/htmlLinks';
import {findDocumentHighlights} from './services/htmlHighlighting';
import {findDocumentSymbols} from './services/htmlSymbolsProvider';
import {TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, DocumentHighlight, FormattingOptions, MarkedString, DocumentLink } from 'vscode-languageserver-types';
export {TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, DocumentHighlight, FormattingOptions, MarkedString, DocumentLink };
export interface HTMLFormatConfiguration {
tabSize: number;
insertSpaces: boolean;
wrapLineLength: number;
unformatted: string;
contentUnformatted: string;
indentInnerHtml: boolean;
wrapAttributes: 'auto' | 'force' | 'force-aligned' | 'force-expand-multiline';
preserveNewLines: boolean;
maxPreserveNewLines: number;
indentHandlebars: boolean;
endWithNewline: boolean;
extraLiners: string;
}
export interface CompletionConfiguration {
[provider: string]: boolean;
}
export interface Node {
tag: string;
start: number;
end: number;
endTagStart: number;
children: Node[];
parent: Node;
attributes?: {[name: string]: string};
}
export enum TokenType {
StartCommentTag,
Comment,
EndCommentTag,
StartTagOpen,
StartTagClose,
StartTagSelfClose,
StartTag,
EndTagOpen,
EndTagClose,
EndTag,
DelimiterAssign,
AttributeName,
AttributeValue,
StartDoctypeTag,
Doctype,
EndDoctypeTag,
Content,
Whitespace,
Unknown,
Script,
Styles,
EOS
}
export enum ScannerState {
WithinContent,
AfterOpeningStartTag,
AfterOpeningEndTag,
WithinDoctype,
WithinTag,
WithinEndTag,
WithinComment,
WithinScriptContent,
WithinStyleContent,
AfterAttributeName,
BeforeAttributeValue
}
export interface Scanner {
scan(): TokenType;
getTokenType(): TokenType;
getTokenOffset(): number;
getTokenLength(): number;
getTokenEnd(): number;
getTokenText(): string;
getTokenError(): string;
getScannerState(): ScannerState;
}
export declare type HTMLDocument = {
roots: Node[];
findNodeBefore(offset: number): Node;
findNodeAt(offset: number): Node;
};
export interface DocumentContext {
resolveReference(ref: string, base?: string): string;
}
export interface LanguageService {
createScanner(input: string): Scanner;
parseHTMLDocument(document: TextDocument): HTMLDocument;
findDocumentHighlights(document: TextDocument, position: Position, htmlDocument: HTMLDocument): DocumentHighlight[];
doComplete(document: TextDocument, position: Position, htmlDocument: HTMLDocument, options?: CompletionConfiguration): CompletionList;
doHover(document: TextDocument, position: Position, htmlDocument: HTMLDocument): Hover;
format(document: TextDocument, range: Range, options: HTMLFormatConfiguration): TextEdit[];
findDocumentLinks(document: TextDocument, documentContext: DocumentContext): DocumentLink[];
findDocumentSymbols(document: TextDocument, htmlDocument: HTMLDocument): SymbolInformation[];
}
export function getLanguageService(): LanguageService {
return {
createScanner,
parseHTMLDocument: document => parse(document.getText()),
doComplete,
doHover,
format,
findDocumentHighlights,
findDocumentLinks,
findDocumentSymbols
};
}