@astrojs/language-server 2.6.2 → 2.7.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/dist/check.d.ts +1 -2
- package/dist/check.js +10 -20
- package/dist/core/astro2tsx.d.ts +17 -9
- package/dist/core/astro2tsx.js +27 -41
- package/dist/core/index.d.ts +11 -13
- package/dist/core/index.js +102 -75
- package/dist/core/parseAstro.js +6 -1
- package/dist/core/parseCSS.d.ts +3 -3
- package/dist/core/parseCSS.js +35 -54
- package/dist/core/parseHTML.d.ts +4 -4
- package/dist/core/parseHTML.js +17 -16
- package/dist/core/parseJS.d.ts +3 -3
- package/dist/core/parseJS.js +34 -61
- package/dist/core/svelte.d.ts +10 -12
- package/dist/core/svelte.js +39 -16
- package/dist/core/utils.d.ts +3 -3
- package/dist/core/utils.js +21 -40
- package/dist/core/vue.d.ts +10 -12
- package/dist/core/vue.js +39 -16
- package/dist/languageServerPlugin.d.ts +3 -2
- package/dist/languageServerPlugin.js +103 -90
- package/dist/nodeServer.js +9 -1
- package/dist/plugins/astro.d.ts +2 -2
- package/dist/plugins/astro.js +63 -60
- package/dist/plugins/html-data.js +11 -1
- package/dist/plugins/html.d.ts +2 -2
- package/dist/plugins/html.js +37 -37
- package/dist/plugins/typescript/codeActions.js +5 -5
- package/dist/plugins/typescript/completions.js +5 -5
- package/dist/plugins/typescript/index.d.ts +2 -2
- package/dist/plugins/typescript/index.js +49 -53
- package/dist/plugins/typescript-addons/index.d.ts +2 -2
- package/dist/plugins/typescript-addons/index.js +32 -28
- package/dist/utils.d.ts +1 -1
- package/package.json +14 -15
package/dist/core/parseCSS.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.collectClassesAndIdsFromDocument = exports.extractStylesheets = void 0;
|
|
27
4
|
const utils_1 = require("@astrojs/compiler/utils");
|
|
28
5
|
const language_core_1 = require("@volar/language-core");
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
function extractStylesheets(fileName, snapshot, htmlDocument, ast) {
|
|
32
|
-
const embeddedCSSFiles = findEmbeddedStyles(fileName, snapshot, htmlDocument.roots);
|
|
6
|
+
function extractStylesheets(snapshot, htmlDocument, ast) {
|
|
7
|
+
const embeddedCSSCodes = findEmbeddedStyles(snapshot, htmlDocument.roots);
|
|
33
8
|
const inlineStyles = findInlineStyles(ast);
|
|
34
9
|
if (inlineStyles.length > 0) {
|
|
35
10
|
const codes = [];
|
|
@@ -39,35 +14,40 @@ function extractStylesheets(fileName, snapshot, htmlDocument, ast) {
|
|
|
39
14
|
inlineStyle.value,
|
|
40
15
|
undefined,
|
|
41
16
|
inlineStyle.position.start.offset + 'style="'.length,
|
|
42
|
-
|
|
17
|
+
{
|
|
18
|
+
completion: true,
|
|
19
|
+
verification: false,
|
|
20
|
+
semantic: true,
|
|
21
|
+
navigation: true,
|
|
22
|
+
structure: true,
|
|
23
|
+
format: false,
|
|
24
|
+
},
|
|
43
25
|
]);
|
|
44
26
|
codes.push(' }\n');
|
|
45
27
|
}
|
|
46
|
-
const mappings =
|
|
47
|
-
const text =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
28
|
+
const mappings = (0, language_core_1.buildMappings)(codes);
|
|
29
|
+
const text = (0, language_core_1.toString)(codes);
|
|
30
|
+
embeddedCSSCodes.push({
|
|
31
|
+
id: 'inline.css',
|
|
32
|
+
languageId: 'css',
|
|
51
33
|
snapshot: {
|
|
52
34
|
getText: (start, end) => text.substring(start, end),
|
|
53
35
|
getLength: () => text.length,
|
|
54
36
|
getChangeRange: () => undefined,
|
|
55
37
|
},
|
|
56
|
-
|
|
57
|
-
embeddedFiles: [],
|
|
58
|
-
kind: language_core_1.FileKind.TextFile,
|
|
38
|
+
embeddedCodes: [],
|
|
59
39
|
mappings,
|
|
60
40
|
});
|
|
61
41
|
}
|
|
62
|
-
return
|
|
42
|
+
return embeddedCSSCodes;
|
|
63
43
|
}
|
|
64
44
|
exports.extractStylesheets = extractStylesheets;
|
|
65
45
|
/**
|
|
66
46
|
* Find all embedded styles in a document.
|
|
67
47
|
* Embedded styles are styles that are defined in `<style>` tags.
|
|
68
48
|
*/
|
|
69
|
-
function findEmbeddedStyles(
|
|
70
|
-
const
|
|
49
|
+
function findEmbeddedStyles(snapshot, roots) {
|
|
50
|
+
const embeddedCSSCodes = [];
|
|
71
51
|
let cssIndex = 0;
|
|
72
52
|
getEmbeddedCSSInNodes(roots);
|
|
73
53
|
function getEmbeddedCSSInNodes(nodes) {
|
|
@@ -76,29 +56,30 @@ function findEmbeddedStyles(fileName, snapshot, roots) {
|
|
|
76
56
|
node.startTagEnd !== undefined &&
|
|
77
57
|
node.endTagStart !== undefined) {
|
|
78
58
|
const styleText = snapshot.getText(node.startTagEnd, node.endTagStart);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
59
|
+
embeddedCSSCodes.push({
|
|
60
|
+
id: `${cssIndex}.css`,
|
|
61
|
+
languageId: 'css',
|
|
82
62
|
snapshot: {
|
|
83
63
|
getText: (start, end) => styleText.substring(start, end),
|
|
84
64
|
getLength: () => styleText.length,
|
|
85
65
|
getChangeRange: () => undefined,
|
|
86
66
|
},
|
|
87
|
-
codegenStacks: [],
|
|
88
67
|
mappings: [
|
|
89
68
|
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
69
|
+
sourceOffsets: [node.startTagEnd],
|
|
70
|
+
generatedOffsets: [0],
|
|
71
|
+
lengths: [styleText.length],
|
|
72
|
+
data: {
|
|
73
|
+
verification: false,
|
|
74
|
+
completion: true,
|
|
75
|
+
semantic: true,
|
|
76
|
+
navigation: true,
|
|
77
|
+
structure: true,
|
|
78
|
+
format: false,
|
|
79
|
+
},
|
|
93
80
|
},
|
|
94
81
|
],
|
|
95
|
-
|
|
96
|
-
diagnostic: false,
|
|
97
|
-
documentSymbol: true,
|
|
98
|
-
foldingRange: true,
|
|
99
|
-
documentFormatting: false,
|
|
100
|
-
},
|
|
101
|
-
embeddedFiles: [],
|
|
82
|
+
embeddedCodes: [],
|
|
102
83
|
});
|
|
103
84
|
cssIndex++;
|
|
104
85
|
}
|
|
@@ -106,7 +87,7 @@ function findEmbeddedStyles(fileName, snapshot, roots) {
|
|
|
106
87
|
getEmbeddedCSSInNodes(node.children);
|
|
107
88
|
}
|
|
108
89
|
}
|
|
109
|
-
return
|
|
90
|
+
return embeddedCSSCodes;
|
|
110
91
|
}
|
|
111
92
|
/**
|
|
112
93
|
* Find all inline styles using the Astro AST
|
package/dist/core/parseHTML.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type ts from 'typescript
|
|
1
|
+
import type { VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type ts from 'typescript';
|
|
3
3
|
import * as html from 'vscode-html-languageservice';
|
|
4
|
-
export declare function parseHTML(
|
|
5
|
-
|
|
4
|
+
export declare function parseHTML(snapshot: ts.IScriptSnapshot, frontmatterEnd: number): {
|
|
5
|
+
virtualCode: VirtualCode;
|
|
6
6
|
htmlDocument: html.HTMLDocument;
|
|
7
7
|
};
|
|
8
8
|
/**
|
package/dist/core/parseHTML.js
CHANGED
|
@@ -24,14 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.preprocessHTML = exports.parseHTML = void 0;
|
|
27
|
-
const language_core_1 = require("@volar/language-core");
|
|
28
27
|
const html = __importStar(require("vscode-html-languageservice"));
|
|
29
28
|
const utils_1 = require("../plugins/utils");
|
|
30
29
|
const htmlLs = html.getLanguageService();
|
|
31
|
-
function parseHTML(
|
|
30
|
+
function parseHTML(snapshot, frontmatterEnd) {
|
|
32
31
|
const htmlContent = preprocessHTML(snapshot.getText(0, snapshot.getLength()), frontmatterEnd);
|
|
33
32
|
return {
|
|
34
|
-
|
|
33
|
+
virtualCode: getHTMLVirtualCode(htmlContent),
|
|
35
34
|
htmlDocument: getHTMLDocument(htmlContent),
|
|
36
35
|
};
|
|
37
36
|
}
|
|
@@ -83,29 +82,31 @@ function preprocessHTML(text, frontmatterEnd) {
|
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
exports.preprocessHTML = preprocessHTML;
|
|
86
|
-
function
|
|
85
|
+
function getHTMLVirtualCode(preprocessedHTML) {
|
|
87
86
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
id: `html`,
|
|
88
|
+
languageId: 'html',
|
|
90
89
|
snapshot: {
|
|
91
90
|
getText: (start, end) => preprocessedHTML.substring(start, end),
|
|
92
91
|
getLength: () => preprocessedHTML.length,
|
|
93
92
|
getChangeRange: () => undefined,
|
|
94
93
|
},
|
|
95
|
-
codegenStacks: [],
|
|
96
94
|
mappings: [
|
|
97
95
|
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
sourceOffsets: [0],
|
|
97
|
+
generatedOffsets: [0],
|
|
98
|
+
lengths: [preprocessedHTML.length],
|
|
99
|
+
data: {
|
|
100
|
+
verification: true,
|
|
101
|
+
completion: true,
|
|
102
|
+
semantic: true,
|
|
103
|
+
navigation: true,
|
|
104
|
+
structure: true,
|
|
105
|
+
format: false,
|
|
106
|
+
},
|
|
101
107
|
},
|
|
102
108
|
],
|
|
103
|
-
|
|
104
|
-
documentSymbol: true,
|
|
105
|
-
foldingRange: true,
|
|
106
|
-
documentFormatting: false,
|
|
107
|
-
},
|
|
108
|
-
embeddedFiles: [],
|
|
109
|
+
embeddedCodes: [],
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
function getHTMLDocument(preprocessedHTML) {
|
package/dist/core/parseJS.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ParseResult } from '@astrojs/compiler/types';
|
|
2
|
-
import {
|
|
3
|
-
import type ts from 'typescript
|
|
2
|
+
import { type VirtualCode } from '@volar/language-core';
|
|
3
|
+
import type ts from 'typescript';
|
|
4
4
|
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
-
export declare function extractScriptTags(
|
|
5
|
+
export declare function extractScriptTags(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
|
package/dist/core/parseJS.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.extractScriptTags = void 0;
|
|
27
4
|
const utils_1 = require("@astrojs/compiler/utils");
|
|
28
5
|
const language_core_1 = require("@volar/language-core");
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
function extractScriptTags(fileName, snapshot, htmlDocument, ast) {
|
|
32
|
-
const embeddedJSFiles = findModuleScripts(fileName, snapshot, htmlDocument.roots);
|
|
6
|
+
function extractScriptTags(snapshot, htmlDocument, ast) {
|
|
7
|
+
const embeddedJSCodes = findModuleScripts(snapshot, htmlDocument.roots);
|
|
33
8
|
const javascriptContexts = [
|
|
34
9
|
...findClassicScripts(htmlDocument, snapshot),
|
|
35
10
|
...findEventAttributes(ast),
|
|
@@ -37,9 +12,9 @@ function extractScriptTags(fileName, snapshot, htmlDocument, ast) {
|
|
|
37
12
|
if (javascriptContexts.length > 0) {
|
|
38
13
|
// classic scripts share the same scope
|
|
39
14
|
// merging them brings about redeclaration errors
|
|
40
|
-
|
|
15
|
+
embeddedJSCodes.push(mergeJSContexts(javascriptContexts));
|
|
41
16
|
}
|
|
42
|
-
return
|
|
17
|
+
return embeddedJSCodes;
|
|
43
18
|
}
|
|
44
19
|
exports.extractScriptTags = extractScriptTags;
|
|
45
20
|
function getScriptType(scriptTag) {
|
|
@@ -57,7 +32,7 @@ function getScriptType(scriptTag) {
|
|
|
57
32
|
* Isolated scripts are scripts that are hoisted by Astro and as such, are isolated from the rest of the code because of the implicit `type="module"`
|
|
58
33
|
* All the isolated scripts are passed to the TypeScript language server as separate `.mts` files.
|
|
59
34
|
*/
|
|
60
|
-
function findModuleScripts(
|
|
35
|
+
function findModuleScripts(snapshot, roots) {
|
|
61
36
|
const embeddedScripts = [];
|
|
62
37
|
let scriptIndex = 0;
|
|
63
38
|
getEmbeddedScriptsInNodes(roots);
|
|
@@ -69,31 +44,31 @@ function findModuleScripts(fileName, snapshot, roots) {
|
|
|
69
44
|
getScriptType(node) !== 'classic') {
|
|
70
45
|
const scriptText = snapshot.getText(node.startTagEnd, node.endTagStart);
|
|
71
46
|
const extension = getScriptType(node) === 'processed module' ? 'mts' : 'mjs';
|
|
47
|
+
const languageId = getScriptType(node) === 'processed module' ? 'typescript' : 'javascript';
|
|
72
48
|
embeddedScripts.push({
|
|
73
|
-
|
|
74
|
-
|
|
49
|
+
id: `${scriptIndex}.${extension}`,
|
|
50
|
+
languageId: languageId,
|
|
75
51
|
snapshot: {
|
|
76
52
|
getText: (start, end) => scriptText.substring(start, end),
|
|
77
53
|
getLength: () => scriptText.length,
|
|
78
54
|
getChangeRange: () => undefined,
|
|
79
55
|
},
|
|
80
|
-
codegenStacks: [],
|
|
81
56
|
mappings: [
|
|
82
57
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
sourceOffsets: [node.startTagEnd],
|
|
59
|
+
generatedOffsets: [0],
|
|
60
|
+
lengths: [scriptText.length],
|
|
61
|
+
data: {
|
|
62
|
+
verification: true,
|
|
63
|
+
completion: true,
|
|
64
|
+
semantic: true,
|
|
65
|
+
navigation: true,
|
|
66
|
+
structure: true,
|
|
67
|
+
format: false,
|
|
68
|
+
},
|
|
86
69
|
},
|
|
87
70
|
],
|
|
88
|
-
|
|
89
|
-
diagnostic: true,
|
|
90
|
-
codeAction: true,
|
|
91
|
-
inlayHint: true,
|
|
92
|
-
documentSymbol: true,
|
|
93
|
-
foldingRange: true,
|
|
94
|
-
documentFormatting: false,
|
|
95
|
-
},
|
|
96
|
-
embeddedFiles: [],
|
|
71
|
+
embeddedCodes: [],
|
|
97
72
|
});
|
|
98
73
|
scriptIndex++;
|
|
99
74
|
}
|
|
@@ -176,36 +151,34 @@ function findEventAttributes(ast) {
|
|
|
176
151
|
/**
|
|
177
152
|
* Merge all the inline and non-hoisted scripts into a single `.mjs` file
|
|
178
153
|
*/
|
|
179
|
-
function mergeJSContexts(
|
|
154
|
+
function mergeJSContexts(javascriptContexts) {
|
|
180
155
|
const codes = [];
|
|
181
156
|
for (const javascriptContext of javascriptContexts) {
|
|
182
157
|
codes.push([
|
|
183
158
|
javascriptContext.content,
|
|
184
159
|
undefined,
|
|
185
160
|
javascriptContext.startOffset,
|
|
186
|
-
|
|
161
|
+
{
|
|
162
|
+
verification: true,
|
|
163
|
+
completion: true,
|
|
164
|
+
semantic: true,
|
|
165
|
+
navigation: true,
|
|
166
|
+
structure: true,
|
|
167
|
+
format: false,
|
|
168
|
+
},
|
|
187
169
|
]);
|
|
188
170
|
}
|
|
189
|
-
const mappings =
|
|
190
|
-
const text =
|
|
171
|
+
const mappings = (0, language_core_1.buildMappings)(codes);
|
|
172
|
+
const text = (0, language_core_1.toString)(codes);
|
|
191
173
|
return {
|
|
192
|
-
|
|
193
|
-
|
|
174
|
+
id: 'inline.mjs',
|
|
175
|
+
languageId: 'javascript',
|
|
194
176
|
snapshot: {
|
|
195
177
|
getText: (start, end) => text.substring(start, end),
|
|
196
178
|
getLength: () => text.length,
|
|
197
179
|
getChangeRange: () => undefined,
|
|
198
180
|
},
|
|
199
|
-
|
|
200
|
-
codeAction: true,
|
|
201
|
-
diagnostic: true,
|
|
202
|
-
documentFormatting: false,
|
|
203
|
-
documentSymbol: true,
|
|
204
|
-
foldingRange: true,
|
|
205
|
-
inlayHint: true,
|
|
206
|
-
},
|
|
207
|
-
embeddedFiles: [],
|
|
208
|
-
kind: language_core_1.FileKind.TypeScriptHostFile,
|
|
181
|
+
embeddedCodes: [],
|
|
209
182
|
mappings,
|
|
210
183
|
};
|
|
211
184
|
}
|
package/dist/core/svelte.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare class SvelteFile implements VirtualFile {
|
|
6
|
-
sourceFileName: string;
|
|
7
|
-
snapshot: ts.IScriptSnapshot;
|
|
8
|
-
kind: FileKind;
|
|
9
|
-
capabilities: FileCapabilities;
|
|
1
|
+
import { type CodeInformation, type LanguagePlugin, type Mapping, type VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type ts from 'typescript';
|
|
3
|
+
export declare function getSvelteLanguageModule(): LanguagePlugin<SvelteVirtualCode>;
|
|
4
|
+
declare class SvelteVirtualCode implements VirtualCode {
|
|
10
5
|
fileName: string;
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
snapshot: ts.IScriptSnapshot;
|
|
7
|
+
id: string;
|
|
8
|
+
languageId: string;
|
|
9
|
+
mappings: Mapping<CodeInformation>[];
|
|
10
|
+
embeddedCodes: VirtualCode[];
|
|
13
11
|
codegenStacks: never[];
|
|
14
|
-
constructor(
|
|
12
|
+
constructor(fileName: string, snapshot: ts.IScriptSnapshot);
|
|
15
13
|
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
16
14
|
private onSnapshotUpdated;
|
|
17
15
|
}
|
package/dist/core/svelte.js
CHANGED
|
@@ -5,25 +5,40 @@ const language_core_1 = require("@volar/language-core");
|
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
function getSvelteLanguageModule() {
|
|
7
7
|
return {
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
8
|
+
createVirtualCode(fileId, languageId, snapshot) {
|
|
9
|
+
if (languageId === 'svelte') {
|
|
10
|
+
const fileName = fileId.includes('://') ? fileId.split('://')[1] : fileId;
|
|
11
|
+
return new SvelteVirtualCode(fileName, snapshot);
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
updateVirtualCode(_fileId, svelteCode, snapshot) {
|
|
15
|
+
svelteCode.update(snapshot);
|
|
16
|
+
return svelteCode;
|
|
17
|
+
},
|
|
18
|
+
typescript: {
|
|
19
|
+
extraFileExtensions: [{ extension: 'svelte', isMixedContent: true, scriptKind: 7 }],
|
|
20
|
+
getScript(svelteCode) {
|
|
21
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(svelteCode)) {
|
|
22
|
+
if (code.id === 'tsx') {
|
|
23
|
+
return {
|
|
24
|
+
code,
|
|
25
|
+
extension: '.tsx',
|
|
26
|
+
scriptKind: 4,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
15
31
|
},
|
|
16
32
|
};
|
|
17
33
|
}
|
|
18
34
|
exports.getSvelteLanguageModule = getSvelteLanguageModule;
|
|
19
|
-
class
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
35
|
+
class SvelteVirtualCode {
|
|
36
|
+
constructor(fileName, snapshot) {
|
|
37
|
+
this.fileName = fileName;
|
|
22
38
|
this.snapshot = snapshot;
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
39
|
+
this.id = 'root';
|
|
40
|
+
this.languageId = 'svelte';
|
|
25
41
|
this.codegenStacks = [];
|
|
26
|
-
this.fileName = sourceFileName;
|
|
27
42
|
this.onSnapshotUpdated();
|
|
28
43
|
}
|
|
29
44
|
update(newSnapshot) {
|
|
@@ -33,13 +48,21 @@ class SvelteFile {
|
|
|
33
48
|
onSnapshotUpdated() {
|
|
34
49
|
this.mappings = [
|
|
35
50
|
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
sourceOffsets: [0],
|
|
52
|
+
generatedOffsets: [0],
|
|
53
|
+
lengths: [this.snapshot.getLength()],
|
|
54
|
+
data: {
|
|
55
|
+
verification: true,
|
|
56
|
+
completion: true,
|
|
57
|
+
semantic: true,
|
|
58
|
+
navigation: true,
|
|
59
|
+
structure: true,
|
|
60
|
+
format: true,
|
|
61
|
+
},
|
|
39
62
|
},
|
|
40
63
|
];
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
64
|
+
this.embeddedCodes = [];
|
|
65
|
+
this.embeddedCodes.push((0, utils_js_1.framework2tsx)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'svelte'));
|
|
43
66
|
}
|
|
44
67
|
}
|
|
45
68
|
//# sourceMappingURL=svelte.js.map
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function framework2tsx(
|
|
1
|
+
import type { VirtualCode } from '@volar/language-core';
|
|
2
|
+
export declare function framework2tsx(filePath: string, sourceCode: string, framework: 'vue' | 'svelte'): VirtualCode;
|
|
3
3
|
export declare function classNameFromFilename(filename: string): string;
|
|
4
|
-
export declare function patchTSX(code: string,
|
|
4
|
+
export declare function patchTSX(code: string, filePath: string): string;
|
package/dist/core/utils.js
CHANGED
|
@@ -1,61 +1,42 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.patchTSX = exports.classNameFromFilename = exports.framework2tsx = void 0;
|
|
27
|
-
const language_core_1 = require("@volar/language-core");
|
|
28
|
-
const path = __importStar(require("node:path"));
|
|
29
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
30
5
|
const importPackage_1 = require("../importPackage");
|
|
31
|
-
function framework2tsx(
|
|
6
|
+
function framework2tsx(filePath, sourceCode, framework) {
|
|
32
7
|
const integrationEditorEntrypoint = framework === 'vue' ? (0, importPackage_1.importVueIntegration)(filePath) : (0, importPackage_1.importSvelteIntegration)(filePath);
|
|
33
8
|
if (!integrationEditorEntrypoint) {
|
|
34
9
|
const EMPTY_FILE = '';
|
|
35
|
-
return
|
|
10
|
+
return getVirtualCode(EMPTY_FILE);
|
|
36
11
|
}
|
|
37
12
|
const className = classNameFromFilename(filePath);
|
|
38
|
-
const tsx = patchTSX(integrationEditorEntrypoint.toTSX(sourceCode, className),
|
|
39
|
-
return
|
|
40
|
-
function
|
|
13
|
+
const tsx = patchTSX(integrationEditorEntrypoint.toTSX(sourceCode, className), filePath);
|
|
14
|
+
return getVirtualCode(tsx);
|
|
15
|
+
function getVirtualCode(content) {
|
|
41
16
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
kind: language_core_1.FileKind.TypeScriptHostFile,
|
|
17
|
+
id: 'tsx',
|
|
18
|
+
languageId: 'typescript',
|
|
45
19
|
snapshot: {
|
|
46
20
|
getText: (start, end) => content.substring(start, end),
|
|
47
21
|
getLength: () => content.length,
|
|
48
22
|
getChangeRange: () => undefined,
|
|
49
23
|
},
|
|
50
|
-
codegenStacks: [],
|
|
51
24
|
mappings: [
|
|
52
25
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
sourceOffsets: [0],
|
|
27
|
+
generatedOffsets: [0],
|
|
28
|
+
lengths: [content.length],
|
|
29
|
+
data: {
|
|
30
|
+
verification: true,
|
|
31
|
+
completion: true,
|
|
32
|
+
semantic: true,
|
|
33
|
+
navigation: true,
|
|
34
|
+
structure: true,
|
|
35
|
+
format: true,
|
|
36
|
+
},
|
|
56
37
|
},
|
|
57
38
|
],
|
|
58
|
-
|
|
39
|
+
embeddedCodes: [],
|
|
59
40
|
};
|
|
60
41
|
}
|
|
61
42
|
}
|
|
@@ -90,8 +71,8 @@ function classNameFromFilename(filename) {
|
|
|
90
71
|
}
|
|
91
72
|
exports.classNameFromFilename = classNameFromFilename;
|
|
92
73
|
// TODO: Patch the upstream packages with these changes
|
|
93
|
-
function patchTSX(code,
|
|
94
|
-
const basename =
|
|
74
|
+
function patchTSX(code, filePath) {
|
|
75
|
+
const basename = filePath.split('/').pop();
|
|
95
76
|
const isDynamic = basename.startsWith('[') && basename.endsWith(']');
|
|
96
77
|
return code.replace(/\b(\S*)__AstroComponent_/gm, (fullMatch, m1) => {
|
|
97
78
|
// If we don't have a match here, it usually means the file has a weird name that couldn't be expressed with valid identifier characters
|
package/dist/core/vue.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare class VueFile implements VirtualFile {
|
|
6
|
-
sourceFileName: string;
|
|
7
|
-
snapshot: ts.IScriptSnapshot;
|
|
8
|
-
kind: FileKind;
|
|
9
|
-
capabilities: FileCapabilities;
|
|
1
|
+
import { type CodeInformation, type LanguagePlugin, type Mapping, type VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type ts from 'typescript';
|
|
3
|
+
export declare function getVueLanguageModule(): LanguagePlugin<VueVirtualCode>;
|
|
4
|
+
declare class VueVirtualCode implements VirtualCode {
|
|
10
5
|
fileName: string;
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
snapshot: ts.IScriptSnapshot;
|
|
7
|
+
id: string;
|
|
8
|
+
languageId: string;
|
|
9
|
+
mappings: Mapping<CodeInformation>[];
|
|
10
|
+
embeddedCodes: VirtualCode[];
|
|
13
11
|
codegenStacks: never[];
|
|
14
|
-
constructor(
|
|
12
|
+
constructor(fileName: string, snapshot: ts.IScriptSnapshot);
|
|
15
13
|
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
16
14
|
private onSnapshotUpdated;
|
|
17
15
|
}
|