@astrojs/language-server 2.12.7 → 2.13.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/core/index.js +1 -1
- package/dist/core/parseCSS.d.ts +1 -1
- package/dist/core/parseCSS.js +28 -10
- package/dist/core/parseJS.js +37 -1
- package/dist/languageServerPlugin.js +1 -5
- package/dist/plugins/astro.js +6 -3
- package/package.json +2 -2
package/dist/core/index.js
CHANGED
|
@@ -152,7 +152,7 @@ class AstroVirtualCode {
|
|
|
152
152
|
: 0);
|
|
153
153
|
this.htmlDocument = htmlDocument;
|
|
154
154
|
htmlVirtualCode.embeddedCodes = [
|
|
155
|
-
(0, parseCSS_1.extractStylesheets)(tsx.ranges.styles),
|
|
155
|
+
...(0, parseCSS_1.extractStylesheets)(tsx.ranges.styles),
|
|
156
156
|
...(0, parseJS_js_1.extractScriptTags)(tsx.ranges.scripts),
|
|
157
157
|
];
|
|
158
158
|
this.astroMeta = { ...astroMetadata, tsxRanges: tsx.ranges };
|
package/dist/core/parseCSS.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TSXExtractedStyle } from '@astrojs/compiler/types';
|
|
2
2
|
import type { VirtualCode } from '@volar/language-core';
|
|
3
|
-
export declare function extractStylesheets(styles: TSXExtractedStyle[]): VirtualCode;
|
|
3
|
+
export declare function extractStylesheets(styles: TSXExtractedStyle[]): VirtualCode[];
|
package/dist/core/parseCSS.js
CHANGED
|
@@ -3,17 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.extractStylesheets = void 0;
|
|
4
4
|
const muggle_string_1 = require("muggle-string");
|
|
5
5
|
const buildMappings_js_1 = require("../buildMappings.js");
|
|
6
|
+
const SUPPORTED_LANGUAGES = ['css', 'scss', 'less'];
|
|
7
|
+
function isSupportedLanguage(lang) {
|
|
8
|
+
return SUPPORTED_LANGUAGES.includes(lang);
|
|
9
|
+
}
|
|
6
10
|
function extractStylesheets(styles) {
|
|
7
|
-
return
|
|
11
|
+
return mergeCSSContextsByLanguage(styles);
|
|
8
12
|
}
|
|
9
13
|
exports.extractStylesheets = extractStylesheets;
|
|
10
|
-
function
|
|
11
|
-
const codes =
|
|
14
|
+
function mergeCSSContextsByLanguage(inlineStyles) {
|
|
15
|
+
const codes = {
|
|
16
|
+
css: [],
|
|
17
|
+
scss: [],
|
|
18
|
+
less: [],
|
|
19
|
+
};
|
|
12
20
|
for (const cssContext of inlineStyles) {
|
|
21
|
+
const currentCode = isSupportedLanguage(cssContext.lang) ? codes[cssContext.lang] : codes.css;
|
|
13
22
|
const isStyleAttribute = cssContext.type === 'style-attribute';
|
|
14
23
|
if (isStyleAttribute)
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
currentCode.push('__ { ');
|
|
25
|
+
currentCode.push([
|
|
17
26
|
cssContext.content,
|
|
18
27
|
undefined,
|
|
19
28
|
cssContext.position.start,
|
|
@@ -27,13 +36,22 @@ function mergeCSSContexts(inlineStyles) {
|
|
|
27
36
|
},
|
|
28
37
|
]);
|
|
29
38
|
if (isStyleAttribute)
|
|
30
|
-
|
|
39
|
+
currentCode.push(' }\n');
|
|
31
40
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
41
|
+
let virtualCodes = [];
|
|
42
|
+
for (const lang of SUPPORTED_LANGUAGES) {
|
|
43
|
+
if (codes[lang].length) {
|
|
44
|
+
virtualCodes.push(createVirtualCodeForLanguage(codes[lang], lang));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return virtualCodes;
|
|
48
|
+
}
|
|
49
|
+
function createVirtualCodeForLanguage(code, lang) {
|
|
50
|
+
const mappings = (0, buildMappings_js_1.buildMappings)(code);
|
|
51
|
+
const text = (0, muggle_string_1.toString)(code);
|
|
34
52
|
return {
|
|
35
|
-
id:
|
|
36
|
-
languageId:
|
|
53
|
+
id: `style.${lang}`,
|
|
54
|
+
languageId: lang,
|
|
37
55
|
snapshot: {
|
|
38
56
|
getText: (start, end) => text.substring(start, end),
|
|
39
57
|
getLength: () => text.length,
|
package/dist/core/parseJS.js
CHANGED
|
@@ -9,13 +9,21 @@ function extractScriptTags(scripts) {
|
|
|
9
9
|
.filter((script) => script.type === 'module' || script.type === 'processed-module')
|
|
10
10
|
.map(moduleScriptToVirtualCode);
|
|
11
11
|
const inlineScripts = scripts
|
|
12
|
-
.filter((script) =>
|
|
12
|
+
.filter((script) =>
|
|
13
|
+
// TODO: Change this at some point so that unknown scripts are not included
|
|
14
|
+
// We can't guarantee that they are JavaScript, so we shouldn't treat them as such, even if it might work in some cases
|
|
15
|
+
// Perhaps we should make it so that the user has to specify the language of the script if it's not a known type (ex: lang="js"), not sure.
|
|
16
|
+
script.type === 'event-attribute' || script.type === 'inline' || script.type === 'unknown')
|
|
13
17
|
.sort((a, b) => a.position.start - b.position.start);
|
|
14
18
|
embeddedJSCodes.push(...moduleScripts);
|
|
15
19
|
const mergedJSContext = mergeJSContexts(inlineScripts);
|
|
16
20
|
if (mergedJSContext) {
|
|
17
21
|
embeddedJSCodes.push(mergedJSContext);
|
|
18
22
|
}
|
|
23
|
+
const JSONScripts = scripts
|
|
24
|
+
.filter((script) => script.type === 'json')
|
|
25
|
+
.map(jsonScriptToVirtualCode);
|
|
26
|
+
embeddedJSCodes.push(...JSONScripts);
|
|
19
27
|
return embeddedJSCodes;
|
|
20
28
|
}
|
|
21
29
|
exports.extractScriptTags = extractScriptTags;
|
|
@@ -52,6 +60,34 @@ function moduleScriptToVirtualCode(script, index) {
|
|
|
52
60
|
embeddedCodes: [],
|
|
53
61
|
};
|
|
54
62
|
}
|
|
63
|
+
function jsonScriptToVirtualCode(script, index) {
|
|
64
|
+
return {
|
|
65
|
+
id: `${index}.json`,
|
|
66
|
+
languageId: 'json',
|
|
67
|
+
snapshot: {
|
|
68
|
+
getText: (start, end) => script.content.substring(start, end),
|
|
69
|
+
getLength: () => script.content.length,
|
|
70
|
+
getChangeRange: () => undefined,
|
|
71
|
+
},
|
|
72
|
+
mappings: [
|
|
73
|
+
{
|
|
74
|
+
sourceOffsets: [script.position.start],
|
|
75
|
+
generatedOffsets: [0],
|
|
76
|
+
lengths: [script.content.length],
|
|
77
|
+
// TODO: Support JSON features
|
|
78
|
+
data: {
|
|
79
|
+
verification: false,
|
|
80
|
+
completion: false,
|
|
81
|
+
semantic: false,
|
|
82
|
+
navigation: false,
|
|
83
|
+
structure: false,
|
|
84
|
+
format: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
embeddedCodes: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
55
91
|
/**
|
|
56
92
|
* Merge all the inline and non-hoisted scripts into a single `.mjs` file
|
|
57
93
|
*/
|
|
@@ -44,11 +44,7 @@ function getLanguageServicePlugins(connection, ts) {
|
|
|
44
44
|
return [
|
|
45
45
|
(0, html_js_1.create)(),
|
|
46
46
|
(0, volar_service_css_1.create)(),
|
|
47
|
-
(0, volar_service_emmet_1.create)(
|
|
48
|
-
mappedLanguages: {
|
|
49
|
-
html: 'jsx',
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
47
|
+
(0, volar_service_emmet_1.create)(),
|
|
52
48
|
...(0, index_js_2.create)(ts),
|
|
53
49
|
(0, volar_service_typescript_twoslash_queries_1.create)(ts),
|
|
54
50
|
(0, index_js_1.create)(),
|
package/dist/plugins/astro.js
CHANGED
|
@@ -75,14 +75,17 @@ const create = (ts) => {
|
|
|
75
75
|
const tsProgram = languageService.getProgram();
|
|
76
76
|
if (!tsProgram)
|
|
77
77
|
return;
|
|
78
|
+
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
|
|
79
|
+
if (!decoded)
|
|
80
|
+
return;
|
|
78
81
|
const globcodeLens = [];
|
|
79
|
-
const sourceFile = tsProgram.getSourceFile(
|
|
82
|
+
const sourceFile = tsProgram.getSourceFile(decoded[0].fsPath);
|
|
80
83
|
function walk() {
|
|
81
84
|
return ts.forEachChild(sourceFile, function cb(node) {
|
|
82
85
|
if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
|
|
83
86
|
const globArgument = node.arguments.at(0);
|
|
84
|
-
if (globArgument) {
|
|
85
|
-
globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(uriConverter.asFileName(
|
|
87
|
+
if (globArgument && decoded) {
|
|
88
|
+
globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(uriConverter.asFileName(decoded[0])), document.positionAt(node.arguments.pos)));
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
return ts.forEachChild(node, cb);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"astro-ls": "./bin/nodeServer.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@astrojs/compiler": "^2.
|
|
23
|
+
"@astrojs/compiler": "^2.10.0",
|
|
24
24
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
25
25
|
"@volar/kit": "~2.4.0-alpha.15",
|
|
26
26
|
"@volar/language-core": "~2.4.0-alpha.15",
|