@astrojs/language-server 0.14.0 → 0.16.1
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/CHANGELOG.md +39 -0
- package/dist/check.js +1 -2
- package/dist/core/config/ConfigManager.d.ts +20 -16
- package/dist/core/config/ConfigManager.js +112 -46
- package/dist/core/config/interfaces.d.ts +0 -52
- package/dist/core/documents/DocumentMapper.js +2 -4
- package/dist/core/documents/parseAstro.js +1 -1
- package/dist/core/documents/utils.d.ts +5 -0
- package/dist/core/documents/utils.js +18 -5
- package/dist/plugins/PluginHost.d.ts +3 -2
- package/dist/plugins/PluginHost.js +37 -10
- package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
- package/dist/plugins/astro/AstroPlugin.js +0 -82
- package/dist/plugins/astro/features/CompletionsProvider.js +30 -15
- package/dist/plugins/css/CSSPlugin.d.ts +5 -5
- package/dist/plugins/css/CSSPlugin.js +41 -20
- package/dist/plugins/html/HTMLPlugin.d.ts +4 -4
- package/dist/plugins/html/HTMLPlugin.js +20 -16
- package/dist/plugins/html/features/astro-attributes.js +44 -27
- package/dist/plugins/interfaces.d.ts +2 -2
- package/dist/plugins/typescript/LanguageServiceManager.js +1 -1
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +10 -7
- package/dist/plugins/typescript/TypeScriptPlugin.js +39 -112
- package/dist/plugins/typescript/astro-sys.js +3 -5
- package/dist/plugins/typescript/astro2tsx.d.ts +1 -1
- package/dist/plugins/typescript/astro2tsx.js +7 -7
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +16 -0
- package/dist/plugins/typescript/features/CodeActionsProvider.js +147 -0
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +26 -7
- package/dist/plugins/typescript/features/CompletionsProvider.js +260 -56
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/DefinitionsProvider.js +36 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +2 -3
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +5 -6
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +64 -0
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +2 -2
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +2 -2
- package/dist/plugins/typescript/features/utils.d.ts +4 -0
- package/dist/plugins/typescript/features/utils.js +25 -3
- package/dist/plugins/typescript/language-service.js +5 -6
- package/dist/plugins/typescript/module-loader.js +1 -1
- package/dist/plugins/typescript/previewer.js +1 -1
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +1 -1
- package/dist/plugins/typescript/snapshots/utils.js +27 -9
- package/dist/plugins/typescript/utils.d.ts +4 -0
- package/dist/plugins/typescript/utils.js +29 -1
- package/dist/server.js +43 -14
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +39 -3
- package/package.json +2 -2
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.AstroPlugin = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
9
|
-
const documents_1 = require("../../core/documents");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
5
|
const LanguageServiceManager_1 = require("../typescript/LanguageServiceManager");
|
|
12
|
-
const utils_2 = require("../typescript/utils");
|
|
13
6
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
14
7
|
class AstroPlugin {
|
|
15
8
|
constructor(docManager, configManager, workspaceUris) {
|
|
@@ -40,80 +33,5 @@ class AstroPlugin {
|
|
|
40
33
|
},
|
|
41
34
|
];
|
|
42
35
|
}
|
|
43
|
-
async getDefinitions(document, position) {
|
|
44
|
-
if (this.isInsideFrontmatter(document, position)) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
const offset = document.offsetAt(position);
|
|
48
|
-
const html = document.html;
|
|
49
|
-
const node = html.findNodeAt(offset);
|
|
50
|
-
if (!this.isComponentTag(node)) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
const [componentName] = node.tag.split(':');
|
|
54
|
-
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
55
|
-
const defs = this.getDefinitionsForComponentName(document, lang, componentName);
|
|
56
|
-
if (!defs || !defs.length) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
const startRange = vscode_languageserver_1.Range.create(vscode_languageserver_1.Position.create(0, 0), vscode_languageserver_1.Position.create(0, 0));
|
|
60
|
-
const links = defs.map((def) => {
|
|
61
|
-
const defFilePath = (0, utils_2.ensureRealFilePath)(def.fileName);
|
|
62
|
-
return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(defFilePath), startRange, startRange);
|
|
63
|
-
});
|
|
64
|
-
return links;
|
|
65
|
-
}
|
|
66
|
-
isInsideFrontmatter(document, position) {
|
|
67
|
-
return (0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
|
|
68
|
-
}
|
|
69
|
-
isComponentTag(node) {
|
|
70
|
-
if (!node.tag) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
const firstChar = node.tag[0];
|
|
74
|
-
return /[A-Z]/.test(firstChar);
|
|
75
|
-
}
|
|
76
|
-
getDefinitionsForComponentName(document, lang, componentName) {
|
|
77
|
-
const filePath = (0, utils_1.urlToPath)(document.uri);
|
|
78
|
-
const tsFilePath = (0, utils_2.toVirtualAstroFilePath)(filePath);
|
|
79
|
-
const program = lang.getProgram();
|
|
80
|
-
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
81
|
-
if (!sourceFile) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
const specifier = this.getImportSpecifierForIdentifier(sourceFile, componentName);
|
|
85
|
-
if (!specifier) {
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
const defs = lang.getDefinitionAtPosition(tsFilePath, specifier.getStart());
|
|
89
|
-
if (!defs) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
return defs;
|
|
93
|
-
}
|
|
94
|
-
getImportSpecifierForIdentifier(sourceFile, identifier) {
|
|
95
|
-
let importSpecifier = undefined;
|
|
96
|
-
typescript_1.default.forEachChild(sourceFile, (tsNode) => {
|
|
97
|
-
if (typescript_1.default.isImportDeclaration(tsNode)) {
|
|
98
|
-
if (tsNode.importClause) {
|
|
99
|
-
const { name, namedBindings } = tsNode.importClause;
|
|
100
|
-
if (name && name.getText() === identifier) {
|
|
101
|
-
importSpecifier = tsNode.moduleSpecifier;
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
else if (namedBindings && namedBindings.kind === typescript_1.default.SyntaxKind.NamedImports) {
|
|
105
|
-
const elements = namedBindings.elements;
|
|
106
|
-
for (let elem of elements) {
|
|
107
|
-
if (elem.name.getText() === identifier) {
|
|
108
|
-
importSpecifier = tsNode.moduleSpecifier;
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
return importSpecifier;
|
|
117
|
-
}
|
|
118
36
|
}
|
|
119
37
|
exports.AstroPlugin = AstroPlugin;
|
|
@@ -26,19 +26,19 @@ class CompletionsProviderImpl {
|
|
|
26
26
|
if (!doc)
|
|
27
27
|
return null;
|
|
28
28
|
let items = [];
|
|
29
|
-
if (
|
|
29
|
+
if (completionContext?.triggerCharacter === '-') {
|
|
30
30
|
const frontmatter = this.getComponentScriptCompletion(doc, position, completionContext);
|
|
31
31
|
if (frontmatter)
|
|
32
32
|
items.push(frontmatter);
|
|
33
33
|
}
|
|
34
34
|
const html = document.html;
|
|
35
35
|
const offset = document.offsetAt(position);
|
|
36
|
-
|
|
36
|
+
const node = html.findNodeAt(offset);
|
|
37
|
+
if ((0, utils_1.isInComponentStartTag)(html, offset) && !(0, utils_1.isInsideExpression)(document.getText(), node.start, offset)) {
|
|
37
38
|
const props = await this.getPropCompletions(document, position, completionContext);
|
|
38
39
|
if (props.length) {
|
|
39
40
|
items.push(...props);
|
|
40
41
|
}
|
|
41
|
-
const node = html.findNodeAt(offset);
|
|
42
42
|
const isAstro = await this.isAstroComponent(document, node);
|
|
43
43
|
if (!isAstro) {
|
|
44
44
|
const directives = (0, utils_4.removeDataAttrCompletion)(this.directivesHTMLLang.doComplete(document, position, html).items);
|
|
@@ -89,7 +89,7 @@ class CompletionsProviderImpl {
|
|
|
89
89
|
if (!inAttribute) {
|
|
90
90
|
return [];
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
92
|
+
if (completionContext?.triggerCharacter === '/' || completionContext?.triggerCharacter === '>') {
|
|
93
93
|
return [];
|
|
94
94
|
}
|
|
95
95
|
// If inside of attribute value, skip.
|
|
@@ -103,8 +103,8 @@ class CompletionsProviderImpl {
|
|
|
103
103
|
// Get the source file
|
|
104
104
|
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
105
105
|
const program = lang.getProgram();
|
|
106
|
-
const sourceFile = program
|
|
107
|
-
const typeChecker = program
|
|
106
|
+
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
107
|
+
const typeChecker = program?.getTypeChecker();
|
|
108
108
|
if (!sourceFile || !typeChecker) {
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
@@ -123,7 +123,8 @@ class CompletionsProviderImpl {
|
|
|
123
123
|
// Add completions for this component's props type properties
|
|
124
124
|
const properties = componentType.getProperties().filter((property) => property.name !== 'children') || [];
|
|
125
125
|
properties.forEach((property) => {
|
|
126
|
-
|
|
126
|
+
const type = typeChecker.getTypeOfSymbolAtLocation(property, imp);
|
|
127
|
+
let completionItem = this.getCompletionItemForProperty(property, typeChecker, type);
|
|
127
128
|
completionItems.push(completionItem);
|
|
128
129
|
});
|
|
129
130
|
// Ensure that props shows up first as a completion, despite this plugin being ran after the HTML one
|
|
@@ -159,11 +160,11 @@ class CompletionsProviderImpl {
|
|
|
159
160
|
return null;
|
|
160
161
|
}
|
|
161
162
|
getPropType(type, typeChecker) {
|
|
162
|
-
const sym = type
|
|
163
|
+
const sym = type?.getSymbol();
|
|
163
164
|
if (!sym) {
|
|
164
165
|
return null;
|
|
165
166
|
}
|
|
166
|
-
for (const decl of
|
|
167
|
+
for (const decl of sym?.getDeclarations() || []) {
|
|
167
168
|
const fileName = (0, utils_3.toVirtualFilePath)(decl.getSourceFile().fileName);
|
|
168
169
|
if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx')) {
|
|
169
170
|
if (!typescript_1.default.isFunctionDeclaration(decl)) {
|
|
@@ -180,10 +181,25 @@ class CompletionsProviderImpl {
|
|
|
180
181
|
}
|
|
181
182
|
return null;
|
|
182
183
|
}
|
|
183
|
-
getCompletionItemForProperty(mem, typeChecker) {
|
|
184
|
+
getCompletionItemForProperty(mem, typeChecker, type) {
|
|
185
|
+
const typeString = typeChecker.typeToString(type);
|
|
186
|
+
let insertText = mem.name;
|
|
187
|
+
switch (typeString) {
|
|
188
|
+
case 'string':
|
|
189
|
+
insertText = `${mem.name}="$1"`;
|
|
190
|
+
break;
|
|
191
|
+
case 'boolean':
|
|
192
|
+
insertText = mem.name;
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
insertText = `${mem.name}={$1}`;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
184
198
|
let item = {
|
|
185
199
|
label: mem.name,
|
|
186
|
-
|
|
200
|
+
detail: typeString,
|
|
201
|
+
insertText: insertText,
|
|
202
|
+
insertTextFormat: vscode_languageserver_1.InsertTextFormat.Snippet,
|
|
187
203
|
commitCharacters: [],
|
|
188
204
|
};
|
|
189
205
|
mem.getDocumentationComment(typeChecker);
|
|
@@ -201,13 +217,12 @@ class CompletionsProviderImpl {
|
|
|
201
217
|
return item;
|
|
202
218
|
}
|
|
203
219
|
async isAstroComponent(document, node) {
|
|
204
|
-
var _a;
|
|
205
220
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
206
221
|
// Get the source file
|
|
207
222
|
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
208
223
|
const program = lang.getProgram();
|
|
209
|
-
const sourceFile = program
|
|
210
|
-
const typeChecker = program
|
|
224
|
+
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
225
|
+
const typeChecker = program?.getTypeChecker();
|
|
211
226
|
if (!sourceFile || !typeChecker) {
|
|
212
227
|
return false;
|
|
213
228
|
}
|
|
@@ -217,7 +232,7 @@ class CompletionsProviderImpl {
|
|
|
217
232
|
if (!importType) {
|
|
218
233
|
return false;
|
|
219
234
|
}
|
|
220
|
-
const symbolDeclaration =
|
|
235
|
+
const symbolDeclaration = importType.getSymbol()?.declarations;
|
|
221
236
|
if (symbolDeclaration) {
|
|
222
237
|
const fileName = symbolDeclaration[0].getSourceFile().fileName;
|
|
223
238
|
return fileName.endsWith('.astro');
|
|
@@ -8,14 +8,14 @@ export declare class CSSPlugin implements Plugin {
|
|
|
8
8
|
private cssDocuments;
|
|
9
9
|
private triggerCharacters;
|
|
10
10
|
constructor(configManager: ConfigManager);
|
|
11
|
-
doHover(document: AstroDocument, position: Position): Hover | null
|
|
11
|
+
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
12
12
|
private doHoverInternal;
|
|
13
|
-
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): CompletionList | null
|
|
13
|
+
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<CompletionList | null>;
|
|
14
14
|
private getCompletionsInternal;
|
|
15
|
-
getDocumentColors(document: AstroDocument): ColorInformation[]
|
|
16
|
-
getColorPresentations(document: AstroDocument, range: Range, color: Color): ColorPresentation[]
|
|
15
|
+
getDocumentColors(document: AstroDocument): Promise<ColorInformation[]>;
|
|
16
|
+
getColorPresentations(document: AstroDocument, range: Range, color: Color): Promise<ColorPresentation[]>;
|
|
17
17
|
getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
|
|
18
|
-
getDocumentSymbols(document: AstroDocument): SymbolInformation[]
|
|
18
|
+
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
|
19
19
|
private inStyleAttributeWithoutInterpolation;
|
|
20
20
|
/**
|
|
21
21
|
* Get the associated CSS Document for a style tag
|
|
@@ -17,8 +17,8 @@ class CSSPlugin {
|
|
|
17
17
|
this.triggerCharacters = new Set(['.', ':', '-', '/']);
|
|
18
18
|
this.configManager = configManager;
|
|
19
19
|
}
|
|
20
|
-
doHover(document, position) {
|
|
21
|
-
if (!this.featureEnabled('hover')) {
|
|
20
|
+
async doHover(document, position) {
|
|
21
|
+
if (!(await this.featureEnabled(document, 'hover'))) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
|
@@ -53,15 +53,15 @@ class CSSPlugin {
|
|
|
53
53
|
const hoverInfo = (0, language_service_1.getLanguageService)(extractLanguage(cssDocument)).doHover(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
|
54
54
|
return hoverInfo ? (0, documents_1.mapHoverToParent)(cssDocument, hoverInfo) : hoverInfo;
|
|
55
55
|
}
|
|
56
|
-
getCompletions(document, position, completionContext) {
|
|
57
|
-
if (!this.featureEnabled('completions')) {
|
|
56
|
+
async getCompletions(document, position, completionContext) {
|
|
57
|
+
if (!(await this.featureEnabled(document, 'completions'))) {
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
|
-
const triggerCharacter = completionContext
|
|
64
|
-
const triggerKind = completionContext
|
|
63
|
+
const triggerCharacter = completionContext?.triggerCharacter;
|
|
64
|
+
const triggerKind = completionContext?.triggerKind;
|
|
65
65
|
const isCustomTriggerCharacter = triggerKind === vscode_languageserver_1.CompletionTriggerKind.TriggerCharacter;
|
|
66
66
|
if (isCustomTriggerCharacter && triggerCharacter && !this.triggerCharacters.has(triggerCharacter)) {
|
|
67
67
|
return null;
|
|
@@ -77,7 +77,7 @@ class CSSPlugin {
|
|
|
77
77
|
}
|
|
78
78
|
if (this.inStyleAttributeWithoutInterpolation(attributeContext, document.getText())) {
|
|
79
79
|
const [start, end] = attributeContext.valueRange;
|
|
80
|
-
return this.getCompletionsInternal(document, position, new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end));
|
|
80
|
+
return await this.getCompletionsInternal(document, position, new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end));
|
|
81
81
|
}
|
|
82
82
|
// If we're not in a style attribute, instead give completions for ids and classes used in the current document
|
|
83
83
|
else if ((attributeContext.name == 'id' || attributeContext.name == 'class') && attributeContext.inValue) {
|
|
@@ -87,27 +87,47 @@ class CSSPlugin {
|
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
89
|
const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
|
|
90
|
-
return this.getCompletionsInternal(document, position, cssDocument);
|
|
90
|
+
return await this.getCompletionsInternal(document, position, cssDocument);
|
|
91
91
|
}
|
|
92
|
-
getCompletionsInternal(document, position, cssDocument) {
|
|
92
|
+
async getCompletionsInternal(document, position, cssDocument) {
|
|
93
|
+
const emmetConfig = await this.configManager.getEmmetConfig(document);
|
|
93
94
|
if (isSASS(cssDocument)) {
|
|
94
95
|
// The CSS language service does not support SASS (not to be confused with SCSS)
|
|
95
96
|
// however we can at least still at least provide Emmet completions in SASS blocks
|
|
96
|
-
return (0, emmet_helper_1.doComplete)(document, position, 'sass',
|
|
97
|
+
return (0, emmet_helper_1.doComplete)(document, position, 'sass', emmetConfig) || null;
|
|
97
98
|
}
|
|
98
99
|
const cssLang = extractLanguage(cssDocument);
|
|
99
100
|
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
|
100
|
-
|
|
101
|
-
isIncomplete:
|
|
101
|
+
let emmetResults = {
|
|
102
|
+
isIncomplete: false,
|
|
102
103
|
items: [],
|
|
103
104
|
};
|
|
105
|
+
const extensionConfig = await this.configManager.getConfig('astro', document.uri);
|
|
106
|
+
if (extensionConfig.css.completions.emmet) {
|
|
107
|
+
langService.setCompletionParticipants([
|
|
108
|
+
{
|
|
109
|
+
onCssProperty: (context) => {
|
|
110
|
+
if (context?.propertyName) {
|
|
111
|
+
emmetResults =
|
|
112
|
+
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
onCssPropertyValue: (context) => {
|
|
116
|
+
if (context?.propertyValue) {
|
|
117
|
+
emmetResults =
|
|
118
|
+
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
104
124
|
const results = langService.doComplete(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
|
105
125
|
return vscode_languageserver_1.CompletionList.create([...(results ? results.items : []), ...emmetResults.items].map((completionItem) => (0, documents_1.mapCompletionItemToOriginal)(cssDocument, completionItem)),
|
|
106
126
|
// Emmet completions change on every keystroke, so they are never complete
|
|
107
127
|
emmetResults.items.length > 0);
|
|
108
128
|
}
|
|
109
|
-
getDocumentColors(document) {
|
|
110
|
-
if (!this.featureEnabled('documentColors')) {
|
|
129
|
+
async getDocumentColors(document) {
|
|
130
|
+
if (!(await this.featureEnabled(document, 'documentColors'))) {
|
|
111
131
|
return [];
|
|
112
132
|
}
|
|
113
133
|
const allColorInfo = this.getCSSDocumentsForDocument(document).map((cssDoc) => {
|
|
@@ -122,8 +142,8 @@ class CSSPlugin {
|
|
|
122
142
|
});
|
|
123
143
|
return (0, lodash_1.flatten)(allColorInfo);
|
|
124
144
|
}
|
|
125
|
-
getColorPresentations(document, range, color) {
|
|
126
|
-
if (!this.featureEnabled('
|
|
145
|
+
async getColorPresentations(document, range, color) {
|
|
146
|
+
if (!(await this.featureEnabled(document, 'documentColors'))) {
|
|
127
147
|
return [];
|
|
128
148
|
}
|
|
129
149
|
const allColorPres = this.getCSSDocumentsForDocument(document).map((cssDoc) => {
|
|
@@ -147,8 +167,8 @@ class CSSPlugin {
|
|
|
147
167
|
});
|
|
148
168
|
return (0, lodash_1.flatten)(allFoldingRanges);
|
|
149
169
|
}
|
|
150
|
-
getDocumentSymbols(document) {
|
|
151
|
-
if (!this.featureEnabled('documentSymbols')) {
|
|
170
|
+
async getDocumentSymbols(document) {
|
|
171
|
+
if (!(await this.featureEnabled(document, 'documentSymbols'))) {
|
|
152
172
|
return [];
|
|
153
173
|
}
|
|
154
174
|
const allDocumentSymbols = this.getCSSDocumentsForDocument(document).map((cssDoc) => {
|
|
@@ -194,8 +214,9 @@ class CSSPlugin {
|
|
|
194
214
|
return (0, documents_1.isInTag)(position, styleTag);
|
|
195
215
|
});
|
|
196
216
|
}
|
|
197
|
-
featureEnabled(feature) {
|
|
198
|
-
return this.configManager.
|
|
217
|
+
async featureEnabled(document, feature) {
|
|
218
|
+
return ((await this.configManager.isEnabled(document, 'css')) &&
|
|
219
|
+
(await this.configManager.isEnabled(document, 'css', feature)));
|
|
199
220
|
}
|
|
200
221
|
}
|
|
201
222
|
exports.CSSPlugin = CSSPlugin;
|
|
@@ -10,14 +10,14 @@ export declare class HTMLPlugin implements Plugin {
|
|
|
10
10
|
private styleScriptTemplate;
|
|
11
11
|
private configManager;
|
|
12
12
|
constructor(configManager: ConfigManager);
|
|
13
|
-
doHover(document: AstroDocument, position: Position): Hover | null
|
|
13
|
+
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
14
14
|
/**
|
|
15
15
|
* Get HTML completions
|
|
16
16
|
*/
|
|
17
|
-
getCompletions(document: AstroDocument, position: Position): CompletionList | null
|
|
17
|
+
getCompletions(document: AstroDocument, position: Position): Promise<CompletionList | null>;
|
|
18
18
|
getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
|
|
19
|
-
doTagComplete(document: AstroDocument, position: Position): string | null
|
|
20
|
-
getDocumentSymbols(document: AstroDocument): SymbolInformation[]
|
|
19
|
+
doTagComplete(document: AstroDocument, position: Position): Promise<string | null>;
|
|
20
|
+
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
|
21
21
|
/**
|
|
22
22
|
* Get lang completions for style tags (ex: `<style lang="scss">`)
|
|
23
23
|
*/
|
|
@@ -25,8 +25,8 @@ class HTMLPlugin {
|
|
|
25
25
|
this.styleScriptTemplate = new Set(['style']);
|
|
26
26
|
this.configManager = configManager;
|
|
27
27
|
}
|
|
28
|
-
doHover(document, position) {
|
|
29
|
-
if (!this.featureEnabled('hover')) {
|
|
28
|
+
async doHover(document, position) {
|
|
29
|
+
if (!(await this.featureEnabled(document, 'hover'))) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
const html = document.html;
|
|
@@ -46,8 +46,8 @@ class HTMLPlugin {
|
|
|
46
46
|
/**
|
|
47
47
|
* Get HTML completions
|
|
48
48
|
*/
|
|
49
|
-
getCompletions(document, position) {
|
|
50
|
-
if (!this.featureEnabled('completions')) {
|
|
49
|
+
async getCompletions(document, position) {
|
|
50
|
+
if (!(await this.featureEnabled(document, 'completions'))) {
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
const html = document.html;
|
|
@@ -62,12 +62,15 @@ class HTMLPlugin {
|
|
|
62
62
|
isIncomplete: true,
|
|
63
63
|
items: [],
|
|
64
64
|
};
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const emmetConfig = await this.configManager.getEmmetConfig(document);
|
|
66
|
+
const extensionConfig = await this.configManager.getConfig('astro', document.uri);
|
|
67
|
+
if (extensionConfig.html.completions.emmet) {
|
|
68
|
+
this.lang.setCompletionParticipants([
|
|
69
|
+
{
|
|
70
|
+
onHtmlContent: () => (emmetResults = (0, emmet_helper_1.doComplete)(document, position, 'html', emmetConfig) || emmetResults),
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
71
74
|
// If we're in a component starting tag, we do not want HTML language completions
|
|
72
75
|
// as HTML attributes are not valid for components
|
|
73
76
|
const results = (0, utils_1.isInComponentStartTag)(html, document.offsetAt(position))
|
|
@@ -84,8 +87,8 @@ class HTMLPlugin {
|
|
|
84
87
|
}
|
|
85
88
|
return this.lang.getFoldingRanges(document);
|
|
86
89
|
}
|
|
87
|
-
doTagComplete(document, position) {
|
|
88
|
-
if (!this.featureEnabled('tagComplete')) {
|
|
90
|
+
async doTagComplete(document, position) {
|
|
91
|
+
if (!(await this.featureEnabled(document, 'tagComplete'))) {
|
|
89
92
|
return null;
|
|
90
93
|
}
|
|
91
94
|
const html = document.html;
|
|
@@ -97,8 +100,8 @@ class HTMLPlugin {
|
|
|
97
100
|
}
|
|
98
101
|
return this.lang.doTagComplete(document, position, html);
|
|
99
102
|
}
|
|
100
|
-
getDocumentSymbols(document) {
|
|
101
|
-
if (!this.featureEnabled('documentSymbols')) {
|
|
103
|
+
async getDocumentSymbols(document) {
|
|
104
|
+
if (!(await this.featureEnabled(document, 'documentSymbols'))) {
|
|
102
105
|
return [];
|
|
103
106
|
}
|
|
104
107
|
const html = document.html;
|
|
@@ -134,8 +137,9 @@ class HTMLPlugin {
|
|
|
134
137
|
}));
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
|
-
featureEnabled(feature) {
|
|
138
|
-
return this.configManager.
|
|
140
|
+
async featureEnabled(document, feature) {
|
|
141
|
+
return ((await this.configManager.isEnabled(document, 'html')) &&
|
|
142
|
+
(await this.configManager.isEnabled(document, 'html', feature)));
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
exports.HTMLPlugin = HTMLPlugin;
|
|
@@ -8,6 +8,12 @@ exports.classListAttribute = (0, vscode_html_languageservice_1.newHTMLDataProvid
|
|
|
8
8
|
{
|
|
9
9
|
name: 'class:list',
|
|
10
10
|
description: 'Utility to provide a list of class',
|
|
11
|
+
references: [
|
|
12
|
+
{
|
|
13
|
+
name: 'Astro reference',
|
|
14
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#classlist',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
11
17
|
},
|
|
12
18
|
],
|
|
13
19
|
});
|
|
@@ -19,8 +25,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
19
25
|
description: 'Inject unescaped HTML into this tag',
|
|
20
26
|
references: [
|
|
21
27
|
{
|
|
22
|
-
name: 'Astro
|
|
23
|
-
url: 'https://docs.astro.build/en/
|
|
28
|
+
name: 'Astro reference',
|
|
29
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#sethtml',
|
|
24
30
|
},
|
|
25
31
|
],
|
|
26
32
|
},
|
|
@@ -29,8 +35,19 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
29
35
|
description: 'Inject escaped text into this tag',
|
|
30
36
|
references: [
|
|
31
37
|
{
|
|
32
|
-
name: 'Astro
|
|
33
|
-
url: 'https://docs.astro.build/en/
|
|
38
|
+
name: 'Astro reference',
|
|
39
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#settext',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'is:raw',
|
|
45
|
+
description: 'Instructs the Astro compiler to treat any children of this element as text',
|
|
46
|
+
valueSet: 'v',
|
|
47
|
+
references: [
|
|
48
|
+
{
|
|
49
|
+
name: 'Astro reference',
|
|
50
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#israw',
|
|
34
51
|
},
|
|
35
52
|
],
|
|
36
53
|
},
|
|
@@ -50,8 +67,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
50
67
|
description: 'Passes serializable server-side variables into a client-side script element',
|
|
51
68
|
references: [
|
|
52
69
|
{
|
|
53
|
-
name: 'Astro
|
|
54
|
-
url: 'https://docs.astro.build/en/
|
|
70
|
+
name: 'Astro reference',
|
|
71
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
|
55
72
|
},
|
|
56
73
|
],
|
|
57
74
|
},
|
|
@@ -61,7 +78,7 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
61
78
|
valueSet: 'v',
|
|
62
79
|
references: [
|
|
63
80
|
{
|
|
64
|
-
name: 'Astro
|
|
81
|
+
name: 'Astro reference',
|
|
65
82
|
url: 'https://docs.astro.build/en/core-concepts/astro-components/#using-hoisted-scripts',
|
|
66
83
|
},
|
|
67
84
|
],
|
|
@@ -72,8 +89,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
72
89
|
valueSet: 'v',
|
|
73
90
|
references: [
|
|
74
91
|
{
|
|
75
|
-
name: 'Astro
|
|
76
|
-
url: 'https://docs.astro.build/en/
|
|
92
|
+
name: 'Astro reference',
|
|
93
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
|
77
94
|
},
|
|
78
95
|
],
|
|
79
96
|
},
|
|
@@ -87,8 +104,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
87
104
|
description: 'Passes serializable server-side variables into a client-side style element',
|
|
88
105
|
references: [
|
|
89
106
|
{
|
|
90
|
-
name: 'Astro
|
|
91
|
-
url: 'https://docs.astro.build/en/
|
|
107
|
+
name: 'Astro reference',
|
|
108
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
|
92
109
|
},
|
|
93
110
|
],
|
|
94
111
|
},
|
|
@@ -98,8 +115,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
98
115
|
valueSet: 'v',
|
|
99
116
|
references: [
|
|
100
117
|
{
|
|
101
|
-
name: 'Astro
|
|
102
|
-
url: 'https://docs.astro.build/en/
|
|
118
|
+
name: 'Astro reference',
|
|
119
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
|
103
120
|
},
|
|
104
121
|
],
|
|
105
122
|
},
|
|
@@ -109,8 +126,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
109
126
|
valueSet: 'v',
|
|
110
127
|
references: [
|
|
111
128
|
{
|
|
112
|
-
name: 'Astro
|
|
113
|
-
url: 'https://docs.astro.build/en/
|
|
129
|
+
name: 'Astro reference',
|
|
130
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
|
114
131
|
},
|
|
115
132
|
],
|
|
116
133
|
},
|
|
@@ -120,8 +137,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
120
137
|
valueSet: 'v',
|
|
121
138
|
references: [
|
|
122
139
|
{
|
|
123
|
-
name: 'Astro
|
|
124
|
-
url: 'https://docs.astro.build/en/
|
|
140
|
+
name: 'Astro reference',
|
|
141
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
|
125
142
|
},
|
|
126
143
|
],
|
|
127
144
|
},
|
|
@@ -138,8 +155,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
138
155
|
valueSet: 'v',
|
|
139
156
|
references: [
|
|
140
157
|
{
|
|
141
|
-
name: 'Astro
|
|
142
|
-
url: 'https://docs.astro.build/en/
|
|
158
|
+
name: 'Astro reference',
|
|
159
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientload',
|
|
143
160
|
},
|
|
144
161
|
],
|
|
145
162
|
},
|
|
@@ -149,8 +166,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
149
166
|
valueSet: 'v',
|
|
150
167
|
references: [
|
|
151
168
|
{
|
|
152
|
-
name: 'Astro
|
|
153
|
-
url: 'https://docs.astro.build/en/
|
|
169
|
+
name: 'Astro reference',
|
|
170
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientidle',
|
|
154
171
|
},
|
|
155
172
|
],
|
|
156
173
|
},
|
|
@@ -160,8 +177,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
160
177
|
valueSet: 'v',
|
|
161
178
|
references: [
|
|
162
179
|
{
|
|
163
|
-
name: 'Astro
|
|
164
|
-
url: 'https://docs.astro.build/en/
|
|
180
|
+
name: 'Astro reference',
|
|
181
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientvisible',
|
|
165
182
|
},
|
|
166
183
|
],
|
|
167
184
|
},
|
|
@@ -170,8 +187,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
170
187
|
description: 'Start importing the component JS as soon as the browser matches the given media query (uses matchMedia). Hydrate the component when import completes. Useful for sidebar toggles, or other elements that should only display on mobile or desktop devices.',
|
|
171
188
|
references: [
|
|
172
189
|
{
|
|
173
|
-
name: 'Astro
|
|
174
|
-
url: 'https://docs.astro.build/en/
|
|
190
|
+
name: 'Astro reference',
|
|
191
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientmedia',
|
|
175
192
|
},
|
|
176
193
|
],
|
|
177
194
|
},
|
|
@@ -181,8 +198,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
181
198
|
valueSet: 'v',
|
|
182
199
|
references: [
|
|
183
200
|
{
|
|
184
|
-
name: 'Astro
|
|
185
|
-
url: 'https://docs.astro.build/en/
|
|
201
|
+
name: 'Astro reference',
|
|
202
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientonly',
|
|
186
203
|
},
|
|
187
204
|
],
|
|
188
205
|
},
|
|
@@ -13,7 +13,7 @@ export interface DiagnosticsProvider {
|
|
|
13
13
|
export interface HoverProvider {
|
|
14
14
|
doHover(document: TextDocument, position: Position): Resolvable<Hover | null>;
|
|
15
15
|
}
|
|
16
|
-
export interface
|
|
16
|
+
export interface FoldingRangesProvider {
|
|
17
17
|
getFoldingRanges(document: TextDocument): Resolvable<FoldingRange[] | null>;
|
|
18
18
|
}
|
|
19
19
|
export interface CompletionsProvider<T extends TextDocumentIdentifier = any> {
|
|
@@ -81,7 +81,7 @@ export interface OnWatchFileChangesProvider {
|
|
|
81
81
|
export interface UpdateNonAstroFile {
|
|
82
82
|
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
|
|
83
83
|
}
|
|
84
|
-
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & DefinitionsProvider & FormattingProvider &
|
|
84
|
+
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & DefinitionsProvider & FormattingProvider & FoldingRangesProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & UpdateNonAstroFile;
|
|
85
85
|
export declare type LSProvider = ProviderBase;
|
|
86
86
|
export declare type Plugin = Partial<ProviderBase> & {
|
|
87
87
|
__name: string;
|