@astrojs/language-server 1.0.5 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -5
- package/bin/nodeServer.js +7 -3
- package/dist/core/astro2tsx.d.ts +6 -0
- package/dist/core/astro2tsx.js +119 -0
- package/dist/core/compilerUtils.d.ts +27 -0
- package/dist/core/compilerUtils.js +52 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +119 -0
- package/dist/core/parseAstro.d.ts +27 -0
- package/dist/core/parseAstro.js +47 -0
- package/dist/core/parseCSS.d.ts +7 -0
- package/dist/core/parseCSS.js +116 -0
- package/dist/core/parseHTML.d.ts +7 -0
- package/dist/core/parseHTML.js +113 -0
- package/dist/core/parseJS.d.ts +7 -0
- package/dist/core/parseJS.js +236 -0
- package/dist/core/svelte.d.ts +18 -0
- package/dist/core/svelte.js +45 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/core/utils.js +138 -0
- package/dist/core/vue.d.ts +18 -0
- package/dist/core/vue.js +45 -0
- package/dist/importPackage.d.ts +1 -1
- package/dist/importPackage.js +4 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +26 -6
- package/dist/languageServerPlugin.d.ts +2 -0
- package/dist/languageServerPlugin.js +76 -0
- package/dist/nodeServer.js +6 -0
- package/dist/plugins/astro.d.ts +3 -0
- package/dist/plugins/astro.js +123 -0
- package/dist/plugins/{html/features/astro-attributes.js → html-data.js} +1 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +33 -0
- package/dist/plugins/typescript/codeActions.d.ts +4 -0
- package/dist/plugins/typescript/codeActions.js +49 -0
- package/dist/plugins/typescript/completions.d.ts +3 -0
- package/dist/plugins/typescript/completions.js +81 -0
- package/dist/plugins/typescript/diagnostics.d.ts +12 -0
- package/dist/plugins/typescript/diagnostics.js +99 -0
- package/dist/plugins/typescript/index.d.ts +3 -0
- package/dist/plugins/typescript/index.js +57 -0
- package/dist/utils.d.ts +19 -69
- package/dist/utils.js +66 -239
- package/package.json +37 -38
- package/types/astro-jsx.d.ts +49 -5
- package/bin/browserServer.js +0 -3
- package/dist/browser.js +0 -15
- package/dist/check.d.ts +0 -23
- package/dist/check.js +0 -60
- package/dist/core/DiagnosticsManager.d.ts +0 -13
- package/dist/core/DiagnosticsManager.js +0 -29
- package/dist/core/config/ConfigManager.d.ts +0 -43
- package/dist/core/config/ConfigManager.js +0 -226
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -18
- package/dist/core/config/interfaces.d.ts +0 -77
- package/dist/core/config/interfaces.js +0 -2
- package/dist/core/documents/AstroDocument.d.ts +0 -19
- package/dist/core/documents/AstroDocument.js +0 -43
- package/dist/core/documents/DocumentBase.d.ts +0 -68
- package/dist/core/documents/DocumentBase.js +0 -75
- package/dist/core/documents/DocumentManager.d.ts +0 -23
- package/dist/core/documents/DocumentManager.js +0 -100
- package/dist/core/documents/DocumentMapper.d.ts +0 -94
- package/dist/core/documents/DocumentMapper.js +0 -264
- package/dist/core/documents/index.d.ts +0 -5
- package/dist/core/documents/index.js +0 -21
- package/dist/core/documents/parseAstro.d.ts +0 -15
- package/dist/core/documents/parseAstro.js +0 -63
- package/dist/core/documents/parseHtml.d.ts +0 -13
- package/dist/core/documents/parseHtml.js +0 -126
- package/dist/core/documents/utils.d.ts +0 -63
- package/dist/core/documents/utils.js +0 -223
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -43
- package/dist/plugins/PluginHost.d.ts +0 -42
- package/dist/plugins/PluginHost.js +0 -206
- package/dist/plugins/astro/AstroPlugin.d.ts +0 -17
- package/dist/plugins/astro/AstroPlugin.js +0 -90
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +0 -17
- package/dist/plugins/astro/features/CompletionsProvider.js +0 -242
- package/dist/plugins/astro/features/DiagnosticsProvider.d.ts +0 -10
- package/dist/plugins/astro/features/DiagnosticsProvider.js +0 -23
- package/dist/plugins/css/CSSDocument.d.ts +0 -45
- package/dist/plugins/css/CSSDocument.js +0 -68
- package/dist/plugins/css/CSSPlugin.d.ts +0 -39
- package/dist/plugins/css/CSSPlugin.js +0 -274
- package/dist/plugins/css/StyleAttributeDocument.d.ts +0 -40
- package/dist/plugins/css/StyleAttributeDocument.js +0 -64
- package/dist/plugins/css/features/astro-selectors.d.ts +0 -2
- package/dist/plugins/css/features/astro-selectors.js +0 -15
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +0 -19
- package/dist/plugins/css/features/getIdClassCompletions.js +0 -57
- package/dist/plugins/css/language-service.d.ts +0 -3
- package/dist/plugins/css/language-service.js +0 -47
- package/dist/plugins/html/HTMLPlugin.d.ts +0 -33
- package/dist/plugins/html/HTMLPlugin.js +0 -198
- package/dist/plugins/html/utils.d.ts +0 -6
- package/dist/plugins/html/utils.js +0 -11
- package/dist/plugins/index.d.ts +0 -6
- package/dist/plugins/index.js +0 -22
- package/dist/plugins/interfaces.d.ts +0 -101
- package/dist/plugins/interfaces.js +0 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +0 -47
- package/dist/plugins/typescript/LanguageServiceManager.js +0 -97
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +0 -54
- package/dist/plugins/typescript/TypeScriptPlugin.js +0 -152
- package/dist/plugins/typescript/astro-sys.d.ts +0 -8
- package/dist/plugins/typescript/astro-sys.js +0 -46
- package/dist/plugins/typescript/astro2tsx.d.ts +0 -2
- package/dist/plugins/typescript/astro2tsx.js +0 -26
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +0 -17
- package/dist/plugins/typescript/features/CodeActionsProvider.js +0 -212
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +0 -31
- package/dist/plugins/typescript/features/CompletionsProvider.js +0 -294
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/DefinitionsProvider.js +0 -58
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -25
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +0 -249
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +0 -67
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/FileReferencesProvider.js +0 -27
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +0 -12
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +0 -71
- package/dist/plugins/typescript/features/HoverProvider.d.ts +0 -10
- package/dist/plugins/typescript/features/HoverProvider.js +0 -50
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ImplementationsProvider.js +0 -53
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/InlayHintsProvider.js +0 -30
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/ReferencesProvider.js +0 -55
- package/dist/plugins/typescript/features/RenameProvider.d.ts +0 -13
- package/dist/plugins/typescript/features/RenameProvider.js +0 -60
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +0 -16
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +0 -75
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +0 -22
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +0 -111
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +0 -9
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +0 -54
- package/dist/plugins/typescript/features/utils.d.ts +0 -14
- package/dist/plugins/typescript/features/utils.js +0 -48
- package/dist/plugins/typescript/language-service.d.ts +0 -42
- package/dist/plugins/typescript/language-service.js +0 -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/bin/nodeServer.js
CHANGED
|
@@ -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/types.js").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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: Upstream this
|
|
3
|
+
*/
|
|
4
|
+
import type { AttributeNode, CommentNode, ComponentNode, CustomElementNode, DoctypeNode, ElementNode, ExpressionNode, FragmentNode, FrontmatterNode, LiteralNode, Node, ParentNode, Point, Position, RootNode, TagLikeNode, TextNode } from '@astrojs/compiler/types';
|
|
5
|
+
export declare const is: {
|
|
6
|
+
parent(node: Node): node is ParentNode;
|
|
7
|
+
literal(node: Node): node is LiteralNode;
|
|
8
|
+
tag(node: Node): node is TagLikeNode;
|
|
9
|
+
whitespace(node: Node): node is TextNode;
|
|
10
|
+
root: (node: Node) => node is RootNode;
|
|
11
|
+
element: (node: Node) => node is ElementNode;
|
|
12
|
+
customElement: (node: Node) => node is CustomElementNode;
|
|
13
|
+
component: (node: Node) => node is ComponentNode;
|
|
14
|
+
fragment: (node: Node) => node is FragmentNode;
|
|
15
|
+
expression: (node: Node) => node is ExpressionNode;
|
|
16
|
+
text: (node: Node) => node is TextNode;
|
|
17
|
+
doctype: (node: Node) => node is DoctypeNode;
|
|
18
|
+
comment: (node: Node) => node is CommentNode;
|
|
19
|
+
frontmatter: (node: Node) => node is FrontmatterNode;
|
|
20
|
+
};
|
|
21
|
+
export declare function createCompilerPosition(start: Point, end: Point): Position;
|
|
22
|
+
export declare function createCompilerPoint(line: number, column: number, offset: number): Point;
|
|
23
|
+
type WithRequired<T, K extends keyof T> = T & {
|
|
24
|
+
[P in K]-?: T[P];
|
|
25
|
+
};
|
|
26
|
+
export type AttributeNodeWithPosition = WithRequired<AttributeNode, 'position'>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TODO: Upstream this
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCompilerPoint = exports.createCompilerPosition = exports.is = void 0;
|
|
7
|
+
function guard(type) {
|
|
8
|
+
return (node) => node.type === type;
|
|
9
|
+
}
|
|
10
|
+
exports.is = {
|
|
11
|
+
parent(node) {
|
|
12
|
+
return Array.isArray(node.children);
|
|
13
|
+
},
|
|
14
|
+
literal(node) {
|
|
15
|
+
return typeof node.value === 'string';
|
|
16
|
+
},
|
|
17
|
+
tag(node) {
|
|
18
|
+
return (node.type === 'element' ||
|
|
19
|
+
node.type === 'custom-element' ||
|
|
20
|
+
node.type === 'component' ||
|
|
21
|
+
node.type === 'fragment');
|
|
22
|
+
},
|
|
23
|
+
whitespace(node) {
|
|
24
|
+
return node.type === 'text' && node.value.trim().length === 0;
|
|
25
|
+
},
|
|
26
|
+
root: guard('root'),
|
|
27
|
+
element: guard('element'),
|
|
28
|
+
customElement: guard('custom-element'),
|
|
29
|
+
component: guard('component'),
|
|
30
|
+
fragment: guard('fragment'),
|
|
31
|
+
expression: guard('expression'),
|
|
32
|
+
text: guard('text'),
|
|
33
|
+
doctype: guard('doctype'),
|
|
34
|
+
comment: guard('comment'),
|
|
35
|
+
frontmatter: guard('frontmatter'),
|
|
36
|
+
};
|
|
37
|
+
function createCompilerPosition(start, end) {
|
|
38
|
+
return {
|
|
39
|
+
start,
|
|
40
|
+
end,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.createCompilerPosition = createCompilerPosition;
|
|
44
|
+
function createCompilerPoint(line, column, offset) {
|
|
45
|
+
return {
|
|
46
|
+
line,
|
|
47
|
+
column,
|
|
48
|
+
offset,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.createCompilerPoint = createCompilerPoint;
|
|
52
|
+
//# sourceMappingURL=compilerUtils.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
codegenStacks: never[];
|
|
23
|
+
constructor(sourceFileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript/lib/tsserverlibrary.js'));
|
|
24
|
+
get hasCompilationErrors(): boolean;
|
|
25
|
+
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
26
|
+
onSnapshotUpdated(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
...(astroInstall
|
|
51
|
+
? ['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath)))
|
|
52
|
+
: []),
|
|
53
|
+
...fileNames,
|
|
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
|
+
htmlVirtualFile.embeddedFiles.push(...(0, parseCSS_1.extractStylesheets)(this.fileName, this.snapshot, htmlDocument, this.astroMeta.ast), ...(0, parseJS_js_1.extractScriptTags)(this.fileName, this.snapshot, htmlDocument, this.astroMeta.ast));
|
|
111
|
+
this.embeddedFiles = [];
|
|
112
|
+
this.embeddedFiles.push(htmlVirtualFile);
|
|
113
|
+
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, this.ts, htmlDocument);
|
|
114
|
+
this.compilerDiagnostics = tsx.diagnostics;
|
|
115
|
+
this.embeddedFiles.push(tsx.virtualFile);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.AstroFile = AstroFile;
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Point } from '@astrojs/compiler/shared/ast';
|
|
2
|
+
import type { ParseResult } from '@astrojs/compiler/types';
|
|
3
|
+
type AstroMetadata = ParseResult & {
|
|
4
|
+
frontmatter: FrontmatterStatus;
|
|
5
|
+
};
|
|
6
|
+
export declare function getAstroMetadata(input: string, position?: boolean): AstroMetadata;
|
|
7
|
+
interface FrontmatterOpen {
|
|
8
|
+
status: 'open';
|
|
9
|
+
position: {
|
|
10
|
+
start: Point;
|
|
11
|
+
end: undefined;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface FrontmatterClosed {
|
|
15
|
+
status: 'closed';
|
|
16
|
+
position: {
|
|
17
|
+
start: Point;
|
|
18
|
+
end: Point;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface FrontmatterNull {
|
|
22
|
+
status: 'doesnt-exist';
|
|
23
|
+
position: undefined;
|
|
24
|
+
}
|
|
25
|
+
export type FrontmatterStatus = FrontmatterOpen | FrontmatterClosed | FrontmatterNull;
|
|
26
|
+
export declare function getFrontmatterStatus(ast: ParseResult['ast']): FrontmatterStatus;
|
|
27
|
+
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,7 @@
|
|
|
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 { AttributeNodeWithPosition } from './compilerUtils.js';
|
|
6
|
+
export declare function extractStylesheets(fileName: string, snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualFile[];
|
|
7
|
+
export declare function findInlineStyles(ast: ParseResult['ast']): AttributeNodeWithPosition[];
|
|
@@ -0,0 +1,116 @@
|
|
|
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.findInlineStyles = exports.extractStylesheets = void 0;
|
|
27
|
+
const language_core_1 = require("@volar/language-core");
|
|
28
|
+
const SourceMap = __importStar(require("@volar/source-map"));
|
|
29
|
+
const muggle = __importStar(require("muggle-string"));
|
|
30
|
+
const compilerUtils_js_1 = require("./compilerUtils.js");
|
|
31
|
+
function extractStylesheets(fileName, snapshot, htmlDocument, ast) {
|
|
32
|
+
const embeddedCSSFiles = [];
|
|
33
|
+
for (const [index, root] of htmlDocument.roots.entries()) {
|
|
34
|
+
if (root.tag === 'style' && root.startTagEnd !== undefined && root.endTagStart !== undefined) {
|
|
35
|
+
const styleText = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
36
|
+
embeddedCSSFiles.push({
|
|
37
|
+
fileName: fileName + `.${index}.css`,
|
|
38
|
+
kind: language_core_1.FileKind.TextFile,
|
|
39
|
+
snapshot: {
|
|
40
|
+
getText: (start, end) => styleText.substring(start, end),
|
|
41
|
+
getLength: () => styleText.length,
|
|
42
|
+
getChangeRange: () => undefined,
|
|
43
|
+
},
|
|
44
|
+
codegenStacks: [],
|
|
45
|
+
mappings: [
|
|
46
|
+
{
|
|
47
|
+
sourceRange: [root.startTagEnd, root.endTagStart],
|
|
48
|
+
generatedRange: [0, styleText.length],
|
|
49
|
+
data: language_core_1.FileRangeCapabilities.full,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
capabilities: {
|
|
53
|
+
diagnostic: false,
|
|
54
|
+
documentSymbol: true,
|
|
55
|
+
foldingRange: true,
|
|
56
|
+
documentFormatting: false,
|
|
57
|
+
},
|
|
58
|
+
embeddedFiles: [],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const inlineStyles = findInlineStyles(ast);
|
|
63
|
+
if (inlineStyles.length > 0) {
|
|
64
|
+
const codes = [];
|
|
65
|
+
for (const inlineStyle of inlineStyles) {
|
|
66
|
+
codes.push('x { ');
|
|
67
|
+
codes.push([
|
|
68
|
+
inlineStyle.value,
|
|
69
|
+
undefined,
|
|
70
|
+
inlineStyle.position.start.offset + 'style="'.length,
|
|
71
|
+
language_core_1.FileRangeCapabilities.full,
|
|
72
|
+
]);
|
|
73
|
+
codes.push(' }\n');
|
|
74
|
+
}
|
|
75
|
+
const mappings = SourceMap.buildMappings(codes);
|
|
76
|
+
const text = muggle.toString(codes);
|
|
77
|
+
embeddedCSSFiles.push({
|
|
78
|
+
fileName: fileName + '.inline.css',
|
|
79
|
+
codegenStacks: [],
|
|
80
|
+
snapshot: {
|
|
81
|
+
getText: (start, end) => text.substring(start, end),
|
|
82
|
+
getLength: () => text.length,
|
|
83
|
+
getChangeRange: () => undefined,
|
|
84
|
+
},
|
|
85
|
+
capabilities: {},
|
|
86
|
+
embeddedFiles: [],
|
|
87
|
+
kind: language_core_1.FileKind.TextFile,
|
|
88
|
+
mappings,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return embeddedCSSFiles;
|
|
92
|
+
}
|
|
93
|
+
exports.extractStylesheets = extractStylesheets;
|
|
94
|
+
function findInlineStyles(ast) {
|
|
95
|
+
const styleAttrs = [];
|
|
96
|
+
// `@astrojs/compiler`'s `walk` method is async, so we can't use it here. Arf
|
|
97
|
+
function walkDown(parent) {
|
|
98
|
+
if (!parent.children)
|
|
99
|
+
return;
|
|
100
|
+
parent.children.forEach((child) => {
|
|
101
|
+
if (compilerUtils_js_1.is.element(child)) {
|
|
102
|
+
const styleAttribute = child.attributes.find((attr) => attr.name === 'style' && attr.kind === 'quoted');
|
|
103
|
+
if (styleAttribute && styleAttribute.position) {
|
|
104
|
+
styleAttrs.push(styleAttribute);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (compilerUtils_js_1.is.parent(child)) {
|
|
108
|
+
walkDown(child);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
walkDown(ast);
|
|
113
|
+
return styleAttrs;
|
|
114
|
+
}
|
|
115
|
+
exports.findInlineStyles = findInlineStyles;
|
|
116
|
+
//# sourceMappingURL=parseCSS.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VirtualFile } from '@volar/language-core';
|
|
2
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import * as html from 'vscode-html-languageservice';
|
|
4
|
+
export declare function parseHTML(fileName: string, snapshot: ts.IScriptSnapshot, frontmatterEnd: number): {
|
|
5
|
+
virtualFile: VirtualFile;
|
|
6
|
+
htmlDocument: html.HTMLDocument;
|
|
7
|
+
};
|