-
Notifications
You must be signed in to change notification settings - Fork 177
/
cssLanguageService.ts
150 lines (136 loc) · 7.91 KB
/
cssLanguageService.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*---------------------------------------------------------------------------------------------
* 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 { Parser } from './parser/cssParser';
import { CSSCompletion } from './services/cssCompletion';
import { CSSHover } from './services/cssHover';
import { CSSNavigation } from './services/cssNavigation';
import { CSSCodeActions } from './services/cssCodeActions';
import { CSSValidation } from './services/cssValidation';
import { SCSSParser } from './parser/scssParser';
import { SCSSCompletion } from './services/scssCompletion';
import { LESSParser } from './parser/lessParser';
import { LESSCompletion } from './services/lessCompletion';
import { getFoldingRanges } from './services/cssFolding';
import { format } from './services/cssFormatter';
import {
LanguageSettings, ICompletionParticipant, DocumentContext, LanguageServiceOptions,
Diagnostic, Position, CompletionList, Hover, Location, DocumentHighlight, DocumentLink,
SymbolInformation, Range, CodeActionContext, Command, CodeAction, ColorInformation,
Color, ColorPresentation, WorkspaceEdit, FoldingRange, SelectionRange, TextDocument,
ICSSDataProvider, CSSDataV1, HoverSettings, CompletionSettings, TextEdit, CSSFormatConfiguration, DocumentSymbol
} from './cssLanguageTypes';
import { CSSDataManager } from './languageFacts/dataManager';
import { CSSDataProvider } from './languageFacts/dataProvider';
import { getSelectionRanges } from './services/cssSelectionRange';
import { SCSSNavigation } from './services/scssNavigation';
import { cssData } from './data/webCustomData';
export type Stylesheet = {};
export * from './cssLanguageTypes';
export interface LanguageService {
configure(raw?: LanguageSettings): void;
setDataProviders(useDefaultDataProvider: boolean, customDataProviders: ICSSDataProvider[]): void;
doValidation(document: TextDocument, stylesheet: Stylesheet, documentSettings?: LanguageSettings): Diagnostic[];
parseStylesheet(document: TextDocument): Stylesheet;
doComplete(document: TextDocument, position: Position, stylesheet: Stylesheet, settings?: CompletionSettings): CompletionList;
doComplete2(document: TextDocument, position: Position, stylesheet: Stylesheet, documentContext: DocumentContext, settings?: CompletionSettings): Promise<CompletionList>;
setCompletionParticipants(registeredCompletionParticipants: ICompletionParticipant[]): void;
doHover(document: TextDocument, position: Position, stylesheet: Stylesheet, settings?: HoverSettings): Hover | null;
findDefinition(document: TextDocument, position: Position, stylesheet: Stylesheet): Location | null;
findReferences(document: TextDocument, position: Position, stylesheet: Stylesheet): Location[];
findDocumentHighlights(document: TextDocument, position: Position, stylesheet: Stylesheet): DocumentHighlight[];
findDocumentLinks(document: TextDocument, stylesheet: Stylesheet, documentContext: DocumentContext): DocumentLink[];
/**
* Return statically resolved links, and dynamically resolved links if `fsProvider` is proved.
*/
findDocumentLinks2(document: TextDocument, stylesheet: Stylesheet, documentContext: DocumentContext): Promise<DocumentLink[]>;
findDocumentSymbols(document: TextDocument, stylesheet: Stylesheet): SymbolInformation[];
findDocumentSymbols2(document: TextDocument, stylesheet: Stylesheet): DocumentSymbol[];
doCodeActions(document: TextDocument, range: Range, context: CodeActionContext, stylesheet: Stylesheet): Command[];
doCodeActions2(document: TextDocument, range: Range, context: CodeActionContext, stylesheet: Stylesheet): CodeAction[];
findDocumentColors(document: TextDocument, stylesheet: Stylesheet): ColorInformation[];
getColorPresentations(document: TextDocument, stylesheet: Stylesheet, color: Color, range: Range): ColorPresentation[];
prepareRename(document: TextDocument, position: Position, stylesheet: Stylesheet): Range | undefined;
doRename(document: TextDocument, position: Position, newName: string, stylesheet: Stylesheet): WorkspaceEdit;
getFoldingRanges(document: TextDocument, context?: { rangeLimit?: number; }): FoldingRange[];
getSelectionRanges(document: TextDocument, positions: Position[], stylesheet: Stylesheet): SelectionRange[];
format(document: TextDocument, range: Range | undefined, options: CSSFormatConfiguration): TextEdit[];
}
export function getDefaultCSSDataProvider(): ICSSDataProvider {
return newCSSDataProvider(cssData);
}
export function newCSSDataProvider(data: CSSDataV1): ICSSDataProvider {
return new CSSDataProvider(data);
}
function createFacade(parser: Parser, completion: CSSCompletion, hover: CSSHover, navigation: CSSNavigation, codeActions: CSSCodeActions, validation: CSSValidation, cssDataManager: CSSDataManager): LanguageService {
return {
configure: (settings) => {
validation.configure(settings);
completion.configure(settings?.completion);
hover.configure(settings?.hover);
navigation.configure(settings?.importAliases);
},
setDataProviders: cssDataManager.setDataProviders.bind(cssDataManager),
doValidation: validation.doValidation.bind(validation),
parseStylesheet: parser.parseStylesheet.bind(parser),
doComplete: completion.doComplete.bind(completion),
doComplete2: completion.doComplete2.bind(completion),
setCompletionParticipants: completion.setCompletionParticipants.bind(completion),
doHover: hover.doHover.bind(hover),
format,
findDefinition: navigation.findDefinition.bind(navigation),
findReferences: navigation.findReferences.bind(navigation),
findDocumentHighlights: navigation.findDocumentHighlights.bind(navigation),
findDocumentLinks: navigation.findDocumentLinks.bind(navigation),
findDocumentLinks2: navigation.findDocumentLinks2.bind(navigation),
findDocumentSymbols: navigation.findSymbolInformations.bind(navigation),
findDocumentSymbols2: navigation.findDocumentSymbols.bind(navigation),
doCodeActions: codeActions.doCodeActions.bind(codeActions),
doCodeActions2: codeActions.doCodeActions2.bind(codeActions),
findDocumentColors: navigation.findDocumentColors.bind(navigation),
getColorPresentations: navigation.getColorPresentations.bind(navigation),
prepareRename: navigation.prepareRename.bind(navigation),
doRename: navigation.doRename.bind(navigation),
getFoldingRanges,
getSelectionRanges
};
}
const defaultLanguageServiceOptions = {};
export function getCSSLanguageService(options: LanguageServiceOptions = defaultLanguageServiceOptions): LanguageService {
const cssDataManager = new CSSDataManager(options);
return createFacade(
new Parser(),
new CSSCompletion(null, options, cssDataManager),
new CSSHover(options && options.clientCapabilities, cssDataManager),
new CSSNavigation(options && options.fileSystemProvider, false),
new CSSCodeActions(cssDataManager),
new CSSValidation(cssDataManager),
cssDataManager
);
}
export function getSCSSLanguageService(options: LanguageServiceOptions = defaultLanguageServiceOptions): LanguageService {
const cssDataManager = new CSSDataManager(options);
return createFacade(
new SCSSParser(),
new SCSSCompletion(options, cssDataManager),
new CSSHover(options && options.clientCapabilities, cssDataManager),
new SCSSNavigation(options && options.fileSystemProvider),
new CSSCodeActions(cssDataManager),
new CSSValidation(cssDataManager),
cssDataManager
);
}
export function getLESSLanguageService(options: LanguageServiceOptions = defaultLanguageServiceOptions): LanguageService {
const cssDataManager = new CSSDataManager(options);
return createFacade(
new LESSParser(),
new LESSCompletion(options, cssDataManager),
new CSSHover(options && options.clientCapabilities, cssDataManager),
new CSSNavigation(options && options.fileSystemProvider, true),
new CSSCodeActions(cssDataManager),
new CSSValidation(cssDataManager),
cssDataManager
);
}