@astrojs/language-server 0.15.0 → 0.17.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 +32 -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/AstroDocument.d.ts +1 -0
- package/dist/core/documents/AstroDocument.js +1 -0
- package/dist/core/documents/DocumentMapper.d.ts +2 -0
- package/dist/core/documents/DocumentMapper.js +9 -9
- package/dist/core/documents/parseAstro.js +1 -1
- package/dist/core/documents/utils.d.ts +1 -0
- package/dist/core/documents/utils.js +19 -5
- package/dist/plugins/PluginHost.d.ts +2 -1
- package/dist/plugins/PluginHost.js +8 -6
- package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
- package/dist/plugins/astro/AstroPlugin.js +1 -83
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -5
- package/dist/plugins/astro/features/CompletionsProvider.js +49 -59
- 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/typescript/LanguageServiceManager.js +1 -1
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +5 -4
- package/dist/plugins/typescript/TypeScriptPlugin.js +30 -108
- 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 +16 -0
- package/dist/plugins/typescript/features/CodeActionsProvider.js +206 -0
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +5 -2
- package/dist/plugins/typescript/features/CompletionsProvider.js +116 -68
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/DefinitionsProvider.js +57 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +60 -18
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +13 -6
- package/dist/plugins/typescript/features/HoverProvider.js +14 -1
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +1 -1
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +11 -3
- 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 +23 -6
- package/dist/plugins/typescript/module-loader.js +1 -1
- package/dist/plugins/typescript/previewer.js +1 -1
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +22 -2
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +48 -1
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +2 -1
- package/dist/plugins/typescript/snapshots/utils.js +3 -6
- package/dist/plugins/typescript/utils.d.ts +12 -1
- package/dist/plugins/typescript/utils.js +29 -1
- package/dist/server.js +43 -14
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +16 -3
- package/package.json +2 -2
|
@@ -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
|
},
|
|
@@ -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,8 +7,10 @@ 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;
|
|
13
|
+
private readonly definitionsProvider;
|
|
12
14
|
private readonly signatureHelpProvider;
|
|
13
15
|
private readonly diagnosticsProvider;
|
|
14
16
|
private readonly documentSymbolsProvider;
|
|
@@ -18,8 +20,9 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
18
20
|
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
19
21
|
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
20
22
|
getFoldingRanges(document: AstroDocument): Promise<FoldingRange[] | null>;
|
|
21
|
-
getSemanticTokens(
|
|
23
|
+
getSemanticTokens(document: AstroDocument, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
22
24
|
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
|
25
|
+
getCodeActions(document: AstroDocument, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
23
26
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext, cancellationToken?: CancellationToken): Promise<AppCompletionList<CompletionItemData> | null>;
|
|
24
27
|
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionItemData>, cancellationToken?: CancellationToken): Promise<AppCompletionItem<CompletionItemData>>;
|
|
25
28
|
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
@@ -27,7 +30,5 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
27
30
|
onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
|
|
28
31
|
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
29
32
|
getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
|
|
30
|
-
private goToDefinitionFoundOnlyAlias;
|
|
31
|
-
private getGoToDefinitionRefsForImportSpecifier;
|
|
32
33
|
private featureEnabled;
|
|
33
34
|
}
|
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.TypeScriptPlugin = void 0;
|
|
27
|
-
const typescript_1 =
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
28
8
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
29
|
-
const path_1 = require("path");
|
|
30
|
-
const utils_1 = require("../../utils");
|
|
31
9
|
const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
32
10
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
33
11
|
const HoverProvider_1 = require("./features/HoverProvider");
|
|
34
12
|
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
35
|
-
const utils_2 = require("./features/utils");
|
|
36
13
|
const LanguageServiceManager_1 = require("./LanguageServiceManager");
|
|
37
|
-
const
|
|
14
|
+
const utils_1 = require("./utils");
|
|
38
15
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
39
16
|
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
40
17
|
const FoldingRangesProvider_1 = require("./features/FoldingRangesProvider");
|
|
18
|
+
const CodeActionsProvider_1 = require("./features/CodeActionsProvider");
|
|
19
|
+
const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
|
|
41
20
|
class TypeScriptPlugin {
|
|
42
21
|
constructor(docManager, configManager, workspaceUris) {
|
|
43
22
|
this.__name = 'typescript';
|
|
44
23
|
this.configManager = configManager;
|
|
45
24
|
this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
|
|
46
|
-
this.
|
|
25
|
+
this.codeActionsProvider = new CodeActionsProvider_1.CodeActionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
26
|
+
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
47
27
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
28
|
+
this.definitionsProvider = new DefinitionsProvider_1.DefinitionsProviderImpl(this.languageServiceManager);
|
|
48
29
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
49
30
|
this.diagnosticsProvider = new DiagnosticsProvider_1.DiagnosticsProviderImpl(this.languageServiceManager);
|
|
50
31
|
this.documentSymbolsProvider = new DocumentSymbolsProvider_1.DocumentSymbolsProviderImpl(this.languageServiceManager);
|
|
@@ -52,7 +33,7 @@ class TypeScriptPlugin {
|
|
|
52
33
|
this.foldingRangesProvider = new FoldingRangesProvider_1.FoldingRangesProviderImpl(this.languageServiceManager);
|
|
53
34
|
}
|
|
54
35
|
async doHover(document, position) {
|
|
55
|
-
if (!this.featureEnabled('hover')) {
|
|
36
|
+
if (!(await this.featureEnabled(document, 'hover'))) {
|
|
56
37
|
return null;
|
|
57
38
|
}
|
|
58
39
|
return this.hoverProvider.doHover(document, position);
|
|
@@ -61,7 +42,7 @@ class TypeScriptPlugin {
|
|
|
61
42
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
62
43
|
const fragment = await tsDoc.createFragment();
|
|
63
44
|
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
|
|
64
|
-
let renames = lang.findRenameLocations((0,
|
|
45
|
+
let renames = lang.findRenameLocations((0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
|
|
65
46
|
if (!renames) {
|
|
66
47
|
return null;
|
|
67
48
|
}
|
|
@@ -69,13 +50,13 @@ class TypeScriptPlugin {
|
|
|
69
50
|
changes: {},
|
|
70
51
|
};
|
|
71
52
|
renames.forEach((rename) => {
|
|
72
|
-
const filePath = (0,
|
|
53
|
+
const filePath = (0, utils_1.ensureRealFilePath)(rename.fileName);
|
|
73
54
|
if (!(filePath in edit.changes)) {
|
|
74
55
|
edit.changes[filePath] = [];
|
|
75
56
|
}
|
|
76
57
|
edit.changes[filePath].push({
|
|
77
58
|
newText: newName,
|
|
78
|
-
range: (0,
|
|
59
|
+
range: (0, utils_1.convertToLocationRange)(fragment, rename.textSpan),
|
|
79
60
|
});
|
|
80
61
|
});
|
|
81
62
|
return edit;
|
|
@@ -83,21 +64,27 @@ class TypeScriptPlugin {
|
|
|
83
64
|
async getFoldingRanges(document) {
|
|
84
65
|
return this.foldingRangesProvider.getFoldingRanges(document);
|
|
85
66
|
}
|
|
86
|
-
async getSemanticTokens(
|
|
87
|
-
if (!this.featureEnabled('semanticTokens')) {
|
|
67
|
+
async getSemanticTokens(document, range, cancellationToken) {
|
|
68
|
+
if (!(await this.featureEnabled(document, 'semanticTokens'))) {
|
|
88
69
|
return null;
|
|
89
70
|
}
|
|
90
|
-
return this.semanticTokensProvider.getSemanticTokens(
|
|
71
|
+
return this.semanticTokensProvider.getSemanticTokens(document, range, cancellationToken);
|
|
91
72
|
}
|
|
92
73
|
async getDocumentSymbols(document) {
|
|
93
|
-
if (!this.featureEnabled('documentSymbols')) {
|
|
74
|
+
if (!(await this.featureEnabled(document, 'documentSymbols'))) {
|
|
94
75
|
return [];
|
|
95
76
|
}
|
|
96
77
|
const symbols = await this.documentSymbolsProvider.getDocumentSymbols(document);
|
|
97
78
|
return symbols;
|
|
98
79
|
}
|
|
80
|
+
async getCodeActions(document, range, context, cancellationToken) {
|
|
81
|
+
if (!(await this.featureEnabled(document, 'codeActions'))) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
return this.codeActionsProvider.getCodeActions(document, range, context, cancellationToken);
|
|
85
|
+
}
|
|
99
86
|
async getCompletions(document, position, completionContext, cancellationToken) {
|
|
100
|
-
if (!this.featureEnabled('completions')) {
|
|
87
|
+
if (!(await this.featureEnabled(document, 'completions'))) {
|
|
101
88
|
return null;
|
|
102
89
|
}
|
|
103
90
|
const completions = await this.completionProvider.getCompletions(document, position, completionContext, cancellationToken);
|
|
@@ -107,36 +94,10 @@ class TypeScriptPlugin {
|
|
|
107
94
|
return this.completionProvider.resolveCompletion(document, completionItem, cancellationToken);
|
|
108
95
|
}
|
|
109
96
|
async getDefinitions(document, position) {
|
|
110
|
-
|
|
111
|
-
const mainFragment = await tsDoc.createFragment();
|
|
112
|
-
const filePath = tsDoc.filePath;
|
|
113
|
-
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
|
|
114
|
-
const fragmentPosition = mainFragment.getGeneratedPosition(position);
|
|
115
|
-
const fragmentOffset = mainFragment.offsetAt(fragmentPosition);
|
|
116
|
-
let defs = lang.getDefinitionAndBoundSpan(tsFilePath, fragmentOffset);
|
|
117
|
-
if (!defs || !defs.definitions) {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
// Resolve all imports if we can
|
|
121
|
-
if (this.goToDefinitionFoundOnlyAlias(tsFilePath, defs.definitions)) {
|
|
122
|
-
let importDef = this.getGoToDefinitionRefsForImportSpecifier(tsFilePath, fragmentOffset, lang);
|
|
123
|
-
if (importDef) {
|
|
124
|
-
defs = importDef;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const docs = new utils_2.SnapshotFragmentMap(this.languageServiceManager);
|
|
128
|
-
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
129
|
-
const result = await Promise.all(defs.definitions.map(async (def) => {
|
|
130
|
-
const { fragment, snapshot } = await docs.retrieve(def.fileName);
|
|
131
|
-
const fileName = (0, utils_3.ensureRealFilePath)(def.fileName);
|
|
132
|
-
// Since we converted our files to TSX and we don't have sourcemaps, we don't know where the function is, unfortunate
|
|
133
|
-
const textSpan = (0, utils_3.isVirtualFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
|
|
134
|
-
return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(fileName), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(mainFragment, defs.textSpan));
|
|
135
|
-
}));
|
|
136
|
-
return result.filter(utils_1.isNotNullOrUndefined);
|
|
97
|
+
return this.definitionsProvider.getDefinitions(document, position);
|
|
137
98
|
}
|
|
138
99
|
async getDiagnostics(document, cancellationToken) {
|
|
139
|
-
if (!this.featureEnabled('diagnostics')) {
|
|
100
|
+
if (!(await this.featureEnabled(document, 'diagnostics'))) {
|
|
140
101
|
return [];
|
|
141
102
|
}
|
|
142
103
|
return this.diagnosticsProvider.getDiagnostics(document, cancellationToken);
|
|
@@ -144,7 +105,7 @@ class TypeScriptPlugin {
|
|
|
144
105
|
async onWatchFileChanges(onWatchFileChangesParas) {
|
|
145
106
|
let doneUpdateProjectFiles = false;
|
|
146
107
|
for (const { fileName, changeType } of onWatchFileChangesParas) {
|
|
147
|
-
const scriptKind = (0,
|
|
108
|
+
const scriptKind = (0, utils_1.getScriptKindFromFileName)(fileName);
|
|
148
109
|
if (scriptKind === typescript_1.default.ScriptKind.Unknown) {
|
|
149
110
|
continue;
|
|
150
111
|
}
|
|
@@ -166,48 +127,9 @@ class TypeScriptPlugin {
|
|
|
166
127
|
async getSignatureHelp(document, position, context, cancellationToken) {
|
|
167
128
|
return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
|
|
168
129
|
}
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
getGoToDefinitionRefsForImportSpecifier(tsFilePath, offset, lang) {
|
|
173
|
-
const program = lang.getProgram();
|
|
174
|
-
const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
|
|
175
|
-
if (sourceFile) {
|
|
176
|
-
let node = typescript_1.default.getTouchingPropertyName(sourceFile, offset);
|
|
177
|
-
if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
|
|
178
|
-
if (node.parent.kind === typescript_1.SyntaxKind.ImportClause) {
|
|
179
|
-
let decl = node.parent.parent;
|
|
180
|
-
let spec = typescript_1.default.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
|
|
181
|
-
if (spec) {
|
|
182
|
-
let fileName = (0, path_1.join)((0, path_1.dirname)(tsFilePath), spec);
|
|
183
|
-
let start = node.pos + 1;
|
|
184
|
-
let def = {
|
|
185
|
-
definitions: [
|
|
186
|
-
{
|
|
187
|
-
kind: 'alias',
|
|
188
|
-
fileName,
|
|
189
|
-
name: '',
|
|
190
|
-
containerKind: '',
|
|
191
|
-
containerName: '',
|
|
192
|
-
textSpan: {
|
|
193
|
-
start: 0,
|
|
194
|
-
length: 0,
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
textSpan: {
|
|
199
|
-
start,
|
|
200
|
-
length: node.end - start,
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
return def;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
featureEnabled(feature) {
|
|
210
|
-
return (this.configManager.enabled('typescript.enabled') && this.configManager.enabled(`typescript.${feature}.enabled`));
|
|
130
|
+
async featureEnabled(document, feature) {
|
|
131
|
+
return ((await this.configManager.isEnabled(document, 'typescript')) &&
|
|
132
|
+
(await this.configManager.isEnabled(document, 'typescript', feature)));
|
|
211
133
|
}
|
|
212
134
|
}
|
|
213
135
|
exports.TypeScriptPlugin = TypeScriptPlugin;
|
|
@@ -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,16 @@
|
|
|
1
|
+
import { CancellationToken } from 'vscode-languageserver';
|
|
2
|
+
import { CodeAction, CodeActionContext, Range } from 'vscode-languageserver-types';
|
|
3
|
+
import { ConfigManager } from '../../../core/config';
|
|
4
|
+
import { AstroDocument } from '../../../core/documents';
|
|
5
|
+
import { CodeActionsProvider } from '../../interfaces';
|
|
6
|
+
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
7
|
+
export declare const sortImportKind: string;
|
|
8
|
+
export declare class CodeActionsProviderImpl implements CodeActionsProvider {
|
|
9
|
+
private languageServiceManager;
|
|
10
|
+
private configManager;
|
|
11
|
+
constructor(languageServiceManager: LanguageServiceManager, configManager: ConfigManager);
|
|
12
|
+
getCodeActions(document: AstroDocument, range: Range, context: CodeActionContext, cancellationToken?: CancellationToken): Promise<CodeAction[]>;
|
|
13
|
+
private getComponentQuickFix;
|
|
14
|
+
private organizeSortImports;
|
|
15
|
+
private fixIndentationOfImports;
|
|
16
|
+
}
|