@astrojs/language-server 1.0.4 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -5
- package/bin/nodeServer.js +7 -3
- package/dist/core/astro2tsx.d.ts +6 -0
- package/dist/core/astro2tsx.js +119 -0
- package/dist/core/compilerUtils.d.ts +27 -0
- package/dist/core/compilerUtils.js +52 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +119 -0
- package/dist/core/parseAstro.d.ts +27 -0
- package/dist/core/parseAstro.js +47 -0
- package/dist/core/parseCSS.d.ts +7 -0
- package/dist/core/parseCSS.js +116 -0
- package/dist/core/parseHTML.d.ts +7 -0
- package/dist/core/parseHTML.js +113 -0
- package/dist/core/parseJS.d.ts +7 -0
- package/dist/core/parseJS.js +236 -0
- package/dist/core/svelte.d.ts +18 -0
- package/dist/core/svelte.js +45 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/core/utils.js +138 -0
- package/dist/core/vue.d.ts +18 -0
- package/dist/core/vue.js +45 -0
- package/dist/importPackage.d.ts +1 -1
- package/dist/importPackage.js +4 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +26 -6
- package/dist/languageServerPlugin.d.ts +2 -0
- package/dist/languageServerPlugin.js +76 -0
- package/dist/nodeServer.js +6 -0
- package/dist/plugins/astro.d.ts +3 -0
- package/dist/plugins/astro.js +123 -0
- package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +33 -0
- package/dist/plugins/typescript/codeActions.d.ts +4 -0
- package/dist/plugins/typescript/codeActions.js +49 -0
- package/dist/plugins/typescript/completions.d.ts +3 -0
- package/dist/plugins/typescript/completions.js +81 -0
- package/dist/plugins/typescript/diagnostics.d.ts +12 -0
- package/dist/plugins/typescript/diagnostics.js +99 -0
- package/dist/plugins/typescript/index.d.ts +3 -0
- package/dist/plugins/typescript/index.js +57 -0
- package/dist/utils.d.ts +19 -69
- package/dist/utils.js +66 -239
- package/package.json +37 -38
- package/types/astro-jsx.d.ts +49 -5
- package/bin/browserServer.js +0 -3
- package/dist/browser.js +0 -15
- package/dist/check.d.ts +0 -23
- package/dist/check.js +0 -60
- package/dist/core/DiagnosticsManager.d.ts +0 -13
- package/dist/core/DiagnosticsManager.js +0 -29
- package/dist/core/config/ConfigManager.d.ts +0 -43
- package/dist/core/config/ConfigManager.js +0 -226
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -18
- package/dist/core/config/interfaces.d.ts +0 -77
- package/dist/core/config/interfaces.js +0 -2
- package/dist/core/documents/AstroDocument.d.ts +0 -19
- package/dist/core/documents/AstroDocument.js +0 -43
- package/dist/core/documents/DocumentBase.d.ts +0 -68
- package/dist/core/documents/DocumentBase.js +0 -75
- package/dist/core/documents/DocumentManager.d.ts +0 -23
- package/dist/core/documents/DocumentManager.js +0 -100
- package/dist/core/documents/DocumentMapper.d.ts +0 -94
- package/dist/core/documents/DocumentMapper.js +0 -264
- package/dist/core/documents/index.d.ts +0 -5
- package/dist/core/documents/index.js +0 -21
- package/dist/core/documents/parseAstro.d.ts +0 -15
- package/dist/core/documents/parseAstro.js +0 -63
- package/dist/core/documents/parseHtml.d.ts +0 -13
- package/dist/core/documents/parseHtml.js +0 -126
- package/dist/core/documents/utils.d.ts +0 -63
- package/dist/core/documents/utils.js +0 -223
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -43
- package/dist/plugins/PluginHost.d.ts +0 -42
- package/dist/plugins/PluginHost.js +0 -206
- package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
- package/dist/plugins/astro/AstroPlugin.js +0 -90
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
- package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
- package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
- package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
- package/dist/plugins/css/CSSDocument.d.ts +0 -45
- package/dist/plugins/css/CSSDocument.js +0 -68
- package/dist/plugins/css/CSSPlugin.d.ts +0 -39
- package/dist/plugins/css/CSSPlugin.js +0 -274
- package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
- package/dist/plugins/css/StyleAttributeDocument.js +0 -64
- package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
- package/dist/plugins/css/features/astro-selectors.js +0 -15
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
- package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
- package/dist/plugins/css/language-service.d.ts +0 -3
- package/dist/plugins/css/language-service.js +0 -47
- package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
- package/dist/plugins/html/HTMLPlugin.js +0 -198
- package/dist/plugins/html/utils.d.ts +0 -6
- package/dist/plugins/html/utils.js +0 -11
- package/dist/plugins/index.d.ts +0 -6
- package/dist/plugins/index.js +0 -22
- package/dist/plugins/interfaces.d.ts +0 -101
- package/dist/plugins/interfaces.js +0 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
- package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
- package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
- package/dist/plugins/typescript/astro-sys.d.ts +0 -8
- package/dist/plugins/typescript/astro-sys.js +0 -46
- package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -26
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
- package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
- package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
- package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
- package/dist/plugins/typescript/features/HoverProvider.js +0 -50
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
- package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/RenameProvider.js +0 -60
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
- package/dist/plugins/typescript/features/utils.d.ts +0 -14
- package/dist/plugins/typescript/features/utils.js +0 -48
- package/dist/plugins/typescript/language-service.d.ts +0 -42
- package/dist/plugins/typescript/language-service.js +0 -277
- package/dist/plugins/typescript/module-loader.d.ts +0 -23
- package/dist/plugins/typescript/module-loader.js +0 -155
- package/dist/plugins/typescript/previewer.d.ts +0 -7
- package/dist/plugins/typescript/previewer.js +0 -108
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
- package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
- package/dist/plugins/typescript/snapshots/utils.js +0 -106
- package/dist/plugins/typescript/utils.d.ts +0 -75
- package/dist/plugins/typescript/utils.js +0 -366
- package/dist/server.d.ts +0 -6
- package/dist/server.js +0 -275
- package/types/README.md +0 -5
- /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
- /package/dist/plugins/{html/features/astro-attributes.d.ts → html-data.d.ts} +0 -0
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PluginHost = void 0;
|
|
4
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const documents_1 = require("../core/documents");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
var ExecuteMode;
|
|
8
|
-
(function (ExecuteMode) {
|
|
9
|
-
ExecuteMode[ExecuteMode["None"] = 0] = "None";
|
|
10
|
-
ExecuteMode[ExecuteMode["FirstNonNull"] = 1] = "FirstNonNull";
|
|
11
|
-
ExecuteMode[ExecuteMode["Collect"] = 2] = "Collect";
|
|
12
|
-
})(ExecuteMode || (ExecuteMode = {}));
|
|
13
|
-
class PluginHost {
|
|
14
|
-
constructor(docManager) {
|
|
15
|
-
this.docManager = docManager;
|
|
16
|
-
this.plugins = [];
|
|
17
|
-
this.pluginHostConfig = {
|
|
18
|
-
filterIncompleteCompletions: true,
|
|
19
|
-
definitionLinkSupport: false,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
initialize(pluginHostConfig) {
|
|
23
|
-
this.pluginHostConfig = pluginHostConfig;
|
|
24
|
-
}
|
|
25
|
-
registerPlugin(plugin) {
|
|
26
|
-
this.plugins.push(plugin);
|
|
27
|
-
}
|
|
28
|
-
async getCompletions(textDocument, position, completionContext, cancellationToken) {
|
|
29
|
-
const document = this.getDocument(textDocument.uri);
|
|
30
|
-
const completions = await Promise.all(this.plugins.map(async (plugin) => {
|
|
31
|
-
const result = await this.tryExecutePlugin(plugin, 'getCompletions', [document, position, completionContext, cancellationToken], null);
|
|
32
|
-
if (result) {
|
|
33
|
-
return { result: result, plugin: plugin.__name };
|
|
34
|
-
}
|
|
35
|
-
})).then((fullCompletions) => fullCompletions.filter(utils_1.isNotNullOrUndefined));
|
|
36
|
-
const html = completions.find((completion) => completion.plugin === 'html');
|
|
37
|
-
const ts = completions.find((completion) => completion.plugin === 'typescript');
|
|
38
|
-
const astro = completions.find((completion) => completion.plugin === 'astro');
|
|
39
|
-
if (html && ts) {
|
|
40
|
-
const inComponentStartTag = (0, documents_1.isInComponentStartTag)(document.html, document.offsetAt(position));
|
|
41
|
-
// If the HTML plugin returned completions, it's highly likely that TS ones are duplicate
|
|
42
|
-
if (html.result.items.length > 0) {
|
|
43
|
-
ts.result.items = [];
|
|
44
|
-
}
|
|
45
|
-
// Inside components, if the Astro plugin has completions we don't want the TS ones are they're duplicates
|
|
46
|
-
if (astro && astro.result.items.length > 0 && inComponentStartTag) {
|
|
47
|
-
ts.result.items = [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
let flattenedCompletions = completions.flatMap((completion) => completion.result.items);
|
|
51
|
-
const isIncomplete = completions.reduce((incomplete, completion) => incomplete || completion.result.isIncomplete, false);
|
|
52
|
-
// If the result is incomplete, we need to filter the results ourselves
|
|
53
|
-
// to throw out non-matching results. VSCode does filter client-side,
|
|
54
|
-
// but other IDEs might not.
|
|
55
|
-
if (isIncomplete && this.pluginHostConfig.filterIncompleteCompletions) {
|
|
56
|
-
const offset = document.offsetAt(position);
|
|
57
|
-
// Assumption for performance reasons:
|
|
58
|
-
// Noone types import names longer than 20 characters and still expects perfect autocompletion.
|
|
59
|
-
const text = document.getText().substring(Math.max(0, offset - 20), offset);
|
|
60
|
-
const start = (0, utils_1.regexLastIndexOf)(text, /[\W\s]/g) + 1;
|
|
61
|
-
const filterValue = text.substring(start).toLowerCase();
|
|
62
|
-
flattenedCompletions = flattenedCompletions.filter((comp) => comp.label.toLowerCase().includes(filterValue));
|
|
63
|
-
}
|
|
64
|
-
return vscode_languageserver_1.CompletionList.create(flattenedCompletions, isIncomplete);
|
|
65
|
-
}
|
|
66
|
-
async resolveCompletion(textDocument, completionItem) {
|
|
67
|
-
const document = this.getDocument(textDocument.uri);
|
|
68
|
-
const result = await this.execute('resolveCompletion', [document, completionItem], ExecuteMode.FirstNonNull);
|
|
69
|
-
return result ?? completionItem;
|
|
70
|
-
}
|
|
71
|
-
async getDiagnostics(textDocument) {
|
|
72
|
-
const document = this.getDocument(textDocument.uri);
|
|
73
|
-
const diagnostics = await this.execute('getDiagnostics', [document], ExecuteMode.Collect);
|
|
74
|
-
return diagnostics;
|
|
75
|
-
}
|
|
76
|
-
async doHover(textDocument, position) {
|
|
77
|
-
const document = this.getDocument(textDocument.uri);
|
|
78
|
-
return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
|
|
79
|
-
}
|
|
80
|
-
async formatDocument(textDocument, options) {
|
|
81
|
-
const document = this.getDocument(textDocument.uri);
|
|
82
|
-
return await this.execute('formatDocument', [document, options], ExecuteMode.Collect);
|
|
83
|
-
}
|
|
84
|
-
async getCodeActions(textDocument, range, context, cancellationToken) {
|
|
85
|
-
const document = this.getDocument(textDocument.uri);
|
|
86
|
-
return await this.execute('getCodeActions', [document, range, context, cancellationToken], ExecuteMode.Collect);
|
|
87
|
-
}
|
|
88
|
-
async doTagComplete(textDocument, position) {
|
|
89
|
-
const document = this.getDocument(textDocument.uri);
|
|
90
|
-
return this.execute('doTagComplete', [document, position], ExecuteMode.FirstNonNull);
|
|
91
|
-
}
|
|
92
|
-
async getFoldingRanges(textDocument) {
|
|
93
|
-
const document = this.getDocument(textDocument.uri);
|
|
94
|
-
return await this.execute('getFoldingRanges', [document], ExecuteMode.Collect);
|
|
95
|
-
}
|
|
96
|
-
async getDocumentSymbols(textDocument, cancellationToken) {
|
|
97
|
-
const document = this.getDocument(textDocument.uri);
|
|
98
|
-
return await this.execute('getDocumentSymbols', [document, cancellationToken], ExecuteMode.Collect);
|
|
99
|
-
}
|
|
100
|
-
async getSemanticTokens(textDocument, range, cancellationToken) {
|
|
101
|
-
const document = this.getDocument(textDocument.uri);
|
|
102
|
-
return await this.execute('getSemanticTokens', [document, range, cancellationToken], ExecuteMode.FirstNonNull);
|
|
103
|
-
}
|
|
104
|
-
async getLinkedEditingRanges(textDocument, position) {
|
|
105
|
-
const document = this.getDocument(textDocument.uri);
|
|
106
|
-
return await this.execute('getLinkedEditingRanges', [document, position], ExecuteMode.FirstNonNull);
|
|
107
|
-
}
|
|
108
|
-
async fileReferences(textDocument) {
|
|
109
|
-
const document = this.getDocument(textDocument.uri);
|
|
110
|
-
return await this.execute('fileReferences', [document], ExecuteMode.FirstNonNull);
|
|
111
|
-
}
|
|
112
|
-
async getDefinitions(textDocument, position) {
|
|
113
|
-
const document = this.getDocument(textDocument.uri);
|
|
114
|
-
const definitions = await this.execute('getDefinitions', [document, position], ExecuteMode.Collect);
|
|
115
|
-
if (this.pluginHostConfig.definitionLinkSupport) {
|
|
116
|
-
return definitions;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return definitions.map((def) => ({ range: def.targetSelectionRange, uri: def.targetUri }));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
getTypeDefinitions(textDocument, position) {
|
|
123
|
-
const document = this.getDocument(textDocument.uri);
|
|
124
|
-
return this.execute('getTypeDefinitions', [document, position], ExecuteMode.FirstNonNull);
|
|
125
|
-
}
|
|
126
|
-
getImplementations(textDocument, position) {
|
|
127
|
-
const document = this.getDocument(textDocument.uri);
|
|
128
|
-
return this.execute('getImplementation', [document, position], ExecuteMode.FirstNonNull);
|
|
129
|
-
}
|
|
130
|
-
getReferences(textdocument, position, context) {
|
|
131
|
-
const document = this.getDocument(textdocument.uri);
|
|
132
|
-
return this.execute('findReferences', [document, position, context], ExecuteMode.FirstNonNull);
|
|
133
|
-
}
|
|
134
|
-
async prepareRename(textDocument, position) {
|
|
135
|
-
const document = this.getDocument(textDocument.uri);
|
|
136
|
-
return await this.execute('prepareRename', [document, position], ExecuteMode.FirstNonNull);
|
|
137
|
-
}
|
|
138
|
-
async rename(textDocument, position, newName) {
|
|
139
|
-
const document = this.getDocument(textDocument.uri);
|
|
140
|
-
return this.execute('rename', [document, position, newName], ExecuteMode.FirstNonNull);
|
|
141
|
-
}
|
|
142
|
-
async getDocumentColors(textDocument) {
|
|
143
|
-
const document = this.getDocument(textDocument.uri);
|
|
144
|
-
return await this.execute('getDocumentColors', [document], ExecuteMode.Collect);
|
|
145
|
-
}
|
|
146
|
-
async getColorPresentations(textDocument, range, color) {
|
|
147
|
-
const document = this.getDocument(textDocument.uri);
|
|
148
|
-
return await this.execute('getColorPresentations', [document, range, color], ExecuteMode.Collect);
|
|
149
|
-
}
|
|
150
|
-
async getInlayHints(textDocument, range, cancellationToken) {
|
|
151
|
-
const document = this.getDocument(textDocument.uri);
|
|
152
|
-
return (await this.execute('getInlayHints', [document, range], ExecuteMode.FirstNonNull)) ?? [];
|
|
153
|
-
}
|
|
154
|
-
async getSignatureHelp(textDocument, position, context, cancellationToken) {
|
|
155
|
-
const document = this.getDocument(textDocument.uri);
|
|
156
|
-
return await this.execute('getSignatureHelp', [document, position, context, cancellationToken], ExecuteMode.FirstNonNull);
|
|
157
|
-
}
|
|
158
|
-
async onWatchFileChanges(onWatchFileChangesParams) {
|
|
159
|
-
for (const support of this.plugins) {
|
|
160
|
-
await support.onWatchFileChanges?.(onWatchFileChangesParams);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
updateNonAstroFile(fileName, changes, text) {
|
|
164
|
-
for (const support of this.plugins) {
|
|
165
|
-
support.updateNonAstroFile?.(fileName, changes, text);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
getDocument(uri) {
|
|
169
|
-
const document = this.docManager.get(uri);
|
|
170
|
-
if (!document) {
|
|
171
|
-
throw new Error('Cannot call methods on an unopened document');
|
|
172
|
-
}
|
|
173
|
-
return document;
|
|
174
|
-
}
|
|
175
|
-
async execute(name, args, mode) {
|
|
176
|
-
const plugins = this.plugins.filter((plugin) => typeof plugin[name] === 'function');
|
|
177
|
-
switch (mode) {
|
|
178
|
-
case ExecuteMode.FirstNonNull:
|
|
179
|
-
for (const plugin of plugins) {
|
|
180
|
-
const res = await this.tryExecutePlugin(plugin, name, args, null);
|
|
181
|
-
if (res != null) {
|
|
182
|
-
return res;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return null;
|
|
186
|
-
case ExecuteMode.Collect:
|
|
187
|
-
return (await Promise.all(plugins.map((plugin) => {
|
|
188
|
-
let ret = this.tryExecutePlugin(plugin, name, args, []);
|
|
189
|
-
return ret;
|
|
190
|
-
}))).flat();
|
|
191
|
-
case ExecuteMode.None:
|
|
192
|
-
await Promise.all(plugins.map((plugin) => this.tryExecutePlugin(plugin, name, args, null)));
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async tryExecutePlugin(plugin, fnName, args, failValue) {
|
|
197
|
-
try {
|
|
198
|
-
return await plugin[fnName](...args);
|
|
199
|
-
}
|
|
200
|
-
catch (e) {
|
|
201
|
-
console.error(e);
|
|
202
|
-
return failValue;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.PluginHost = PluginHost;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CompletionContext, Diagnostic, FoldingRange, FormattingOptions, Position, TextEdit } from 'vscode-languageserver';
|
|
2
|
-
import type { ConfigManager } from '../../core/config';
|
|
3
|
-
import type { AstroDocument } from '../../core/documents';
|
|
4
|
-
import type { AppCompletionList, Plugin } from '../interfaces';
|
|
5
|
-
import type { LanguageServiceManager } from '../typescript/LanguageServiceManager';
|
|
6
|
-
export declare class AstroPlugin implements Plugin {
|
|
7
|
-
__name: string;
|
|
8
|
-
private configManager;
|
|
9
|
-
private readonly languageServiceManager;
|
|
10
|
-
private readonly completionProvider;
|
|
11
|
-
private readonly diagnosticsProvider;
|
|
12
|
-
constructor(configManager: ConfigManager, languageServiceManager: LanguageServiceManager);
|
|
13
|
-
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
14
|
-
getDiagnostics(document: AstroDocument): Promise<Diagnostic[]>;
|
|
15
|
-
formatDocument(document: AstroDocument, options: FormattingOptions): Promise<TextEdit[]>;
|
|
16
|
-
getFoldingRanges(document: AstroDocument): FoldingRange[];
|
|
17
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AstroPlugin = void 0;
|
|
4
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const importPackage_1 = require("../../importPackage");
|
|
6
|
-
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
7
|
-
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
8
|
-
class AstroPlugin {
|
|
9
|
-
constructor(configManager, languageServiceManager) {
|
|
10
|
-
this.__name = 'astro';
|
|
11
|
-
this.configManager = configManager;
|
|
12
|
-
this.languageServiceManager = languageServiceManager;
|
|
13
|
-
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
14
|
-
this.diagnosticsProvider = new DiagnosticsProvider_1.DiagnosticsProviderImpl(this.languageServiceManager);
|
|
15
|
-
}
|
|
16
|
-
async getCompletions(document, position, completionContext) {
|
|
17
|
-
const completions = this.completionProvider.getCompletions(document, position, completionContext);
|
|
18
|
-
return completions;
|
|
19
|
-
}
|
|
20
|
-
async getDiagnostics(document) {
|
|
21
|
-
return await this.diagnosticsProvider.getDiagnostics(document);
|
|
22
|
-
}
|
|
23
|
-
async formatDocument(document, options) {
|
|
24
|
-
const filePath = document.getFilePath();
|
|
25
|
-
if (!filePath) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const prettier = (0, importPackage_1.importPrettier)(filePath);
|
|
29
|
-
const prettierConfig = (await prettier.resolveConfig(filePath, { editorconfig: true, useCache: false })) ?? {};
|
|
30
|
-
const prettierVSConfig = await this.configManager.getPrettierVSConfig(document);
|
|
31
|
-
const editorFormatConfig = options !== undefined // We need to check for options existing here because some editors might not have it
|
|
32
|
-
? {
|
|
33
|
-
tabWidth: options.tabSize,
|
|
34
|
-
useTabs: !options.insertSpaces,
|
|
35
|
-
}
|
|
36
|
-
: {};
|
|
37
|
-
// Return a config with the following cascade:
|
|
38
|
-
// - Prettier config file should always win if it exists, if it doesn't:
|
|
39
|
-
// - Prettier config from the VS Code extension is used, if it doesn't exist:
|
|
40
|
-
// - Use the editor's basic configuration settings
|
|
41
|
-
const resultConfig = returnObjectIfHasKeys(prettierConfig) || returnObjectIfHasKeys(prettierVSConfig) || editorFormatConfig;
|
|
42
|
-
const fileInfo = await prettier.getFileInfo(filePath, { ignorePath: '.prettierignore' });
|
|
43
|
-
if (fileInfo.ignored) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const result = prettier.format(document.getText(), {
|
|
47
|
-
...resultConfig,
|
|
48
|
-
plugins: [...getAstroPrettierPlugin(), ...(resultConfig.plugins ?? [])],
|
|
49
|
-
parser: 'astro',
|
|
50
|
-
});
|
|
51
|
-
return document.getText() === result
|
|
52
|
-
? []
|
|
53
|
-
: [vscode_languageserver_1.TextEdit.replace(vscode_languageserver_1.Range.create(document.positionAt(0), document.positionAt(document.getTextLength())), result)];
|
|
54
|
-
function getAstroPrettierPlugin() {
|
|
55
|
-
const hasPluginLoadedAlready = prettier.getSupportInfo().languages.some((l) => l.name === 'astro');
|
|
56
|
-
return hasPluginLoadedAlready ? [] : [(0, importPackage_1.getPrettierPluginPath)(filePath)];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
getFoldingRanges(document) {
|
|
60
|
-
const foldingRanges = [];
|
|
61
|
-
const { frontmatter } = document.astroMeta;
|
|
62
|
-
// Currently editing frontmatter, don't fold
|
|
63
|
-
if (frontmatter.state !== 'closed')
|
|
64
|
-
return foldingRanges;
|
|
65
|
-
// The way folding ranges work is by folding anything between the starting position and the ending one, as such
|
|
66
|
-
// the start in this case should be after the frontmatter start (after the starting ---) until the last character
|
|
67
|
-
// of the last line of the frontmatter before its ending (before the closing ---)
|
|
68
|
-
// ---
|
|
69
|
-
// ^ -- start
|
|
70
|
-
// console.log("Astro")
|
|
71
|
-
// --- ^ -- end
|
|
72
|
-
const start = document.positionAt(frontmatter.startOffset + 3);
|
|
73
|
-
const end = document.positionAt(frontmatter.endOffset - 1);
|
|
74
|
-
return [
|
|
75
|
-
{
|
|
76
|
-
startLine: start.line,
|
|
77
|
-
startCharacter: start.character,
|
|
78
|
-
endLine: end.line,
|
|
79
|
-
endCharacter: end.character,
|
|
80
|
-
kind: vscode_languageserver_1.FoldingRangeKind.Imports,
|
|
81
|
-
},
|
|
82
|
-
];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.AstroPlugin = AstroPlugin;
|
|
86
|
-
function returnObjectIfHasKeys(obj) {
|
|
87
|
-
if (Object.keys(obj || {}).length > 0) {
|
|
88
|
-
return obj;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CompletionContext, Position } from 'vscode-languageserver';
|
|
2
|
-
import type { AstroDocument } from '../../../core/documents';
|
|
3
|
-
import type { AppCompletionList, CompletionsProvider } from '../../interfaces';
|
|
4
|
-
import type { LanguageServiceManager } from '../../typescript/LanguageServiceManager';
|
|
5
|
-
export declare class CompletionsProviderImpl implements CompletionsProvider {
|
|
6
|
-
private readonly languageServiceManager;
|
|
7
|
-
private readonly ts;
|
|
8
|
-
private lastCompletion;
|
|
9
|
-
directivesHTMLLang: import("vscode-html-languageservice").LanguageService;
|
|
10
|
-
constructor(languageServiceManager: LanguageServiceManager);
|
|
11
|
-
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
12
|
-
private getComponentScriptCompletion;
|
|
13
|
-
private getPropCompletionsAndFilePath;
|
|
14
|
-
private getImportedSymbol;
|
|
15
|
-
private getPropType;
|
|
16
|
-
private getCompletionItemForProperty;
|
|
17
|
-
}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompletionsProviderImpl = void 0;
|
|
4
|
-
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
5
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
6
|
-
const utils_1 = require("../../../core/documents/utils");
|
|
7
|
-
const astro_attributes_1 = require("../../html/features/astro-attributes");
|
|
8
|
-
const utils_2 = require("../../html/utils");
|
|
9
|
-
const utils_3 = require("../../typescript/utils");
|
|
10
|
-
class CompletionsProviderImpl {
|
|
11
|
-
constructor(languageServiceManager) {
|
|
12
|
-
this.lastCompletion = null;
|
|
13
|
-
this.directivesHTMLLang = (0, vscode_html_languageservice_1.getLanguageService)({
|
|
14
|
-
customDataProviders: [astro_attributes_1.astroDirectives],
|
|
15
|
-
useDefaultDataProvider: false,
|
|
16
|
-
});
|
|
17
|
-
this.languageServiceManager = languageServiceManager;
|
|
18
|
-
this.ts = languageServiceManager.docContext.ts;
|
|
19
|
-
}
|
|
20
|
-
async getCompletions(document, position, completionContext) {
|
|
21
|
-
let items = [];
|
|
22
|
-
const html = document.html;
|
|
23
|
-
const offset = document.offsetAt(position);
|
|
24
|
-
const node = html.findNodeAt(offset);
|
|
25
|
-
const insideExpression = (0, utils_1.isInsideExpression)(document.getText(), node.start, offset);
|
|
26
|
-
if (completionContext?.triggerCharacter === '-' && node.parent === undefined && !insideExpression) {
|
|
27
|
-
const frontmatter = this.getComponentScriptCompletion(document, position);
|
|
28
|
-
if (frontmatter)
|
|
29
|
-
items.push(frontmatter);
|
|
30
|
-
}
|
|
31
|
-
if ((0, utils_1.isInComponentStartTag)(html, offset) && !insideExpression) {
|
|
32
|
-
const { completions: props, componentFilePath } = await this.getPropCompletionsAndFilePath(document, position, completionContext);
|
|
33
|
-
if (props.length) {
|
|
34
|
-
items.push(...props);
|
|
35
|
-
}
|
|
36
|
-
const isAstro = componentFilePath?.endsWith('.astro');
|
|
37
|
-
if (!isAstro && node.tag !== 'Fragment') {
|
|
38
|
-
const directives = (0, utils_2.removeDataAttrCompletion)(this.directivesHTMLLang.doComplete(document, position, html).items);
|
|
39
|
-
items.push(...directives);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return vscode_languageserver_1.CompletionList.create(items, true);
|
|
43
|
-
}
|
|
44
|
-
getComponentScriptCompletion(document, position) {
|
|
45
|
-
const base = {
|
|
46
|
-
kind: vscode_languageserver_1.CompletionItemKind.Snippet,
|
|
47
|
-
label: '---',
|
|
48
|
-
sortText: '\0',
|
|
49
|
-
preselect: true,
|
|
50
|
-
detail: 'Create component script block',
|
|
51
|
-
insertTextFormat: vscode_languageserver_1.InsertTextFormat.Snippet,
|
|
52
|
-
commitCharacters: [],
|
|
53
|
-
};
|
|
54
|
-
const prefix = document.getLineUntilOffset(document.offsetAt(position));
|
|
55
|
-
if (document.astroMeta.frontmatter.state === null) {
|
|
56
|
-
return {
|
|
57
|
-
...base,
|
|
58
|
-
insertText: '---\n$0\n---',
|
|
59
|
-
textEdit: prefix.match(/^\s*\-+/)
|
|
60
|
-
? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---\n$0\n---')
|
|
61
|
-
: undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (document.astroMeta.frontmatter.state === 'open') {
|
|
65
|
-
let insertText = '---';
|
|
66
|
-
// If the current line is a full component script starter/ender, the user expects a full frontmatter
|
|
67
|
-
// completion and not just a completion for "---" on the same line (which result in, well, nothing)
|
|
68
|
-
if (prefix === '---') {
|
|
69
|
-
insertText = '---\n$0\n---';
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
...base,
|
|
73
|
-
insertText,
|
|
74
|
-
detail: insertText === '---' ? 'Close component script block' : 'Create component script block',
|
|
75
|
-
textEdit: prefix.match(/^\s*\-+/)
|
|
76
|
-
? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, insertText)
|
|
77
|
-
: undefined,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
async getPropCompletionsAndFilePath(document, position, completionContext) {
|
|
83
|
-
const offset = document.offsetAt(position);
|
|
84
|
-
const html = document.html;
|
|
85
|
-
const node = html.findNodeAt(offset);
|
|
86
|
-
if (!(0, utils_1.isPossibleComponent)(node)) {
|
|
87
|
-
return { completions: [], componentFilePath: null };
|
|
88
|
-
}
|
|
89
|
-
const inAttribute = node.start + node.tag.length < offset;
|
|
90
|
-
if (!inAttribute) {
|
|
91
|
-
return { completions: [], componentFilePath: null };
|
|
92
|
-
}
|
|
93
|
-
if (completionContext?.triggerCharacter === '/' || completionContext?.triggerCharacter === '>') {
|
|
94
|
-
return { completions: [], componentFilePath: null };
|
|
95
|
-
}
|
|
96
|
-
// If inside of attribute value, skip.
|
|
97
|
-
if (completionContext &&
|
|
98
|
-
completionContext.triggerKind === vscode_languageserver_1.CompletionTriggerKind.TriggerCharacter &&
|
|
99
|
-
completionContext.triggerCharacter === '"') {
|
|
100
|
-
return { completions: [], componentFilePath: null };
|
|
101
|
-
}
|
|
102
|
-
const componentName = node.tag;
|
|
103
|
-
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
104
|
-
// Get the source file
|
|
105
|
-
const tsFilePath = tsDoc.filePath;
|
|
106
|
-
const program = lang.getProgram();
|
|
107
|
-
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
108
|
-
const typeChecker = program?.getTypeChecker();
|
|
109
|
-
if (!sourceFile || !typeChecker) {
|
|
110
|
-
return { completions: [], componentFilePath: null };
|
|
111
|
-
}
|
|
112
|
-
// Get the import statement
|
|
113
|
-
const imp = this.getImportedSymbol(sourceFile, componentName);
|
|
114
|
-
const importType = imp && typeChecker.getTypeAtLocation(imp);
|
|
115
|
-
if (!importType) {
|
|
116
|
-
return { completions: [], componentFilePath: null };
|
|
117
|
-
}
|
|
118
|
-
const symbol = importType.getSymbol();
|
|
119
|
-
if (!symbol) {
|
|
120
|
-
return { completions: [], componentFilePath: null };
|
|
121
|
-
}
|
|
122
|
-
const symbolDeclaration = symbol.declarations;
|
|
123
|
-
if (!symbolDeclaration) {
|
|
124
|
-
return { completions: [], componentFilePath: null };
|
|
125
|
-
}
|
|
126
|
-
const filePath = symbolDeclaration[0].getSourceFile().fileName;
|
|
127
|
-
const componentSnapshot = await this.languageServiceManager.getSnapshot(filePath);
|
|
128
|
-
if (this.lastCompletion) {
|
|
129
|
-
if (this.lastCompletion.tag === componentName &&
|
|
130
|
-
this.lastCompletion.documentVersion == componentSnapshot.version) {
|
|
131
|
-
return { completions: this.lastCompletion.completions, componentFilePath: filePath };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Get the component's props type
|
|
135
|
-
const componentType = this.getPropType(symbolDeclaration, typeChecker);
|
|
136
|
-
if (!componentType) {
|
|
137
|
-
return { completions: [], componentFilePath: null };
|
|
138
|
-
}
|
|
139
|
-
let completionItems = [];
|
|
140
|
-
// Add completions for this component's props type properties
|
|
141
|
-
const properties = componentType.getProperties().filter((property) => property.name !== 'children') || [];
|
|
142
|
-
properties.forEach((property) => {
|
|
143
|
-
const type = typeChecker.getTypeOfSymbolAtLocation(property, imp);
|
|
144
|
-
let completionItem = this.getCompletionItemForProperty(property, typeChecker, type);
|
|
145
|
-
completionItems.push(completionItem);
|
|
146
|
-
});
|
|
147
|
-
this.lastCompletion = {
|
|
148
|
-
tag: componentName,
|
|
149
|
-
documentVersion: componentSnapshot.version,
|
|
150
|
-
completions: completionItems,
|
|
151
|
-
};
|
|
152
|
-
return { completions: completionItems, componentFilePath: filePath };
|
|
153
|
-
}
|
|
154
|
-
getImportedSymbol(sourceFile, identifier) {
|
|
155
|
-
for (let list of sourceFile.getChildren()) {
|
|
156
|
-
for (let node of list.getChildren()) {
|
|
157
|
-
if (this.ts.isImportDeclaration(node)) {
|
|
158
|
-
let clauses = node.importClause;
|
|
159
|
-
if (!clauses)
|
|
160
|
-
continue;
|
|
161
|
-
let namedImport = clauses.getChildAt(0);
|
|
162
|
-
if (this.ts.isNamedImports(namedImport)) {
|
|
163
|
-
for (let imp of namedImport.elements) {
|
|
164
|
-
// Iterate the named imports
|
|
165
|
-
if (imp.name.getText() === identifier) {
|
|
166
|
-
return imp;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else if (this.ts.isIdentifier(namedImport)) {
|
|
171
|
-
if (namedImport.getText() === identifier) {
|
|
172
|
-
return namedImport;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
getPropType(declarations, typeChecker) {
|
|
181
|
-
for (const decl of declarations) {
|
|
182
|
-
const fileName = (0, utils_3.toVirtualFilePath)(decl.getSourceFile().fileName);
|
|
183
|
-
if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx') || fileName.endsWith('.d.ts')) {
|
|
184
|
-
if (!this.ts.isFunctionDeclaration(decl) && !this.ts.isFunctionTypeNode(decl)) {
|
|
185
|
-
console.error(`We only support functions declarations at the moment`);
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
const fn = decl;
|
|
189
|
-
if (!fn.parameters.length)
|
|
190
|
-
continue;
|
|
191
|
-
const param1 = fn.parameters[0];
|
|
192
|
-
const propType = typeChecker.getTypeAtLocation(param1);
|
|
193
|
-
return propType;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
getCompletionItemForProperty(mem, typeChecker, type) {
|
|
199
|
-
const typeString = typeChecker.typeToString(type);
|
|
200
|
-
let insertText = mem.name;
|
|
201
|
-
switch (typeString) {
|
|
202
|
-
case 'string':
|
|
203
|
-
insertText = `${mem.name}="$1"`;
|
|
204
|
-
break;
|
|
205
|
-
case 'boolean':
|
|
206
|
-
insertText = mem.name;
|
|
207
|
-
break;
|
|
208
|
-
default:
|
|
209
|
-
insertText = `${mem.name}={$1}`;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
let item = {
|
|
213
|
-
label: mem.name,
|
|
214
|
-
detail: typeString,
|
|
215
|
-
insertText: insertText,
|
|
216
|
-
insertTextFormat: vscode_languageserver_1.InsertTextFormat.Snippet,
|
|
217
|
-
commitCharacters: [],
|
|
218
|
-
// Ensure that props shows up first as a completion, despite this plugin being ran after the HTML one
|
|
219
|
-
sortText: '\0',
|
|
220
|
-
};
|
|
221
|
-
if (mem.flags & this.ts.SymbolFlags.Optional) {
|
|
222
|
-
item.filterText = item.label;
|
|
223
|
-
item.label += '?';
|
|
224
|
-
// Put optional props at a lower priority
|
|
225
|
-
item.sortText = '_';
|
|
226
|
-
}
|
|
227
|
-
mem.getDocumentationComment(typeChecker);
|
|
228
|
-
let description = mem
|
|
229
|
-
.getDocumentationComment(typeChecker)
|
|
230
|
-
.map((val) => val.text)
|
|
231
|
-
.join('\n');
|
|
232
|
-
if (description) {
|
|
233
|
-
let docs = {
|
|
234
|
-
kind: vscode_languageserver_1.MarkupKind.Markdown,
|
|
235
|
-
value: description,
|
|
236
|
-
};
|
|
237
|
-
item.documentation = docs;
|
|
238
|
-
}
|
|
239
|
-
return item;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
exports.CompletionsProviderImpl = CompletionsProviderImpl;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Diagnostic } from 'vscode-languageserver-types';
|
|
2
|
-
import { AstroDocument } from '../../../core/documents';
|
|
3
|
-
import { DiagnosticsProvider } from '../../interfaces';
|
|
4
|
-
import { LanguageServiceManager } from '../../typescript/LanguageServiceManager';
|
|
5
|
-
export declare class DiagnosticsProviderImpl implements DiagnosticsProvider {
|
|
6
|
-
private languageServiceManager;
|
|
7
|
-
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
-
getDiagnostics(document: AstroDocument): Promise<Diagnostic[]>;
|
|
9
|
-
private compilerMessageToDiagnostic;
|
|
10
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiagnosticsProviderImpl = void 0;
|
|
4
|
-
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
5
|
-
class DiagnosticsProviderImpl {
|
|
6
|
-
constructor(languageServiceManager) {
|
|
7
|
-
this.languageServiceManager = languageServiceManager;
|
|
8
|
-
}
|
|
9
|
-
async getDiagnostics(document) {
|
|
10
|
-
const { tsDoc } = (await this.languageServiceManager.getLSAndTSDoc(document));
|
|
11
|
-
return tsDoc.compilerDiagnostics.map(this.compilerMessageToDiagnostic);
|
|
12
|
-
}
|
|
13
|
-
compilerMessageToDiagnostic(message) {
|
|
14
|
-
return {
|
|
15
|
-
message: message.text + '\n\n' + message.hint,
|
|
16
|
-
range: vscode_languageserver_types_1.Range.create(message.location.line - 1, message.location.column - 1, message.location.line, message.location.length),
|
|
17
|
-
code: message.code,
|
|
18
|
-
severity: message.severity,
|
|
19
|
-
source: 'astro',
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.DiagnosticsProviderImpl = DiagnosticsProviderImpl;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Stylesheet, TextDocument } from 'vscode-css-languageservice';
|
|
2
|
-
import type { Position } from 'vscode-languageserver';
|
|
3
|
-
import { AstroDocument, DocumentMapper, ReadableDocument, TagInformation } from '../../core/documents';
|
|
4
|
-
export interface CSSDocumentBase extends DocumentMapper, TextDocument {
|
|
5
|
-
languageId: string;
|
|
6
|
-
stylesheet: Stylesheet;
|
|
7
|
-
}
|
|
8
|
-
export declare class CSSDocument extends ReadableDocument implements DocumentMapper {
|
|
9
|
-
private parent;
|
|
10
|
-
private styleInfo;
|
|
11
|
-
readonly version: number;
|
|
12
|
-
stylesheet: Stylesheet;
|
|
13
|
-
languageId: string;
|
|
14
|
-
constructor(parent: AstroDocument, styleInfo: Pick<TagInformation, 'attributes' | 'start' | 'end'>);
|
|
15
|
-
/**
|
|
16
|
-
* Get the fragment position relative to the parent
|
|
17
|
-
* @param pos Position in fragment
|
|
18
|
-
*/
|
|
19
|
-
getOriginalPosition(pos: Position): Position;
|
|
20
|
-
/**
|
|
21
|
-
* Get the position relative to the start of the fragment
|
|
22
|
-
* @param pos Position in parent
|
|
23
|
-
*/
|
|
24
|
-
getGeneratedPosition(pos: Position): Position;
|
|
25
|
-
/**
|
|
26
|
-
* Returns true if the given parent position is inside of this fragment
|
|
27
|
-
* @param pos Position in parent
|
|
28
|
-
*/
|
|
29
|
-
isInGenerated(pos: Position): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Get the fragment text from the parent
|
|
32
|
-
*/
|
|
33
|
-
getText(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the length of the fragment as calculated from the start and end position
|
|
36
|
-
*/
|
|
37
|
-
getTextLength(): number;
|
|
38
|
-
/**
|
|
39
|
-
* Return the parent file path
|
|
40
|
-
*/
|
|
41
|
-
getFilePath(): string | null;
|
|
42
|
-
getURL(): string;
|
|
43
|
-
getAttributes(): Record<string, string>;
|
|
44
|
-
private get language();
|
|
45
|
-
}
|