@astrojs/language-server 1.0.8 → 2.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -5
- package/README.md +10 -0
- package/bin/nodeServer.js +7 -3
- package/dist/check.d.ts +20 -19
- package/dist/check.js +106 -49
- package/dist/core/astro2tsx.d.ts +6 -0
- package/dist/core/astro2tsx.js +119 -0
- package/dist/core/index.d.ts +28 -0
- package/dist/core/index.js +121 -0
- package/dist/core/parseAstro.d.ts +26 -0
- package/dist/core/parseAstro.js +47 -0
- package/dist/core/parseCSS.d.ts +8 -0
- package/dist/core/parseCSS.js +138 -0
- package/dist/core/parseHTML.d.ts +11 -0
- package/dist/core/parseHTML.js +114 -0
- package/dist/core/parseJS.d.ts +7 -0
- package/dist/core/parseJS.js +236 -0
- package/dist/core/svelte.d.ts +18 -0
- package/dist/core/svelte.js +45 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/core/utils.js +138 -0
- package/dist/core/vue.d.ts +18 -0
- package/dist/core/vue.js +45 -0
- package/dist/importPackage.d.ts +3 -3
- package/dist/importPackage.js +12 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -6
- package/dist/languageServerPlugin.d.ts +2 -0
- package/dist/languageServerPlugin.js +102 -0
- package/dist/nodeServer.js +6 -0
- package/dist/plugins/astro.d.ts +3 -0
- package/dist/plugins/astro.js +123 -0
- package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +48 -0
- package/dist/plugins/typescript/codeActions.d.ts +4 -0
- package/dist/plugins/typescript/codeActions.js +54 -0
- package/dist/plugins/typescript/completions.d.ts +3 -0
- package/dist/plugins/typescript/completions.js +87 -0
- package/dist/plugins/typescript/diagnostics.d.ts +12 -0
- package/dist/plugins/typescript/diagnostics.js +99 -0
- package/dist/plugins/typescript/index.d.ts +3 -0
- package/dist/plugins/typescript/index.js +61 -0
- package/dist/utils.d.ts +26 -69
- package/dist/utils.js +85 -235
- package/package.json +52 -39
- package/types/astro-jsx.d.ts +49 -5
- package/bin/browserServer.js +0 -3
- package/dist/browser.js +0 -15
- package/dist/core/DiagnosticsManager.d.ts +0 -13
- package/dist/core/DiagnosticsManager.js +0 -29
- package/dist/core/config/ConfigManager.d.ts +0 -43
- package/dist/core/config/ConfigManager.js +0 -226
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -18
- package/dist/core/config/interfaces.d.ts +0 -77
- package/dist/core/config/interfaces.js +0 -2
- package/dist/core/documents/AstroDocument.d.ts +0 -19
- package/dist/core/documents/AstroDocument.js +0 -43
- package/dist/core/documents/DocumentBase.d.ts +0 -68
- package/dist/core/documents/DocumentBase.js +0 -75
- package/dist/core/documents/DocumentManager.d.ts +0 -23
- package/dist/core/documents/DocumentManager.js +0 -100
- package/dist/core/documents/DocumentMapper.d.ts +0 -94
- package/dist/core/documents/DocumentMapper.js +0 -264
- package/dist/core/documents/index.d.ts +0 -5
- package/dist/core/documents/index.js +0 -21
- package/dist/core/documents/parseAstro.d.ts +0 -15
- package/dist/core/documents/parseAstro.js +0 -63
- package/dist/core/documents/parseHtml.d.ts +0 -13
- package/dist/core/documents/parseHtml.js +0 -126
- package/dist/core/documents/utils.d.ts +0 -63
- package/dist/core/documents/utils.js +0 -223
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -43
- package/dist/plugins/PluginHost.d.ts +0 -42
- package/dist/plugins/PluginHost.js +0 -206
- package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
- package/dist/plugins/astro/AstroPlugin.js +0 -90
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
- package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
- package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
- package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
- package/dist/plugins/css/CSSDocument.d.ts +0 -45
- package/dist/plugins/css/CSSDocument.js +0 -68
- package/dist/plugins/css/CSSPlugin.d.ts +0 -39
- package/dist/plugins/css/CSSPlugin.js +0 -274
- package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
- package/dist/plugins/css/StyleAttributeDocument.js +0 -64
- package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
- package/dist/plugins/css/features/astro-selectors.js +0 -15
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
- package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
- package/dist/plugins/css/language-service.d.ts +0 -3
- package/dist/plugins/css/language-service.js +0 -47
- package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
- package/dist/plugins/html/HTMLPlugin.js +0 -198
- package/dist/plugins/html/utils.d.ts +0 -6
- package/dist/plugins/html/utils.js +0 -11
- package/dist/plugins/index.d.ts +0 -6
- package/dist/plugins/index.js +0 -22
- package/dist/plugins/interfaces.d.ts +0 -101
- package/dist/plugins/interfaces.js +0 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
- package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
- package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
- package/dist/plugins/typescript/astro-sys.d.ts +0 -8
- package/dist/plugins/typescript/astro-sys.js +0 -46
- package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -26
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
- package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
- package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
- package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
- package/dist/plugins/typescript/features/HoverProvider.js +0 -50
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
- package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/RenameProvider.js +0 -60
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
- package/dist/plugins/typescript/features/utils.d.ts +0 -14
- package/dist/plugins/typescript/features/utils.js +0 -48
- package/dist/plugins/typescript/language-service.d.ts +0 -42
- package/dist/plugins/typescript/language-service.js +0 -278
- package/dist/plugins/typescript/module-loader.d.ts +0 -23
- package/dist/plugins/typescript/module-loader.js +0 -155
- package/dist/plugins/typescript/previewer.d.ts +0 -7
- package/dist/plugins/typescript/previewer.js +0 -108
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +0 -95
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +0 -187
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +0 -44
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +0 -179
- package/dist/plugins/typescript/snapshots/utils.d.ts +0 -29
- package/dist/plugins/typescript/snapshots/utils.js +0 -106
- package/dist/plugins/typescript/utils.d.ts +0 -75
- package/dist/plugins/typescript/utils.js +0 -366
- package/dist/server.d.ts +0 -6
- package/dist/server.js +0 -275
- package/types/README.md +0 -5
- /package/dist/{browser.d.ts → nodeServer.d.ts} +0 -0
- /package/dist/plugins/{html/features/astro-attributes.d.ts → html-data.d.ts} +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 The Astro Technology Company
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -20,13 +20,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
"""
|
|
25
24
|
|
|
26
|
-
This license applies to code originating from the https://github.com/sveltejs/language-tools repository
|
|
27
|
-
which has provided an extremely solid foundation for us to build upon:
|
|
25
|
+
This license applies to code originating from the https://github.com/sveltejs/language-tools repository:
|
|
28
26
|
|
|
29
|
-
Copyright (c) 2020-Present [these people](https://github.com/sveltejs/language-tools/graphs/contributors)
|
|
27
|
+
Copyright (c) 2020-Present [these people](https://github.com/sveltejs/language-tools/graphs/contributors)
|
|
30
28
|
|
|
31
29
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
32
30
|
|
package/README.md
CHANGED
|
@@ -13,3 +13,13 @@ The Astro language server, implement the [language server protocol](https://micr
|
|
|
13
13
|
├── test # Tests
|
|
14
14
|
└── types # Types injected into Astro files by the language server under certain conditions
|
|
15
15
|
```
|
|
16
|
+
|
|
17
|
+
## Troubleshooting
|
|
18
|
+
|
|
19
|
+
### Formatting does not work
|
|
20
|
+
|
|
21
|
+
> Using VS Code? This section does not apply to you, the VS Code extension includes both Prettier and the Astro plugin by default.
|
|
22
|
+
|
|
23
|
+
The Astro language server uses Prettier to format Astro files, but does not include `prettier` or `prettier-plugin-astro` by itself as dependencies in order to keep the dependency count low and allow users to better control the version of Prettier they want to use.
|
|
24
|
+
|
|
25
|
+
As such, if you want to use formatting, you'll need to install `prettier` and `prettier-plugin-astro` as dependencies in your project.
|
package/bin/nodeServer.js
CHANGED
package/dist/check.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
text: string;
|
|
8
|
-
diagnostics: Diagnostic[];
|
|
1
|
+
import * as kit from '@volar/kit';
|
|
2
|
+
export { DiagnosticSeverity, type Diagnostic } from '@volar/language-server';
|
|
3
|
+
export interface CheckResult {
|
|
4
|
+
errors: kit.Diagnostic[];
|
|
5
|
+
fileUrl: URL;
|
|
6
|
+
fileContent: string;
|
|
9
7
|
}
|
|
10
8
|
export declare class AstroCheck {
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
private readonly workspacePath;
|
|
10
|
+
private readonly typescriptPath;
|
|
11
|
+
private ts;
|
|
12
|
+
private project;
|
|
13
|
+
private linter;
|
|
14
|
+
constructor(workspacePath: string, typescriptPath: string | undefined);
|
|
15
|
+
/**
|
|
16
|
+
* Lint a list of files or the entire project and optionally log the errors found
|
|
17
|
+
* @param fileNames List of files to lint, if undefined, all files included in the project will be linted
|
|
18
|
+
* @param logErrors Whether to log errors by itself. This is disabled by default.
|
|
19
|
+
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
20
|
+
*/
|
|
21
|
+
lint(fileNames?: string[] | undefined, logErrors?: boolean): Promise<CheckResult[]>;
|
|
21
22
|
private initialize;
|
|
22
|
-
private
|
|
23
|
+
private getTsconfig;
|
|
23
24
|
}
|
package/dist/check.js
CHANGED
|
@@ -1,60 +1,117 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.AstroCheck = exports.DiagnosticSeverity = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
30
|
+
const kit = __importStar(require("@volar/kit"));
|
|
31
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
32
|
+
const node_url_1 = require("node:url");
|
|
33
|
+
const index_js_1 = require("./core/index.js");
|
|
34
|
+
const svelte_js_1 = require("./core/svelte.js");
|
|
35
|
+
const utils_js_1 = require("./core/utils.js");
|
|
36
|
+
const vue_js_1 = require("./core/vue.js");
|
|
37
|
+
const astro_js_1 = __importDefault(require("./plugins/astro.js"));
|
|
38
|
+
const index_js_2 = __importDefault(require("./plugins/typescript/index.js"));
|
|
39
|
+
// Export those for downstream consumers
|
|
40
|
+
var language_server_1 = require("@volar/language-server");
|
|
41
|
+
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return language_server_1.DiagnosticSeverity; } });
|
|
11
42
|
class AstroCheck {
|
|
12
|
-
constructor(workspacePath, typescriptPath
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
try {
|
|
17
|
-
const ts = require(typescriptPath);
|
|
18
|
-
this.initialize(workspacePath, ts);
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
throw new Error(`Couldn't load TypeScript from path ${typescriptPath}`);
|
|
22
|
-
}
|
|
23
|
-
if (options) {
|
|
24
|
-
this.configManager.updateGlobalConfig(options);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
upsertDocument(doc) {
|
|
28
|
-
this.docManager.openDocument({
|
|
29
|
-
text: doc.text,
|
|
30
|
-
uri: doc.uri,
|
|
31
|
-
});
|
|
32
|
-
this.docManager.markAsOpenedInClient(doc.uri);
|
|
43
|
+
constructor(workspacePath, typescriptPath) {
|
|
44
|
+
this.workspacePath = workspacePath;
|
|
45
|
+
this.typescriptPath = typescriptPath;
|
|
46
|
+
this.initialize();
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Lint a list of files or the entire project and optionally log the errors found
|
|
50
|
+
* @param fileNames List of files to lint, if undefined, all files included in the project will be linted
|
|
51
|
+
* @param logErrors Whether to log errors by itself. This is disabled by default.
|
|
52
|
+
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
53
|
+
*/
|
|
54
|
+
async lint(fileNames = undefined, logErrors = false) {
|
|
55
|
+
const files = fileNames !== undefined
|
|
56
|
+
? fileNames
|
|
57
|
+
: this.project.languageServiceHost
|
|
58
|
+
.getScriptFileNames()
|
|
59
|
+
.filter((file) => file.endsWith('.astro'));
|
|
60
|
+
const errors = [];
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const fileErrors = await this.linter.check(file);
|
|
63
|
+
if (logErrors) {
|
|
64
|
+
this.linter.logErrors(file, fileErrors);
|
|
65
|
+
}
|
|
66
|
+
if (fileErrors.length > 0) {
|
|
67
|
+
const fileSnapshot = this.project.languageServiceHost.getScriptSnapshot(file);
|
|
68
|
+
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
|
|
69
|
+
errors.push({
|
|
70
|
+
errors: fileErrors,
|
|
71
|
+
fileContent: fileContent ?? '',
|
|
72
|
+
fileUrl: (0, node_url_1.pathToFileURL)(file),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
37
75
|
}
|
|
38
|
-
|
|
39
|
-
this.docManager.releaseDocument(uri);
|
|
76
|
+
return errors;
|
|
40
77
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fileUri: uri || '',
|
|
55
|
-
text: this.docManager.get(uri)?.getText() || '',
|
|
56
|
-
diagnostics,
|
|
78
|
+
initialize() {
|
|
79
|
+
this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
|
|
80
|
+
const tsconfigPath = this.getTsconfig();
|
|
81
|
+
const config = {
|
|
82
|
+
languages: {
|
|
83
|
+
astro: (0, index_js_1.getLanguageModule)((0, utils_js_1.getAstroInstall)([this.workspacePath]), this.ts),
|
|
84
|
+
svelte: (0, svelte_js_1.getSvelteLanguageModule)(),
|
|
85
|
+
vue: (0, vue_js_1.getVueLanguageModule)(),
|
|
86
|
+
},
|
|
87
|
+
services: {
|
|
88
|
+
typescript: (0, index_js_2.default)(),
|
|
89
|
+
astro: (0, astro_js_1.default)(),
|
|
90
|
+
},
|
|
57
91
|
};
|
|
92
|
+
if (tsconfigPath) {
|
|
93
|
+
this.project = kit.createProject(tsconfigPath, [
|
|
94
|
+
{ extension: 'astro', isMixedContent: true, scriptKind: 7 },
|
|
95
|
+
{ extension: 'vue', isMixedContent: true, scriptKind: 7 },
|
|
96
|
+
{ extension: 'svelte', isMixedContent: true, scriptKind: 7 },
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.project = kit.createInferredProject(this.workspacePath, () => {
|
|
101
|
+
return fast_glob_1.default.sync('**/*.astro', {
|
|
102
|
+
cwd: this.workspacePath,
|
|
103
|
+
ignore: ['node_modules'],
|
|
104
|
+
absolute: true,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
this.linter = kit.createLinter(config, this.project.languageServiceHost);
|
|
109
|
+
}
|
|
110
|
+
getTsconfig() {
|
|
111
|
+
const tsconfig = this.ts.findConfigFile(this.workspacePath, this.ts.sys.fileExists) ||
|
|
112
|
+
this.ts.findConfigFile(this.workspacePath, this.ts.sys.fileExists, 'jsconfig.json');
|
|
113
|
+
return tsconfig;
|
|
58
114
|
}
|
|
59
115
|
}
|
|
60
116
|
exports.AstroCheck = AstroCheck;
|
|
117
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VirtualFile } from '@volar/language-core';
|
|
2
|
+
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
3
|
+
export declare function astro2tsx(input: string, fileName: string, ts: typeof import('typescript/lib/tsserverlibrary.js'), htmlDocument: HTMLDocument): {
|
|
4
|
+
virtualFile: VirtualFile;
|
|
5
|
+
diagnostics: import("@astrojs/compiler").DiagnosticMessage[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.astro2tsx = void 0;
|
|
4
|
+
const sync_1 = require("@astrojs/compiler/sync");
|
|
5
|
+
const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
|
|
6
|
+
const language_core_1 = require("@volar/language-core");
|
|
7
|
+
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
|
+
function astro2tsx(input, fileName, ts, htmlDocument) {
|
|
10
|
+
const tsx = (0, sync_1.convertToTSX)(input, { filename: fileName });
|
|
11
|
+
return {
|
|
12
|
+
virtualFile: getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument),
|
|
13
|
+
diagnostics: tsx.diagnostics,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.astro2tsx = astro2tsx;
|
|
17
|
+
function getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument) {
|
|
18
|
+
tsx.code = (0, utils_js_1.patchTSX)(tsx.code);
|
|
19
|
+
const v3Mappings = (0, sourcemap_codec_1.decode)(tsx.map.mappings);
|
|
20
|
+
const sourcedDoc = vscode_html_languageservice_1.TextDocument.create(fileName, 'astro', 0, input);
|
|
21
|
+
const genDoc = vscode_html_languageservice_1.TextDocument.create(fileName + '.tsx', 'typescriptreact', 0, tsx.code);
|
|
22
|
+
const mappings = [];
|
|
23
|
+
let current;
|
|
24
|
+
for (let genLine = 0; genLine < v3Mappings.length; genLine++) {
|
|
25
|
+
for (const segment of v3Mappings[genLine]) {
|
|
26
|
+
const genCharacter = segment[0];
|
|
27
|
+
const genOffset = genDoc.offsetAt({ line: genLine, character: genCharacter });
|
|
28
|
+
if (current) {
|
|
29
|
+
let length = genOffset - current.genOffset;
|
|
30
|
+
const sourceText = input.substring(current.sourceOffset, current.sourceOffset + length);
|
|
31
|
+
const genText = tsx.code.substring(current.genOffset, current.genOffset + length);
|
|
32
|
+
if (sourceText !== genText) {
|
|
33
|
+
length = 0;
|
|
34
|
+
for (let i = 0; i < genOffset - current.genOffset; i++) {
|
|
35
|
+
if (sourceText[i] === genText[i]) {
|
|
36
|
+
length = i + 1;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (length > 0) {
|
|
44
|
+
const lastMapping = mappings.length ? mappings[mappings.length - 1] : undefined;
|
|
45
|
+
if (lastMapping &&
|
|
46
|
+
lastMapping.generatedRange[1] === current.genOffset &&
|
|
47
|
+
lastMapping.sourceRange[1] === current.sourceOffset) {
|
|
48
|
+
lastMapping.generatedRange[1] = current.genOffset + length;
|
|
49
|
+
lastMapping.sourceRange[1] = current.sourceOffset + length;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Disable features inside script tags. This is a bit annoying to do, I wonder if maybe leaving script tags
|
|
53
|
+
// unmapped would be better.
|
|
54
|
+
const node = htmlDocument.findNodeAt(current.sourceOffset);
|
|
55
|
+
const rangeCapabilities = node.tag !== 'script'
|
|
56
|
+
? language_core_1.FileRangeCapabilities.full
|
|
57
|
+
: {
|
|
58
|
+
completion: false,
|
|
59
|
+
definition: false,
|
|
60
|
+
diagnostic: false,
|
|
61
|
+
displayWithLink: false,
|
|
62
|
+
hover: false,
|
|
63
|
+
references: false,
|
|
64
|
+
referencesCodeLens: false,
|
|
65
|
+
rename: false,
|
|
66
|
+
semanticTokens: false,
|
|
67
|
+
};
|
|
68
|
+
mappings.push({
|
|
69
|
+
sourceRange: [current.sourceOffset, current.sourceOffset + length],
|
|
70
|
+
generatedRange: [current.genOffset, current.genOffset + length],
|
|
71
|
+
data: rangeCapabilities,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
current = undefined;
|
|
76
|
+
}
|
|
77
|
+
if (segment[2] !== undefined && segment[3] !== undefined) {
|
|
78
|
+
const sourceOffset = sourcedDoc.offsetAt({ line: segment[2], character: segment[3] });
|
|
79
|
+
current = {
|
|
80
|
+
genOffset,
|
|
81
|
+
sourceOffset,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Ensure that `0:0` is mapped to `0:0` to make sure we properly handle "unmapped" lines
|
|
87
|
+
mappings.push({
|
|
88
|
+
sourceRange: [0, 0],
|
|
89
|
+
generatedRange: [0, 0],
|
|
90
|
+
data: {},
|
|
91
|
+
});
|
|
92
|
+
const ast = ts.createSourceFile('/a.tsx', tsx.code, ts.ScriptTarget.ESNext);
|
|
93
|
+
mappings.push({
|
|
94
|
+
sourceRange: [0, input.length],
|
|
95
|
+
generatedRange: [ast.statements[0].getStart(ast), tsx.code.length],
|
|
96
|
+
data: {},
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
fileName: fileName + '.tsx',
|
|
100
|
+
kind: language_core_1.FileKind.TypeScriptHostFile,
|
|
101
|
+
capabilities: {
|
|
102
|
+
codeAction: true,
|
|
103
|
+
documentFormatting: false,
|
|
104
|
+
diagnostic: true,
|
|
105
|
+
documentSymbol: true,
|
|
106
|
+
inlayHint: true,
|
|
107
|
+
foldingRange: true,
|
|
108
|
+
},
|
|
109
|
+
codegenStacks: [],
|
|
110
|
+
snapshot: {
|
|
111
|
+
getText: (start, end) => tsx.code.substring(start, end),
|
|
112
|
+
getLength: () => tsx.code.length,
|
|
113
|
+
getChangeRange: () => undefined,
|
|
114
|
+
},
|
|
115
|
+
mappings: mappings,
|
|
116
|
+
embeddedFiles: [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=astro2tsx.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DiagnosticMessage, ParseResult } from '@astrojs/compiler/types';
|
|
2
|
+
import { FileCapabilities, FileKind, type Language, type VirtualFile } from '@volar/language-core';
|
|
3
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
+
import { FrontmatterStatus } from './parseAstro';
|
|
6
|
+
import type { AstroInstall } from './utils';
|
|
7
|
+
export declare function getLanguageModule(astroInstall: AstroInstall | undefined, ts: typeof import('typescript/lib/tsserverlibrary.js')): Language<AstroFile>;
|
|
8
|
+
export declare class AstroFile implements VirtualFile {
|
|
9
|
+
sourceFileName: string;
|
|
10
|
+
snapshot: ts.IScriptSnapshot;
|
|
11
|
+
private readonly ts;
|
|
12
|
+
kind: FileKind;
|
|
13
|
+
capabilities: FileCapabilities;
|
|
14
|
+
fileName: string;
|
|
15
|
+
mappings: VirtualFile['mappings'];
|
|
16
|
+
embeddedFiles: VirtualFile['embeddedFiles'];
|
|
17
|
+
astroMeta: ParseResult & {
|
|
18
|
+
frontmatter: FrontmatterStatus;
|
|
19
|
+
};
|
|
20
|
+
compilerDiagnostics: DiagnosticMessage[];
|
|
21
|
+
htmlDocument: HTMLDocument;
|
|
22
|
+
scriptFiles: string[];
|
|
23
|
+
codegenStacks: never[];
|
|
24
|
+
constructor(sourceFileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript/lib/tsserverlibrary.js'));
|
|
25
|
+
get hasCompilationErrors(): boolean;
|
|
26
|
+
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
27
|
+
onSnapshotUpdated(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.AstroFile = exports.getLanguageModule = void 0;
|
|
27
|
+
const language_core_1 = require("@volar/language-core");
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
29
|
+
const astro2tsx_1 = require("./astro2tsx");
|
|
30
|
+
const parseAstro_1 = require("./parseAstro");
|
|
31
|
+
const parseCSS_1 = require("./parseCSS");
|
|
32
|
+
const parseHTML_1 = require("./parseHTML");
|
|
33
|
+
const parseJS_js_1 = require("./parseJS.js");
|
|
34
|
+
function getLanguageModule(astroInstall, ts) {
|
|
35
|
+
return {
|
|
36
|
+
createVirtualFile(fileName, snapshot) {
|
|
37
|
+
if (fileName.endsWith('.astro')) {
|
|
38
|
+
return new AstroFile(fileName, snapshot, ts);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
updateVirtualFile(astroFile, snapshot) {
|
|
42
|
+
astroFile.update(snapshot);
|
|
43
|
+
},
|
|
44
|
+
resolveHost(host) {
|
|
45
|
+
return {
|
|
46
|
+
...host,
|
|
47
|
+
getScriptFileNames() {
|
|
48
|
+
const fileNames = host.getScriptFileNames();
|
|
49
|
+
return [
|
|
50
|
+
...fileNames,
|
|
51
|
+
...(astroInstall
|
|
52
|
+
? ['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath)))
|
|
53
|
+
: []),
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
getCompilationSettings() {
|
|
57
|
+
const baseCompilationSettings = host.getCompilationSettings();
|
|
58
|
+
return {
|
|
59
|
+
...baseCompilationSettings,
|
|
60
|
+
module: ts.ModuleKind.ESNext ?? 99,
|
|
61
|
+
target: ts.ScriptTarget.ESNext ?? 99,
|
|
62
|
+
jsx: ts.JsxEmit.Preserve ?? 1,
|
|
63
|
+
jsxImportSource: undefined,
|
|
64
|
+
jsxFactory: 'astroHTML',
|
|
65
|
+
resolveJsonModule: true,
|
|
66
|
+
allowJs: true,
|
|
67
|
+
isolatedModules: true,
|
|
68
|
+
moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
|
|
69
|
+
!baseCompilationSettings.moduleResolution
|
|
70
|
+
? ts.ModuleResolutionKind.Node10
|
|
71
|
+
: baseCompilationSettings.moduleResolution,
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.getLanguageModule = getLanguageModule;
|
|
79
|
+
class AstroFile {
|
|
80
|
+
constructor(sourceFileName, snapshot, ts) {
|
|
81
|
+
this.sourceFileName = sourceFileName;
|
|
82
|
+
this.snapshot = snapshot;
|
|
83
|
+
this.ts = ts;
|
|
84
|
+
this.kind = language_core_1.FileKind.TextFile;
|
|
85
|
+
this.capabilities = language_core_1.FileCapabilities.full;
|
|
86
|
+
this.codegenStacks = [];
|
|
87
|
+
this.fileName = sourceFileName;
|
|
88
|
+
this.onSnapshotUpdated();
|
|
89
|
+
}
|
|
90
|
+
get hasCompilationErrors() {
|
|
91
|
+
return this.compilerDiagnostics.filter((diag) => diag.severity === 1).length > 0;
|
|
92
|
+
}
|
|
93
|
+
update(newSnapshot) {
|
|
94
|
+
this.snapshot = newSnapshot;
|
|
95
|
+
this.onSnapshotUpdated();
|
|
96
|
+
}
|
|
97
|
+
onSnapshotUpdated() {
|
|
98
|
+
this.mappings = [
|
|
99
|
+
{
|
|
100
|
+
sourceRange: [0, this.snapshot.getLength()],
|
|
101
|
+
generatedRange: [0, this.snapshot.getLength()],
|
|
102
|
+
data: language_core_1.FileRangeCapabilities.full,
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
this.astroMeta = (0, parseAstro_1.getAstroMetadata)(this.snapshot.getText(0, this.snapshot.getLength()));
|
|
106
|
+
const { htmlDocument, virtualFile: htmlVirtualFile } = (0, parseHTML_1.parseHTML)(this.fileName, this.snapshot, this.astroMeta.frontmatter.status === 'closed'
|
|
107
|
+
? this.astroMeta.frontmatter.position.end.offset
|
|
108
|
+
: 0);
|
|
109
|
+
this.htmlDocument = htmlDocument;
|
|
110
|
+
const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.fileName, this.snapshot, htmlDocument, this.astroMeta.ast);
|
|
111
|
+
this.scriptFiles = scriptTags.map((scriptTag) => scriptTag.fileName);
|
|
112
|
+
htmlVirtualFile.embeddedFiles.push(...(0, parseCSS_1.extractStylesheets)(this.fileName, this.snapshot, htmlDocument, this.astroMeta.ast), ...scriptTags);
|
|
113
|
+
this.embeddedFiles = [];
|
|
114
|
+
this.embeddedFiles.push(htmlVirtualFile);
|
|
115
|
+
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, this.ts, htmlDocument);
|
|
116
|
+
this.compilerDiagnostics = tsx.diagnostics;
|
|
117
|
+
this.embeddedFiles.push(tsx.virtualFile);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.AstroFile = AstroFile;
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ParseResult, Point } from '@astrojs/compiler/types';
|
|
2
|
+
type AstroMetadata = ParseResult & {
|
|
3
|
+
frontmatter: FrontmatterStatus;
|
|
4
|
+
};
|
|
5
|
+
export declare function getAstroMetadata(input: string, position?: boolean): AstroMetadata;
|
|
6
|
+
interface FrontmatterOpen {
|
|
7
|
+
status: 'open';
|
|
8
|
+
position: {
|
|
9
|
+
start: Point;
|
|
10
|
+
end: undefined;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface FrontmatterClosed {
|
|
14
|
+
status: 'closed';
|
|
15
|
+
position: {
|
|
16
|
+
start: Point;
|
|
17
|
+
end: Point;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface FrontmatterNull {
|
|
21
|
+
status: 'doesnt-exist';
|
|
22
|
+
position: undefined;
|
|
23
|
+
}
|
|
24
|
+
export type FrontmatterStatus = FrontmatterOpen | FrontmatterClosed | FrontmatterNull;
|
|
25
|
+
export declare function getFrontmatterStatus(ast: ParseResult['ast']): FrontmatterStatus;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFrontmatterStatus = exports.getAstroMetadata = void 0;
|
|
4
|
+
const sync_1 = require("@astrojs/compiler/sync");
|
|
5
|
+
function getAstroMetadata(input, position = true) {
|
|
6
|
+
const parseResult = (0, sync_1.parse)(input, { position: position });
|
|
7
|
+
return {
|
|
8
|
+
...parseResult,
|
|
9
|
+
frontmatter: getFrontmatterStatus(parseResult.ast),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.getAstroMetadata = getAstroMetadata;
|
|
13
|
+
function getFrontmatterStatus(ast) {
|
|
14
|
+
if (!ast.children || (ast.children && ast.children.length === 0)) {
|
|
15
|
+
return {
|
|
16
|
+
status: 'doesnt-exist',
|
|
17
|
+
position: undefined,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (ast.children[0].type === 'frontmatter') {
|
|
21
|
+
const frontmatter = ast.children[0];
|
|
22
|
+
if (frontmatter.position) {
|
|
23
|
+
if (frontmatter.position.end) {
|
|
24
|
+
return {
|
|
25
|
+
status: 'closed',
|
|
26
|
+
position: {
|
|
27
|
+
start: frontmatter.position.start,
|
|
28
|
+
end: frontmatter.position.end,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
status: 'open',
|
|
34
|
+
position: {
|
|
35
|
+
start: frontmatter.position.start,
|
|
36
|
+
end: undefined,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: 'doesnt-exist',
|
|
43
|
+
position: undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.getFrontmatterStatus = getFrontmatterStatus;
|
|
47
|
+
//# sourceMappingURL=parseAstro.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ParseResult } from '@astrojs/compiler/types';
|
|
2
|
+
import { VirtualFile } from '@volar/language-core';
|
|
3
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
+
import type { AttributeNodeWithPosition } from '../utils.js';
|
|
6
|
+
export declare function extractStylesheets(fileName: string, snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualFile[];
|
|
7
|
+
export declare function collectClassesAndIdsFromDocument(ast: ParseResult['ast']): string[];
|
|
8
|
+
export declare function findInlineStyles(ast: ParseResult['ast']): AttributeNodeWithPosition[];
|