@astrojs/language-server 0.15.0 → 0.16.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/CHANGELOG.md +15 -0
- package/dist/check.js +1 -2
- package/dist/core/documents/DocumentMapper.js +2 -4
- package/dist/core/documents/parseAstro.js +1 -1
- package/dist/core/documents/utils.js +3 -4
- package/dist/plugins/PluginHost.d.ts +2 -1
- package/dist/plugins/PluginHost.js +8 -6
- package/dist/plugins/astro/AstroPlugin.js +1 -1
- package/dist/plugins/astro/features/CompletionsProvider.js +9 -10
- package/dist/plugins/css/CSSPlugin.js +20 -4
- package/dist/plugins/html/features/astro-attributes.js +43 -27
- package/dist/plugins/typescript/LanguageServiceManager.js +1 -1
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +3 -1
- package/dist/plugins/typescript/TypeScriptPlugin.js +9 -1
- package/dist/plugins/typescript/astro-sys.js +3 -5
- package/dist/plugins/typescript/astro2tsx.js +1 -2
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +14 -0
- package/dist/plugins/typescript/features/CodeActionsProvider.js +141 -0
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +2 -1
- package/dist/plugins/typescript/features/CompletionsProvider.js +37 -32
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +2 -3
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +1 -1
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +2 -2
- package/dist/plugins/typescript/features/utils.d.ts +2 -0
- package/dist/plugins/typescript/features/utils.js +19 -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 +3 -6
- package/dist/plugins/typescript/utils.d.ts +1 -0
- package/dist/plugins/typescript/utils.js +13 -1
- package/dist/server.js +28 -7
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +16 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9abff62: Add support for code actions
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- b485acd: Fixed bug where nonexistent server settings would result in a crash
|
|
12
|
+
- 1cff04c: Fix Emmet settings not being loaded, add support for Emmet in CSS
|
|
13
|
+
- 1bcae45: Remove support for Node 12 (VS Code versions under 1.56)
|
|
14
|
+
- c8d81a1: Update directives tooltips, add missing `is:raw`
|
|
15
|
+
- Updated dependencies [1bcae45]
|
|
16
|
+
- @astrojs/svelte-language-integration@0.1.4
|
|
17
|
+
|
|
3
18
|
## 0.15.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/check.js
CHANGED
|
@@ -37,11 +37,10 @@ class AstroCheck {
|
|
|
37
37
|
this.pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(this.docManager, this.configManager, [workspacePath]));
|
|
38
38
|
}
|
|
39
39
|
async getDiagnosticsForFile(uri) {
|
|
40
|
-
var _a;
|
|
41
40
|
const diagnostics = await this.pluginHost.getDiagnostics({ uri });
|
|
42
41
|
return {
|
|
43
42
|
filePath: new URL(uri).pathname || '',
|
|
44
|
-
text:
|
|
43
|
+
text: this.docManager.get(uri)?.getText() || '',
|
|
45
44
|
diagnostics,
|
|
46
45
|
};
|
|
47
46
|
}
|
|
@@ -33,8 +33,7 @@ class IdentityMapper {
|
|
|
33
33
|
return this.url;
|
|
34
34
|
}
|
|
35
35
|
destroy() {
|
|
36
|
-
|
|
37
|
-
(_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
36
|
+
this.parent?.destroy?.();
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
exports.IdentityMapper = IdentityMapper;
|
|
@@ -130,8 +129,7 @@ class SourceMapDocumentMapper {
|
|
|
130
129
|
* Needs to be called when source mapper is no longer needed in order to prevent memory leaks.
|
|
131
130
|
*/
|
|
132
131
|
destroy() {
|
|
133
|
-
|
|
134
|
-
(_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
132
|
+
this.parent?.destroy?.();
|
|
135
133
|
this.consumer.destroy();
|
|
136
134
|
}
|
|
137
135
|
}
|
|
@@ -55,7 +55,7 @@ function getContent(content, frontmatter) {
|
|
|
55
55
|
}
|
|
56
56
|
case 'closed': {
|
|
57
57
|
const { endOffset } = frontmatter;
|
|
58
|
-
const end = (endOffset
|
|
58
|
+
const end = (endOffset ?? 0) + 3;
|
|
59
59
|
const offset = (0, utils_1.getFirstNonWhitespaceIndex)(content.slice(end));
|
|
60
60
|
return { firstNonWhitespaceOffset: end + offset };
|
|
61
61
|
}
|
|
@@ -19,7 +19,7 @@ exports.walk = walk;
|
|
|
19
19
|
* @param tag the tag to extract
|
|
20
20
|
*/
|
|
21
21
|
function extractTags(text, tag, html) {
|
|
22
|
-
const rootNodes =
|
|
22
|
+
const rootNodes = html?.roots || (0, parseHtml_1.parseHtml)(text).roots;
|
|
23
23
|
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
24
24
|
if (tag === 'style' && !matchedNodes.length && rootNodes.length) {
|
|
25
25
|
for (let child of walk(rootNodes[0])) {
|
|
@@ -30,9 +30,8 @@ function extractTags(text, tag, html) {
|
|
|
30
30
|
}
|
|
31
31
|
return matchedNodes.map(transformToTagInfo);
|
|
32
32
|
function transformToTagInfo(matchedNode) {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const end = (_b = matchedNode.endTagStart) !== null && _b !== void 0 ? _b : matchedNode.end;
|
|
33
|
+
const start = matchedNode.startTagEnd ?? matchedNode.start;
|
|
34
|
+
const end = matchedNode.endTagStart ?? matchedNode.end;
|
|
36
35
|
const startPos = positionAt(start, text);
|
|
37
36
|
const endPos = positionAt(end, text);
|
|
38
37
|
const container = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CancellationToken, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, Location, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, TextDocumentIdentifier, WorkspaceEdit, SymbolInformation, SemanticTokens } from 'vscode-languageserver';
|
|
1
|
+
import { CancellationToken, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, Location, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, TextDocumentIdentifier, WorkspaceEdit, SymbolInformation, SemanticTokens, CodeActionContext, CodeAction } from 'vscode-languageserver';
|
|
2
2
|
import type { AppCompletionItem, Plugin } from './interfaces';
|
|
3
3
|
import { DocumentManager } from '../core/documents/DocumentManager';
|
|
4
4
|
interface PluginHostConfig {
|
|
@@ -16,6 +16,7 @@ export declare class PluginHost {
|
|
|
16
16
|
resolveCompletion(textDocument: TextDocumentIdentifier, completionItem: AppCompletionItem): Promise<CompletionItem>;
|
|
17
17
|
getDiagnostics(textDocument: TextDocumentIdentifier): Promise<Diagnostic[]>;
|
|
18
18
|
doHover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null>;
|
|
19
|
+
getCodeActions(textDocument: TextDocumentIdentifier, range: Range, context: CodeActionContext, cancellationToken: CancellationToken): Promise<CodeAction[]>;
|
|
19
20
|
doTagComplete(textDocument: TextDocumentIdentifier, position: Position): Promise<string | null>;
|
|
20
21
|
getFoldingRanges(textDocument: TextDocumentIdentifier): Promise<FoldingRange[] | null>;
|
|
21
22
|
getDocumentSymbols(textDocument: TextDocumentIdentifier, cancellationToken: CancellationToken): Promise<SymbolInformation[]>;
|
|
@@ -59,7 +59,7 @@ class PluginHost {
|
|
|
59
59
|
async resolveCompletion(textDocument, completionItem) {
|
|
60
60
|
const document = this.getDocument(textDocument.uri);
|
|
61
61
|
const result = await this.execute('resolveCompletion', [document, completionItem], ExecuteMode.FirstNonNull);
|
|
62
|
-
return result
|
|
62
|
+
return result ?? completionItem;
|
|
63
63
|
}
|
|
64
64
|
async getDiagnostics(textDocument) {
|
|
65
65
|
const document = this.getDocument(textDocument.uri);
|
|
@@ -69,13 +69,17 @@ class PluginHost {
|
|
|
69
69
|
const document = this.getDocument(textDocument.uri);
|
|
70
70
|
return this.execute('doHover', [document, position], ExecuteMode.FirstNonNull);
|
|
71
71
|
}
|
|
72
|
+
async getCodeActions(textDocument, range, context, cancellationToken) {
|
|
73
|
+
const document = this.getDocument(textDocument.uri);
|
|
74
|
+
return (0, lodash_1.flatten)(await this.execute('getCodeActions', [document, range, context, cancellationToken], ExecuteMode.Collect));
|
|
75
|
+
}
|
|
72
76
|
async doTagComplete(textDocument, position) {
|
|
73
77
|
const document = this.getDocument(textDocument.uri);
|
|
74
78
|
return this.execute('doTagComplete', [document, position], ExecuteMode.FirstNonNull);
|
|
75
79
|
}
|
|
76
80
|
async getFoldingRanges(textDocument) {
|
|
77
81
|
const document = this.getDocument(textDocument.uri);
|
|
78
|
-
const foldingRanges = (0, lodash_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect))
|
|
82
|
+
const foldingRanges = (0, lodash_1.flatten)(await this.execute('getFoldingRanges', [document], ExecuteMode.Collect));
|
|
79
83
|
return foldingRanges;
|
|
80
84
|
}
|
|
81
85
|
async getDocumentSymbols(textDocument, cancellationToken) {
|
|
@@ -116,15 +120,13 @@ class PluginHost {
|
|
|
116
120
|
return await this.execute('getSignatureHelp', [document, position, context, cancellationToken], ExecuteMode.FirstNonNull);
|
|
117
121
|
}
|
|
118
122
|
onWatchFileChanges(onWatchFileChangesParams) {
|
|
119
|
-
var _a;
|
|
120
123
|
for (const support of this.plugins) {
|
|
121
|
-
|
|
124
|
+
support.onWatchFileChanges?.(onWatchFileChangesParams);
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
updateNonAstroFile(fileName, changes) {
|
|
125
|
-
var _a;
|
|
126
128
|
for (const support of this.plugins) {
|
|
127
|
-
|
|
129
|
+
support.updateNonAstroFile?.(fileName, changes);
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
getDocument(uri) {
|
|
@@ -77,7 +77,7 @@ class AstroPlugin {
|
|
|
77
77
|
const filePath = (0, utils_1.urlToPath)(document.uri);
|
|
78
78
|
const tsFilePath = (0, utils_2.toVirtualAstroFilePath)(filePath);
|
|
79
79
|
const program = lang.getProgram();
|
|
80
|
-
const sourceFile = program
|
|
80
|
+
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
81
81
|
if (!sourceFile) {
|
|
82
82
|
return undefined;
|
|
83
83
|
}
|
|
@@ -26,7 +26,7 @@ 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);
|
|
@@ -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
|
}
|
|
@@ -160,11 +160,11 @@ class CompletionsProviderImpl {
|
|
|
160
160
|
return null;
|
|
161
161
|
}
|
|
162
162
|
getPropType(type, typeChecker) {
|
|
163
|
-
const sym = type
|
|
163
|
+
const sym = type?.getSymbol();
|
|
164
164
|
if (!sym) {
|
|
165
165
|
return null;
|
|
166
166
|
}
|
|
167
|
-
for (const decl of
|
|
167
|
+
for (const decl of sym?.getDeclarations() || []) {
|
|
168
168
|
const fileName = (0, utils_3.toVirtualFilePath)(decl.getSourceFile().fileName);
|
|
169
169
|
if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx')) {
|
|
170
170
|
if (!typescript_1.default.isFunctionDeclaration(decl)) {
|
|
@@ -217,13 +217,12 @@ class CompletionsProviderImpl {
|
|
|
217
217
|
return item;
|
|
218
218
|
}
|
|
219
219
|
async isAstroComponent(document, node) {
|
|
220
|
-
var _a;
|
|
221
220
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
222
221
|
// Get the source file
|
|
223
222
|
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
224
223
|
const program = lang.getProgram();
|
|
225
|
-
const sourceFile = program
|
|
226
|
-
const typeChecker = program
|
|
224
|
+
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
225
|
+
const typeChecker = program?.getTypeChecker();
|
|
227
226
|
if (!sourceFile || !typeChecker) {
|
|
228
227
|
return false;
|
|
229
228
|
}
|
|
@@ -233,7 +232,7 @@ class CompletionsProviderImpl {
|
|
|
233
232
|
if (!importType) {
|
|
234
233
|
return false;
|
|
235
234
|
}
|
|
236
|
-
const symbolDeclaration =
|
|
235
|
+
const symbolDeclaration = importType.getSymbol()?.declarations;
|
|
237
236
|
if (symbolDeclaration) {
|
|
238
237
|
const fileName = symbolDeclaration[0].getSourceFile().fileName;
|
|
239
238
|
return fileName.endsWith('.astro');
|
|
@@ -60,8 +60,8 @@ class CSSPlugin {
|
|
|
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;
|
|
@@ -97,10 +97,26 @@ class CSSPlugin {
|
|
|
97
97
|
}
|
|
98
98
|
const cssLang = extractLanguage(cssDocument);
|
|
99
99
|
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
|
100
|
-
|
|
101
|
-
isIncomplete:
|
|
100
|
+
let emmetResults = {
|
|
101
|
+
isIncomplete: false,
|
|
102
102
|
items: [],
|
|
103
103
|
};
|
|
104
|
+
langService.setCompletionParticipants([
|
|
105
|
+
{
|
|
106
|
+
onCssProperty: (context) => {
|
|
107
|
+
if (context?.propertyName) {
|
|
108
|
+
emmetResults =
|
|
109
|
+
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), this.configManager.getEmmetConfig()) || emmetResults;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
onCssPropertyValue: (context) => {
|
|
113
|
+
if (context?.propertyValue) {
|
|
114
|
+
emmetResults =
|
|
115
|
+
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), this.configManager.getEmmetConfig()) || emmetResults;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
]);
|
|
104
120
|
const results = langService.doComplete(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
|
105
121
|
return vscode_languageserver_1.CompletionList.create([...(results ? results.items : []), ...emmetResults.items].map((completionItem) => (0, documents_1.mapCompletionItemToOriginal)(cssDocument, completionItem)),
|
|
106
122
|
// Emmet completions change on every keystroke, so they are never complete
|
|
@@ -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,18 @@ 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
|
+
references: [
|
|
47
|
+
{
|
|
48
|
+
name: 'Astro reference',
|
|
49
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#israw',
|
|
34
50
|
},
|
|
35
51
|
],
|
|
36
52
|
},
|
|
@@ -50,8 +66,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
50
66
|
description: 'Passes serializable server-side variables into a client-side script element',
|
|
51
67
|
references: [
|
|
52
68
|
{
|
|
53
|
-
name: 'Astro
|
|
54
|
-
url: 'https://docs.astro.build/en/
|
|
69
|
+
name: 'Astro reference',
|
|
70
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
|
55
71
|
},
|
|
56
72
|
],
|
|
57
73
|
},
|
|
@@ -61,7 +77,7 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
61
77
|
valueSet: 'v',
|
|
62
78
|
references: [
|
|
63
79
|
{
|
|
64
|
-
name: 'Astro
|
|
80
|
+
name: 'Astro reference',
|
|
65
81
|
url: 'https://docs.astro.build/en/core-concepts/astro-components/#using-hoisted-scripts',
|
|
66
82
|
},
|
|
67
83
|
],
|
|
@@ -72,8 +88,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
72
88
|
valueSet: 'v',
|
|
73
89
|
references: [
|
|
74
90
|
{
|
|
75
|
-
name: 'Astro
|
|
76
|
-
url: 'https://docs.astro.build/en/
|
|
91
|
+
name: 'Astro reference',
|
|
92
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
|
77
93
|
},
|
|
78
94
|
],
|
|
79
95
|
},
|
|
@@ -87,8 +103,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
87
103
|
description: 'Passes serializable server-side variables into a client-side style element',
|
|
88
104
|
references: [
|
|
89
105
|
{
|
|
90
|
-
name: 'Astro
|
|
91
|
-
url: 'https://docs.astro.build/en/
|
|
106
|
+
name: 'Astro reference',
|
|
107
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
|
92
108
|
},
|
|
93
109
|
],
|
|
94
110
|
},
|
|
@@ -98,8 +114,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
98
114
|
valueSet: 'v',
|
|
99
115
|
references: [
|
|
100
116
|
{
|
|
101
|
-
name: 'Astro
|
|
102
|
-
url: 'https://docs.astro.build/en/
|
|
117
|
+
name: 'Astro reference',
|
|
118
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
|
103
119
|
},
|
|
104
120
|
],
|
|
105
121
|
},
|
|
@@ -109,8 +125,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
109
125
|
valueSet: 'v',
|
|
110
126
|
references: [
|
|
111
127
|
{
|
|
112
|
-
name: 'Astro
|
|
113
|
-
url: 'https://docs.astro.build/en/
|
|
128
|
+
name: 'Astro reference',
|
|
129
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
|
114
130
|
},
|
|
115
131
|
],
|
|
116
132
|
},
|
|
@@ -120,8 +136,8 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
120
136
|
valueSet: 'v',
|
|
121
137
|
references: [
|
|
122
138
|
{
|
|
123
|
-
name: 'Astro
|
|
124
|
-
url: 'https://docs.astro.build/en/
|
|
139
|
+
name: 'Astro reference',
|
|
140
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
|
125
141
|
},
|
|
126
142
|
],
|
|
127
143
|
},
|
|
@@ -138,8 +154,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
138
154
|
valueSet: 'v',
|
|
139
155
|
references: [
|
|
140
156
|
{
|
|
141
|
-
name: 'Astro
|
|
142
|
-
url: 'https://docs.astro.build/en/
|
|
157
|
+
name: 'Astro reference',
|
|
158
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientload',
|
|
143
159
|
},
|
|
144
160
|
],
|
|
145
161
|
},
|
|
@@ -149,8 +165,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
149
165
|
valueSet: 'v',
|
|
150
166
|
references: [
|
|
151
167
|
{
|
|
152
|
-
name: 'Astro
|
|
153
|
-
url: 'https://docs.astro.build/en/
|
|
168
|
+
name: 'Astro reference',
|
|
169
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientidle',
|
|
154
170
|
},
|
|
155
171
|
],
|
|
156
172
|
},
|
|
@@ -160,8 +176,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
160
176
|
valueSet: 'v',
|
|
161
177
|
references: [
|
|
162
178
|
{
|
|
163
|
-
name: 'Astro
|
|
164
|
-
url: 'https://docs.astro.build/en/
|
|
179
|
+
name: 'Astro reference',
|
|
180
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientvisible',
|
|
165
181
|
},
|
|
166
182
|
],
|
|
167
183
|
},
|
|
@@ -170,8 +186,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
170
186
|
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
187
|
references: [
|
|
172
188
|
{
|
|
173
|
-
name: 'Astro
|
|
174
|
-
url: 'https://docs.astro.build/en/
|
|
189
|
+
name: 'Astro reference',
|
|
190
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientmedia',
|
|
175
191
|
},
|
|
176
192
|
],
|
|
177
193
|
},
|
|
@@ -181,8 +197,8 @@ exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
181
197
|
valueSet: 'v',
|
|
182
198
|
references: [
|
|
183
199
|
{
|
|
184
|
-
name: 'Astro
|
|
185
|
-
url: 'https://docs.astro.build/en/
|
|
200
|
+
name: 'Astro reference',
|
|
201
|
+
url: 'https://docs.astro.build/en/reference/directives-reference/#clientonly',
|
|
186
202
|
},
|
|
187
203
|
],
|
|
188
204
|
},
|
|
@@ -29,7 +29,7 @@ class LanguageServiceManager {
|
|
|
29
29
|
const handleDocumentChange = (document) => {
|
|
30
30
|
this.getSnapshot(document);
|
|
31
31
|
};
|
|
32
|
-
docManager.on('documentChange', (0, utils_1.debounceSameArg)(handleDocumentChange, (newDoc, prevDoc) => newDoc.uri ===
|
|
32
|
+
docManager.on('documentChange', (0, utils_1.debounceSameArg)(handleDocumentChange, (newDoc, prevDoc) => newDoc.uri === prevDoc?.uri, 1000));
|
|
33
33
|
docManager.on('documentOpen', handleDocumentChange);
|
|
34
34
|
}
|
|
35
35
|
async getSnapshot(pathOrDoc) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
1
|
+
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, Hover, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
2
|
import { ConfigManager } from '../../core/config';
|
|
3
3
|
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
4
|
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
@@ -7,6 +7,7 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
7
7
|
__name: string;
|
|
8
8
|
private configManager;
|
|
9
9
|
private readonly languageServiceManager;
|
|
10
|
+
private readonly codeActionsProvider;
|
|
10
11
|
private readonly completionProvider;
|
|
11
12
|
private readonly hoverProvider;
|
|
12
13
|
private readonly signatureHelpProvider;
|
|
@@ -20,6 +21,7 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
20
21
|
getFoldingRanges(document: AstroDocument): Promise<FoldingRange[] | null>;
|
|
21
22
|
getSemanticTokens(textDocument: AstroDocument, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
22
23
|
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
|
24
|
+
getCodeActions(document: AstroDocument, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
23
25
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext, cancellationToken?: CancellationToken): Promise<AppCompletionList<CompletionItemData> | null>;
|
|
24
26
|
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionItemData>, cancellationToken?: CancellationToken): Promise<AppCompletionItem<CompletionItemData>>;
|
|
25
27
|
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
@@ -38,11 +38,13 @@ const utils_3 = require("./utils");
|
|
|
38
38
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
39
39
|
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
40
40
|
const FoldingRangesProvider_1 = require("./features/FoldingRangesProvider");
|
|
41
|
+
const CodeActionsProvider_1 = require("./features/CodeActionsProvider");
|
|
41
42
|
class TypeScriptPlugin {
|
|
42
43
|
constructor(docManager, configManager, workspaceUris) {
|
|
43
44
|
this.__name = 'typescript';
|
|
44
45
|
this.configManager = configManager;
|
|
45
46
|
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
47
|
+
this.codeActionsProvider = new CodeActionsProvider_1.CodeActionsProviderImpl(this.languageServiceManager);
|
|
46
48
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
47
49
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
48
50
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
@@ -96,6 +98,12 @@ class TypeScriptPlugin {
|
|
|
96
98
|
const symbols = await this.documentSymbolsProvider.getDocumentSymbols(document);
|
|
97
99
|
return symbols;
|
|
98
100
|
}
|
|
101
|
+
async getCodeActions(document, range, context, cancellationToken) {
|
|
102
|
+
if (!this.featureEnabled('codeActions')) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
return this.codeActionsProvider.getCodeActions(document, range, context, cancellationToken);
|
|
106
|
+
}
|
|
99
107
|
async getCompletions(document, position, completionContext, cancellationToken) {
|
|
100
108
|
if (!this.featureEnabled('completions')) {
|
|
101
109
|
return null;
|
|
@@ -171,7 +179,7 @@ class TypeScriptPlugin {
|
|
|
171
179
|
}
|
|
172
180
|
getGoToDefinitionRefsForImportSpecifier(tsFilePath, offset, lang) {
|
|
173
181
|
const program = lang.getProgram();
|
|
174
|
-
const sourceFile = program
|
|
182
|
+
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
175
183
|
if (sourceFile) {
|
|
176
184
|
let node = typescript_1.default.getTouchingPropertyName(sourceFile, offset);
|
|
177
185
|
if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
|
|
@@ -14,9 +14,8 @@ function createAstroSys(getSnapshot) {
|
|
|
14
14
|
const AstroSys = {
|
|
15
15
|
...typescript_1.default.sys,
|
|
16
16
|
fileExists(path) {
|
|
17
|
-
var _a;
|
|
18
17
|
path = (0, utils_1.ensureRealFilePath)(path);
|
|
19
|
-
const exists =
|
|
18
|
+
const exists = fileExistsCache.get(path) ?? typescript_1.default.sys.fileExists(path);
|
|
20
19
|
fileExistsCache.set(path, exists);
|
|
21
20
|
return exists;
|
|
22
21
|
},
|
|
@@ -25,14 +24,13 @@ function createAstroSys(getSnapshot) {
|
|
|
25
24
|
return snapshot.getText(0, snapshot.getLength());
|
|
26
25
|
},
|
|
27
26
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
28
|
-
const extensionsWithAstro = (extensions
|
|
27
|
+
const extensionsWithAstro = (extensions ?? []).concat(...['.astro', '.svelte', '.vue']);
|
|
29
28
|
const result = typescript_1.default.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
|
|
30
29
|
return result;
|
|
31
30
|
},
|
|
32
31
|
deleteFile(path) {
|
|
33
|
-
var _a, _b;
|
|
34
32
|
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
35
|
-
return
|
|
33
|
+
return typescript_1.default.sys.deleteFile?.(path);
|
|
36
34
|
},
|
|
37
35
|
deleteFromCache(path) {
|
|
38
36
|
fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
|
|
@@ -13,7 +13,6 @@ function escapeTemplateLiteralContent(content) {
|
|
|
13
13
|
return content.replace(/`/g, '\\`');
|
|
14
14
|
}
|
|
15
15
|
function default_1(content, className) {
|
|
16
|
-
var _a, _b;
|
|
17
16
|
let result = {
|
|
18
17
|
code: '',
|
|
19
18
|
};
|
|
@@ -22,7 +21,7 @@ function default_1(content, className) {
|
|
|
22
21
|
let frontMatterRaw = '';
|
|
23
22
|
if (astroDocument.frontmatter.state === 'closed') {
|
|
24
23
|
frontMatterRaw = content
|
|
25
|
-
.substring(
|
|
24
|
+
.substring(astroDocument.frontmatter.startOffset ?? 0, (astroDocument.frontmatter.endOffset ?? 0) + 3)
|
|
26
25
|
// Handle case where semicolons is not used in the frontmatter section
|
|
27
26
|
// We need to add something before the semi-colon or TypeScript won't be able to do completions
|
|
28
27
|
.replace(/((?!^)(?<!;)\n)(---)/g, (_whole, start, _dashes) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CancellationToken } from 'vscode-languageserver';
|
|
2
|
+
import { CodeAction, CodeActionContext, Range } from 'vscode-languageserver-types';
|
|
3
|
+
import { AstroDocument } from '../../../core/documents';
|
|
4
|
+
import { CodeActionsProvider } from '../../interfaces';
|
|
5
|
+
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
6
|
+
export declare const sortImportKind: string;
|
|
7
|
+
export declare class CodeActionsProviderImpl implements CodeActionsProvider {
|
|
8
|
+
private languageServiceManager;
|
|
9
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
10
|
+
getCodeActions(document: AstroDocument, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
11
|
+
private getComponentQuickFix;
|
|
12
|
+
private organizeSortImports;
|
|
13
|
+
private fixIndentationOfImports;
|
|
14
|
+
}
|