@astrojs/language-server 2.8.4 → 2.9.1
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.js +4 -2
- package/dist/core/index.js +12 -7
- package/dist/core/svelte.js +12 -21
- package/dist/core/utils.js +1 -15
- package/dist/core/vue.js +12 -21
- package/dist/languageServerPlugin.d.ts +3 -3
- package/dist/languageServerPlugin.js +41 -56
- package/dist/nodeServer.js +17 -1
- package/dist/plugins/astro.d.ts +2 -2
- package/dist/plugins/astro.js +10 -6
- package/dist/plugins/html.d.ts +2 -2
- package/dist/plugins/html.js +5 -4
- package/dist/plugins/typescript/codeActions.js +6 -4
- package/dist/plugins/typescript/completions.js +6 -4
- package/dist/plugins/typescript/index.d.ts +2 -2
- package/dist/plugins/typescript/index.js +6 -5
- package/dist/plugins/typescript-addons/index.d.ts +2 -2
- package/dist/plugins/typescript-addons/index.js +6 -5
- package/package.json +14 -14
package/dist/check.js
CHANGED
|
@@ -56,7 +56,9 @@ class AstroCheck {
|
|
|
56
56
|
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
57
57
|
*/
|
|
58
58
|
async lint({ fileNames = undefined, cancel = () => false, logErrors = undefined, }) {
|
|
59
|
-
let files = (fileNames !== undefined
|
|
59
|
+
let files = (fileNames !== undefined
|
|
60
|
+
? fileNames
|
|
61
|
+
: this.linter.language.typescript.projectHost.getScriptFileNames()).filter((file) => {
|
|
60
62
|
// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
|
|
61
63
|
// So we don't want to check them here
|
|
62
64
|
return !file.endsWith('.vue') && !file.endsWith('.svelte');
|
|
@@ -92,7 +94,7 @@ class AstroCheck {
|
|
|
92
94
|
if (logErrors !== undefined && errorText) {
|
|
93
95
|
console.info(errorText);
|
|
94
96
|
}
|
|
95
|
-
const fileSnapshot = this.linter.
|
|
97
|
+
const fileSnapshot = this.linter.language.typescript.projectHost.getScriptSnapshot(file);
|
|
96
98
|
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
|
|
97
99
|
result.fileResult.push({
|
|
98
100
|
errors: fileDiagnostics,
|
package/dist/core/index.js
CHANGED
|
@@ -35,21 +35,26 @@ const parseHTML_1 = require("./parseHTML");
|
|
|
35
35
|
const parseJS_js_1 = require("./parseJS.js");
|
|
36
36
|
function getLanguageModule(astroInstall, ts) {
|
|
37
37
|
return {
|
|
38
|
-
|
|
38
|
+
getLanguageId(scriptId) {
|
|
39
|
+
if (scriptId.endsWith('.astro')) {
|
|
40
|
+
return 'astro';
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
createVirtualCode(scriptId, languageId, snapshot) {
|
|
39
44
|
if (languageId === 'astro') {
|
|
40
|
-
const fileName =
|
|
41
|
-
? vscode_uri_1.URI.parse(
|
|
42
|
-
:
|
|
45
|
+
const fileName = scriptId.includes('://')
|
|
46
|
+
? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
|
|
47
|
+
: scriptId;
|
|
43
48
|
return new AstroVirtualCode(fileName, snapshot);
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
|
-
updateVirtualCode(
|
|
51
|
+
updateVirtualCode(_scriptId, astroCode, snapshot) {
|
|
47
52
|
astroCode.update(snapshot);
|
|
48
53
|
return astroCode;
|
|
49
54
|
},
|
|
50
55
|
typescript: {
|
|
51
56
|
extraFileExtensions: [{ extension: 'astro', isMixedContent: true, scriptKind: 7 }],
|
|
52
|
-
|
|
57
|
+
getServiceScript(astroCode) {
|
|
53
58
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(astroCode)) {
|
|
54
59
|
if (code.id === 'tsx') {
|
|
55
60
|
return {
|
|
@@ -61,7 +66,7 @@ function getLanguageModule(astroInstall, ts) {
|
|
|
61
66
|
}
|
|
62
67
|
return undefined;
|
|
63
68
|
},
|
|
64
|
-
|
|
69
|
+
getExtraServiceScripts(fileName, astroCode) {
|
|
65
70
|
const result = [];
|
|
66
71
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(astroCode)) {
|
|
67
72
|
if (code.id.endsWith('.mjs') || code.id.endsWith('.mts')) {
|
package/dist/core/svelte.js
CHANGED
|
@@ -6,21 +6,26 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function getSvelteLanguageModule() {
|
|
8
8
|
return {
|
|
9
|
-
|
|
9
|
+
getLanguageId(scriptId) {
|
|
10
|
+
if (scriptId.endsWith('.svelte')) {
|
|
11
|
+
return 'svelte';
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
createVirtualCode(scriptId, languageId, snapshot) {
|
|
10
15
|
if (languageId === 'svelte') {
|
|
11
|
-
const fileName =
|
|
12
|
-
? vscode_uri_1.URI.parse(
|
|
13
|
-
:
|
|
16
|
+
const fileName = scriptId.includes('://')
|
|
17
|
+
? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
|
|
18
|
+
: scriptId;
|
|
14
19
|
return new SvelteVirtualCode(fileName, snapshot);
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
|
-
updateVirtualCode(
|
|
22
|
+
updateVirtualCode(_scriptId, svelteCode, snapshot) {
|
|
18
23
|
svelteCode.update(snapshot);
|
|
19
24
|
return svelteCode;
|
|
20
25
|
},
|
|
21
26
|
typescript: {
|
|
22
27
|
extraFileExtensions: [{ extension: 'svelte', isMixedContent: true, scriptKind: 7 }],
|
|
23
|
-
|
|
28
|
+
getServiceScript(svelteCode) {
|
|
24
29
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(svelteCode)) {
|
|
25
30
|
if (code.id === 'tsx') {
|
|
26
31
|
return {
|
|
@@ -49,21 +54,7 @@ class SvelteVirtualCode {
|
|
|
49
54
|
this.onSnapshotUpdated();
|
|
50
55
|
}
|
|
51
56
|
onSnapshotUpdated() {
|
|
52
|
-
this.mappings = [
|
|
53
|
-
{
|
|
54
|
-
sourceOffsets: [0],
|
|
55
|
-
generatedOffsets: [0],
|
|
56
|
-
lengths: [this.snapshot.getLength()],
|
|
57
|
-
data: {
|
|
58
|
-
verification: true,
|
|
59
|
-
completion: true,
|
|
60
|
-
semantic: true,
|
|
61
|
-
navigation: true,
|
|
62
|
-
structure: true,
|
|
63
|
-
format: true,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
];
|
|
57
|
+
this.mappings = [];
|
|
67
58
|
this.embeddedCodes = [];
|
|
68
59
|
this.embeddedCodes.push((0, utils_js_1.framework2tsx)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'svelte'));
|
|
69
60
|
}
|
package/dist/core/utils.js
CHANGED
|
@@ -21,21 +21,7 @@ function framework2tsx(filePath, sourceCode, framework) {
|
|
|
21
21
|
getLength: () => content.length,
|
|
22
22
|
getChangeRange: () => undefined,
|
|
23
23
|
},
|
|
24
|
-
mappings: [
|
|
25
|
-
{
|
|
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
|
-
},
|
|
37
|
-
},
|
|
38
|
-
],
|
|
24
|
+
mappings: [],
|
|
39
25
|
embeddedCodes: [],
|
|
40
26
|
};
|
|
41
27
|
}
|
package/dist/core/vue.js
CHANGED
|
@@ -6,21 +6,26 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function getVueLanguageModule() {
|
|
8
8
|
return {
|
|
9
|
-
|
|
9
|
+
getLanguageId(scriptId) {
|
|
10
|
+
if (scriptId.endsWith('.vue')) {
|
|
11
|
+
return 'vue';
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
createVirtualCode(scriptId, languageId, snapshot) {
|
|
10
15
|
if (languageId === 'vue') {
|
|
11
|
-
const fileName =
|
|
12
|
-
? vscode_uri_1.URI.parse(
|
|
13
|
-
:
|
|
16
|
+
const fileName = scriptId.includes('://')
|
|
17
|
+
? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
|
|
18
|
+
: scriptId;
|
|
14
19
|
return new VueVirtualCode(fileName, snapshot);
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
|
-
updateVirtualCode(
|
|
22
|
+
updateVirtualCode(_scriptId, vueCode, snapshot) {
|
|
18
23
|
vueCode.update(snapshot);
|
|
19
24
|
return vueCode;
|
|
20
25
|
},
|
|
21
26
|
typescript: {
|
|
22
27
|
extraFileExtensions: [{ extension: 'vue', isMixedContent: true, scriptKind: 7 }],
|
|
23
|
-
|
|
28
|
+
getServiceScript(vueCode) {
|
|
24
29
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(vueCode)) {
|
|
25
30
|
if (code.id === 'tsx') {
|
|
26
31
|
return {
|
|
@@ -49,21 +54,7 @@ class VueVirtualCode {
|
|
|
49
54
|
this.onSnapshotUpdated();
|
|
50
55
|
}
|
|
51
56
|
onSnapshotUpdated() {
|
|
52
|
-
this.mappings = [
|
|
53
|
-
{
|
|
54
|
-
sourceOffsets: [0],
|
|
55
|
-
generatedOffsets: [0],
|
|
56
|
-
lengths: [this.snapshot.getLength()],
|
|
57
|
-
data: {
|
|
58
|
-
verification: true,
|
|
59
|
-
completion: true,
|
|
60
|
-
semantic: true,
|
|
61
|
-
navigation: true,
|
|
62
|
-
structure: true,
|
|
63
|
-
format: true,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
];
|
|
57
|
+
this.mappings = [];
|
|
67
58
|
this.embeddedCodes = [];
|
|
68
59
|
this.embeddedCodes.push((0, utils_js_1.framework2tsx)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'vue'));
|
|
69
60
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Connection } from '@volar/language-server/node';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { Connection, LanguagePlugin, ServiceEnvironment, VirtualCode } from '@volar/language-server/node';
|
|
2
|
+
export declare function getLanguagePlugins(connection: Connection, ts: typeof import('typescript'), serviceEnv: ServiceEnvironment, tsconfig: string | undefined): LanguagePlugin<VirtualCode>[];
|
|
3
|
+
export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript')): import("@volar/language-server/node").LanguageServicePlugin<any>[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLanguageServicePlugins = exports.getLanguagePlugins = void 0;
|
|
4
4
|
const node_1 = require("@volar/language-server/node");
|
|
5
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
6
6
|
const core_1 = require("./core");
|
|
@@ -17,59 +17,40 @@ const astro_js_1 = require("./plugins/astro.js");
|
|
|
17
17
|
const html_js_1 = require("./plugins/html.js");
|
|
18
18
|
const index_js_1 = require("./plugins/typescript-addons/index.js");
|
|
19
19
|
const index_js_2 = require("./plugins/typescript/index.js");
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const rootPath = projectContext.typescript.configFileName
|
|
55
|
-
? projectContext.typescript.configFileName.split('/').slice(0, -1).join('/')
|
|
56
|
-
: serviceEnv.typescript.uriToFileName(serviceEnv.workspaceFolder);
|
|
57
|
-
const nearestPackageJson = ts.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
|
|
58
|
-
const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
|
|
59
|
-
nearestPackageJson: nearestPackageJson,
|
|
60
|
-
readDirectory: ts.sys.readDirectory,
|
|
61
|
-
});
|
|
62
|
-
if (astroInstall === 'not-found') {
|
|
63
|
-
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
64
|
-
message: `Couldn't find Astro in workspace "${rootPath}". Experience might be degraded. For the best experience, please make sure Astro is installed into your project and restart the language server.`,
|
|
65
|
-
type: node_1.MessageType.Warning,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
languagePlugins.unshift((0, core_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
|
|
69
|
-
}
|
|
70
|
-
return languagePlugins;
|
|
71
|
-
},
|
|
72
|
-
};
|
|
20
|
+
function getLanguagePlugins(connection, ts, serviceEnv, tsconfig) {
|
|
21
|
+
const languagePlugins = [
|
|
22
|
+
(0, vue_js_1.getVueLanguageModule)(),
|
|
23
|
+
(0, svelte_js_1.getSvelteLanguageModule)(),
|
|
24
|
+
];
|
|
25
|
+
const rootPath = tsconfig
|
|
26
|
+
? tsconfig.split('/').slice(0, -1).join('/')
|
|
27
|
+
: serviceEnv.typescript.uriToFileName(serviceEnv.workspaceFolder);
|
|
28
|
+
const nearestPackageJson = ts.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
|
|
29
|
+
const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
|
|
30
|
+
nearestPackageJson: nearestPackageJson,
|
|
31
|
+
readDirectory: ts.sys.readDirectory,
|
|
32
|
+
});
|
|
33
|
+
if (astroInstall === 'not-found') {
|
|
34
|
+
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
35
|
+
message: `Couldn't find Astro in workspace "${rootPath}". Experience might be degraded. For the best experience, please make sure Astro is installed into your project and restart the language server.`,
|
|
36
|
+
type: node_1.MessageType.Warning,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
languagePlugins.unshift((0, core_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
|
|
40
|
+
return languagePlugins;
|
|
41
|
+
}
|
|
42
|
+
exports.getLanguagePlugins = getLanguagePlugins;
|
|
43
|
+
function getLanguageServicePlugins(connection, ts) {
|
|
44
|
+
return [
|
|
45
|
+
(0, html_js_1.create)(),
|
|
46
|
+
(0, volar_service_css_1.create)(),
|
|
47
|
+
(0, volar_service_emmet_1.create)(),
|
|
48
|
+
...(0, index_js_2.create)(ts),
|
|
49
|
+
(0, volar_service_typescript_twoslash_queries_1.create)(ts),
|
|
50
|
+
(0, index_js_1.create)(),
|
|
51
|
+
(0, astro_js_1.create)(ts),
|
|
52
|
+
getPrettierService(),
|
|
53
|
+
];
|
|
73
54
|
function getPrettierService() {
|
|
74
55
|
let prettier;
|
|
75
56
|
let prettierPluginPath;
|
|
@@ -91,7 +72,11 @@ function createServerOptions(connection, ts) {
|
|
|
91
72
|
}, {
|
|
92
73
|
documentSelector: ['astro'],
|
|
93
74
|
getFormattingOptions: async (prettierInstance, document, formatOptions, context) => {
|
|
94
|
-
const
|
|
75
|
+
const documentUri = context.decodeEmbeddedDocumentUri(document.uri)?.[0] ?? document.uri;
|
|
76
|
+
const filePath = vscode_uri_1.URI.parse(documentUri).fsPath;
|
|
77
|
+
if (!filePath) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
95
80
|
let configOptions = null;
|
|
96
81
|
try {
|
|
97
82
|
configOptions = await prettierInstance.resolveConfig(filePath, {
|
|
@@ -136,5 +121,5 @@ function createServerOptions(connection, ts) {
|
|
|
136
121
|
});
|
|
137
122
|
}
|
|
138
123
|
}
|
|
139
|
-
exports.
|
|
124
|
+
exports.getLanguageServicePlugins = getLanguageServicePlugins;
|
|
140
125
|
//# sourceMappingURL=languageServerPlugin.js.map
|
package/dist/nodeServer.js
CHANGED
|
@@ -11,9 +11,25 @@ connection.onInitialize((params) => {
|
|
|
11
11
|
throw new Error('The `typescript.tsdk` init option is required. It should point to a directory containing a `typescript.js` or `tsserverlibrary.js` file, such as `node_modules/typescript/lib`.');
|
|
12
12
|
}
|
|
13
13
|
const { typescript, diagnosticMessages } = (0, node_1.loadTsdkByPath)(tsdk, params.locale);
|
|
14
|
-
return server.initialize(params, (0, node_1.
|
|
14
|
+
return server.initialize(params, (0, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript), (0, node_1.createTypeScriptProjectProvider)(typescript, diagnosticMessages, (env, project) => (0, languageServerPlugin_js_1.getLanguagePlugins)(connection, typescript, env, project.configFileName)));
|
|
15
15
|
});
|
|
16
16
|
connection.onInitialized(() => {
|
|
17
17
|
server.initialized();
|
|
18
|
+
server.watchFiles([
|
|
19
|
+
`**/*.{${[
|
|
20
|
+
'js',
|
|
21
|
+
'cjs',
|
|
22
|
+
'mjs',
|
|
23
|
+
'ts',
|
|
24
|
+
'cts',
|
|
25
|
+
'mts',
|
|
26
|
+
'jsx',
|
|
27
|
+
'tsx',
|
|
28
|
+
'json',
|
|
29
|
+
'astro',
|
|
30
|
+
'vue',
|
|
31
|
+
'svelte',
|
|
32
|
+
].join(',')}}`,
|
|
33
|
+
]);
|
|
18
34
|
});
|
|
19
35
|
//# sourceMappingURL=nodeServer.js.map
|
package/dist/plugins/astro.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const create: (ts: typeof import('typescript')) =>
|
|
1
|
+
import { LanguageServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: (ts: typeof import('typescript')) => LanguageServicePlugin;
|
package/dist/plugins/astro.js
CHANGED
|
@@ -18,11 +18,13 @@ const create = (ts) => {
|
|
|
18
18
|
if (token.isCancellationRequested)
|
|
19
19
|
return null;
|
|
20
20
|
let items = [];
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
22
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
23
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
24
|
+
if (!(virtualCode instanceof index_js_1.AstroVirtualCode))
|
|
23
25
|
return;
|
|
24
26
|
if (completionContext.triggerCharacter === '-') {
|
|
25
|
-
const frontmatterCompletion = getFrontmatterCompletion(
|
|
27
|
+
const frontmatterCompletion = getFrontmatterCompletion(virtualCode, document, position);
|
|
26
28
|
if (frontmatterCompletion)
|
|
27
29
|
items.push(frontmatterCompletion);
|
|
28
30
|
}
|
|
@@ -34,10 +36,12 @@ const create = (ts) => {
|
|
|
34
36
|
provideSemanticDiagnostics(document, token) {
|
|
35
37
|
if (token.isCancellationRequested)
|
|
36
38
|
return [];
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
40
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
41
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
42
|
+
if (!(virtualCode instanceof index_js_1.AstroVirtualCode))
|
|
39
43
|
return;
|
|
40
|
-
return
|
|
44
|
+
return virtualCode.compilerDiagnostics.map(compilerMessageToDiagnostic);
|
|
41
45
|
function compilerMessageToDiagnostic(message) {
|
|
42
46
|
const start = language_server_1.Position.create(message.location.line - 1, message.location.column - 1);
|
|
43
47
|
const end = document.positionAt(document.offsetAt(start) + message.location.length);
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const create: () =>
|
|
1
|
+
import { LanguageServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: () => LanguageServicePlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -61,12 +61,13 @@ const create = () => {
|
|
|
61
61
|
async provideCompletionItems(document, position, completionContext, token) {
|
|
62
62
|
if (document.languageId !== 'html')
|
|
63
63
|
return;
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
64
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
65
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
66
|
+
const root = sourceScript?.generated?.root;
|
|
67
|
+
if (!(root instanceof index_js_1.AstroVirtualCode))
|
|
67
68
|
return;
|
|
68
69
|
// Don't return completions if the current node is a component
|
|
69
|
-
if ((0, utils_js_1.isInComponentStartTag)(
|
|
70
|
+
if ((0, utils_js_1.isInComponentStartTag)(root.htmlDocument, document.offsetAt(position))) {
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
72
73
|
const completions = await htmlPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
@@ -22,11 +22,13 @@ function mapCodeAction(codeAction, context) {
|
|
|
22
22
|
return codeAction;
|
|
23
23
|
codeAction.edit.documentChanges = codeAction.edit.documentChanges.map((change) => {
|
|
24
24
|
if (language_server_1.TextDocumentEdit.is(change)) {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
const decoded = context.decodeEmbeddedDocumentUri(change.textDocument.uri);
|
|
26
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
27
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
28
|
+
const root = sourceScript?.generated?.root;
|
|
29
|
+
if (!virtualCode || !(root instanceof index_js_1.AstroVirtualCode))
|
|
28
30
|
return change;
|
|
29
|
-
change.edits = change.edits.map((edit) => (0, utils_js_1.mapEdit)(edit,
|
|
31
|
+
change.edits = change.edits.map((edit) => (0, utils_js_1.mapEdit)(edit, root, virtualCode.languageId));
|
|
30
32
|
}
|
|
31
33
|
return change;
|
|
32
34
|
});
|
|
@@ -31,11 +31,13 @@ function enhancedResolveCompletionItem(resolvedCompletion, context) {
|
|
|
31
31
|
resolvedCompletion.detail = getDetailForFileCompletion(resolvedCompletion.detail ?? '', resolvedCompletion.data.originalItem.source);
|
|
32
32
|
}
|
|
33
33
|
if (resolvedCompletion.additionalTextEdits) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
34
|
+
const decoded = context.decodeEmbeddedDocumentUri(resolvedCompletion.data.uri);
|
|
35
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
36
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
37
|
+
const root = sourceScript?.generated?.root;
|
|
38
|
+
if (!virtualCode || !(root instanceof index_js_1.AstroVirtualCode))
|
|
37
39
|
return resolvedCompletion;
|
|
38
|
-
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) => (0, utils_js_1.mapEdit)(edit,
|
|
40
|
+
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) => (0, utils_js_1.mapEdit)(edit, root, virtualCode.languageId));
|
|
39
41
|
}
|
|
40
42
|
return resolvedCompletion;
|
|
41
43
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const create: (ts: typeof import('typescript')) =>
|
|
1
|
+
import type { LanguageServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: (ts: typeof import('typescript')) => LanguageServicePlugin[];
|
|
@@ -41,15 +41,16 @@ const create = (ts) => {
|
|
|
41
41
|
return (0, codeActions_js_1.enhancedResolveCodeAction)(resolvedCodeAction, context);
|
|
42
42
|
},
|
|
43
43
|
async provideSemanticDiagnostics(document, token) {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
44
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
45
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
46
|
+
const root = sourceScript?.generated?.root;
|
|
46
47
|
let tsxLineCount = undefined;
|
|
47
|
-
if (
|
|
48
|
+
if (root instanceof index_js_1.AstroVirtualCode) {
|
|
48
49
|
// If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
|
|
49
|
-
if (
|
|
50
|
+
if (root.hasCompilationErrors)
|
|
50
51
|
return null;
|
|
51
52
|
// We'll use this to filter out diagnostics that are outside the mapped range of the TSX
|
|
52
|
-
tsxLineCount =
|
|
53
|
+
tsxLineCount = root.astroMeta.tsxRanges.body.end.line;
|
|
53
54
|
}
|
|
54
55
|
const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics(document, token);
|
|
55
56
|
if (!diagnostics)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const create: () =>
|
|
1
|
+
import type { LanguageServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: () => LanguageServicePlugin;
|
|
@@ -21,17 +21,18 @@ const create = () => {
|
|
|
21
21
|
token.isCancellationRequested ||
|
|
22
22
|
completionContext.triggerKind === 2)
|
|
23
23
|
return null;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
24
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
25
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
26
|
+
const root = sourceScript?.generated?.root;
|
|
27
|
+
if (!(root instanceof index_js_1.AstroVirtualCode))
|
|
27
28
|
return undefined;
|
|
28
|
-
if (!(0, utils_js_1.isInsideFrontmatter)(document.offsetAt(position),
|
|
29
|
+
if (!(0, utils_js_1.isInsideFrontmatter)(document.offsetAt(position), root.astroMeta.frontmatter))
|
|
29
30
|
return null;
|
|
30
31
|
const completionList = {
|
|
31
32
|
items: [],
|
|
32
33
|
isIncomplete: false,
|
|
33
34
|
};
|
|
34
|
-
completionList.items.push(...(0, snippets_js_1.getSnippetCompletions)(
|
|
35
|
+
completionList.items.push(...(0, snippets_js_1.getSnippetCompletions)(root.astroMeta.frontmatter));
|
|
35
36
|
return completionList;
|
|
36
37
|
},
|
|
37
38
|
resolveCompletionItem(item) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@astrojs/compiler": "^2.7.0",
|
|
24
24
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
25
|
-
"@volar/kit": "~2.1
|
|
26
|
-
"@volar/language-core": "~2.1
|
|
27
|
-
"@volar/language-server": "~2.1
|
|
28
|
-
"@volar/language-service": "~2.1
|
|
29
|
-
"@volar/typescript": "~2.1
|
|
25
|
+
"@volar/kit": "~2.2.1",
|
|
26
|
+
"@volar/language-core": "~2.2.1",
|
|
27
|
+
"@volar/language-server": "~2.2.1",
|
|
28
|
+
"@volar/language-service": "~2.2.1",
|
|
29
|
+
"@volar/typescript": "~2.2.1",
|
|
30
30
|
"fast-glob": "^3.2.12",
|
|
31
|
-
"volar-service-css": "0.0.
|
|
32
|
-
"volar-service-emmet": "0.0.
|
|
33
|
-
"volar-service-html": "0.0.
|
|
34
|
-
"volar-service-prettier": "0.0.
|
|
35
|
-
"volar-service-typescript": "0.0.
|
|
36
|
-
"volar-service-typescript-twoslash-queries": "0.0.
|
|
37
|
-
"vscode-html-languageservice": "^5.
|
|
31
|
+
"volar-service-css": "0.0.43",
|
|
32
|
+
"volar-service-emmet": "0.0.43",
|
|
33
|
+
"volar-service-html": "0.0.43",
|
|
34
|
+
"volar-service-prettier": "0.0.43",
|
|
35
|
+
"volar-service-typescript": "0.0.43",
|
|
36
|
+
"volar-service-typescript-twoslash-queries": "0.0.43",
|
|
37
|
+
"vscode-html-languageservice": "^5.2.0",
|
|
38
38
|
"vscode-uri": "^3.0.8"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/chai": "^4.3.5",
|
|
45
45
|
"@types/mocha": "^10.0.1",
|
|
46
46
|
"@types/node": "^18.17.8",
|
|
47
|
-
"@volar/test-utils": "~2.1
|
|
47
|
+
"@volar/test-utils": "~2.2.1",
|
|
48
48
|
"astro": "^4.3.5",
|
|
49
49
|
"chai": "^4.3.7",
|
|
50
50
|
"mocha": "^10.2.0",
|