@astrojs/language-server 2.8.3 → 2.9.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.js +4 -2
- package/dist/core/index.js +12 -7
- package/dist/core/svelte.js +11 -6
- package/dist/core/vue.js +11 -6
- package/dist/languageServerPlugin.d.ts +3 -3
- package/dist/languageServerPlugin.js +45 -58
- 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 +50 -10
- package/dist/plugins/typescript/codeActions.js +7 -11
- package/dist/plugins/typescript/completions.js +7 -10
- package/dist/plugins/typescript/index.d.ts +2 -2
- package/dist/plugins/typescript/index.js +6 -5
- package/dist/plugins/typescript/utils.d.ts +3 -0
- package/dist/plugins/typescript/utils.js +21 -0
- 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 {
|
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 {
|
|
@@ -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,79 +17,66 @@ 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;
|
|
57
|
+
let hasShownNotification = false;
|
|
76
58
|
return (0, volar_service_prettier_1.create)((context) => {
|
|
77
59
|
const workspaceUri = vscode_uri_1.URI.parse(context.env.workspaceFolder);
|
|
78
60
|
if (workspaceUri.scheme === 'file') {
|
|
79
61
|
prettier = (0, importPackage_js_1.importPrettier)(workspaceUri.fsPath);
|
|
80
62
|
prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspaceUri.fsPath);
|
|
81
|
-
if (!prettier || !prettierPluginPath) {
|
|
63
|
+
if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
|
|
82
64
|
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
83
|
-
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
|
|
65
|
+
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project and restart the language server.",
|
|
84
66
|
type: node_1.MessageType.Warning,
|
|
85
67
|
});
|
|
68
|
+
hasShownNotification = true;
|
|
86
69
|
}
|
|
87
70
|
return prettier;
|
|
88
71
|
}
|
|
89
72
|
}, {
|
|
90
73
|
documentSelector: ['astro'],
|
|
91
74
|
getFormattingOptions: async (prettierInstance, document, formatOptions, context) => {
|
|
92
|
-
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
|
+
}
|
|
93
80
|
let configOptions = null;
|
|
94
81
|
try {
|
|
95
82
|
configOptions = await prettierInstance.resolveConfig(filePath, {
|
|
@@ -134,5 +121,5 @@ function createServerOptions(connection, ts) {
|
|
|
134
121
|
});
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
|
-
exports.
|
|
124
|
+
exports.getLanguageServicePlugins = getLanguageServicePlugins;
|
|
138
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
|
@@ -1,33 +1,73 @@
|
|
|
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.create = void 0;
|
|
4
27
|
const language_server_1 = require("@volar/language-server");
|
|
5
28
|
const volar_service_html_1 = require("volar-service-html");
|
|
29
|
+
const html = __importStar(require("vscode-html-languageservice"));
|
|
30
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
6
31
|
const index_js_1 = require("../core/index.js");
|
|
7
32
|
const html_data_js_1 = require("./html-data.js");
|
|
8
33
|
const utils_js_1 = require("./utils.js");
|
|
9
34
|
const create = () => {
|
|
10
|
-
const htmlServicePlugin = (0, volar_service_html_1.create)(
|
|
35
|
+
const htmlServicePlugin = (0, volar_service_html_1.create)({
|
|
36
|
+
getCustomData: async (context) => {
|
|
37
|
+
const customData = (await context.env.getConfiguration?.('html.customData')) ?? [];
|
|
38
|
+
const newData = [];
|
|
39
|
+
for (const customDataPath of customData) {
|
|
40
|
+
const uri = vscode_uri_1.Utils.resolvePath(vscode_uri_1.URI.parse(context.env.workspaceFolder), customDataPath);
|
|
41
|
+
const json = await context.env.fs?.readFile?.(uri.toString());
|
|
42
|
+
if (json) {
|
|
43
|
+
try {
|
|
44
|
+
const data = JSON.parse(json);
|
|
45
|
+
newData.push(html.newHTMLDataProvider(customDataPath, data));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [...newData, html_data_js_1.astroAttributes, html_data_js_1.astroElements, html_data_js_1.classListAttribute];
|
|
53
|
+
},
|
|
54
|
+
});
|
|
11
55
|
return {
|
|
12
56
|
...htmlServicePlugin,
|
|
13
57
|
create(context) {
|
|
14
58
|
const htmlPlugin = htmlServicePlugin.create(context);
|
|
15
|
-
htmlPlugin.provide['html/updateCustomData']?.([
|
|
16
|
-
html_data_js_1.astroAttributes,
|
|
17
|
-
html_data_js_1.astroElements,
|
|
18
|
-
html_data_js_1.classListAttribute,
|
|
19
|
-
]);
|
|
20
59
|
return {
|
|
21
60
|
...htmlPlugin,
|
|
22
61
|
async provideCompletionItems(document, position, completionContext, token) {
|
|
23
62
|
if (document.languageId !== 'html')
|
|
24
63
|
return;
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
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))
|
|
28
68
|
return;
|
|
29
69
|
// Don't return completions if the current node is a component
|
|
30
|
-
if ((0, utils_js_1.isInComponentStartTag)(
|
|
70
|
+
if ((0, utils_js_1.isInComponentStartTag)(root.htmlDocument, document.offsetAt(position))) {
|
|
31
71
|
return null;
|
|
32
72
|
}
|
|
33
73
|
const completions = await htmlPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhancedResolveCodeAction = exports.enhancedProvideCodeActions = void 0;
|
|
4
4
|
const language_server_1 = require("@volar/language-server");
|
|
5
5
|
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
const utils_js_1 = require("
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function enhancedProvideCodeActions(codeActions, context) {
|
|
8
8
|
return codeActions.map((codeAction) => mapCodeAction(codeAction, context));
|
|
9
9
|
}
|
|
@@ -22,17 +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) =>
|
|
30
|
-
const shouldModifyEdit = (0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta);
|
|
31
|
-
if (shouldModifyEdit.itShould) {
|
|
32
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
33
|
-
}
|
|
34
|
-
return edit;
|
|
35
|
-
});
|
|
31
|
+
change.edits = change.edits.map((edit) => (0, utils_js_1.mapEdit)(edit, root, virtualCode.languageId));
|
|
36
32
|
}
|
|
37
33
|
return change;
|
|
38
34
|
});
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhancedResolveCompletionItem = exports.enhancedProvideCompletionItems = void 0;
|
|
4
4
|
const language_server_1 = require("@volar/language-server");
|
|
5
5
|
const index_js_1 = require("../../core/index.js");
|
|
6
|
-
const utils_js_1 = require("
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
7
|
function enhancedProvideCompletionItems(completions) {
|
|
8
8
|
completions.items = completions.items.filter(isValidCompletion).map((completion) => {
|
|
9
9
|
const source = completion?.data?.originalItem?.source;
|
|
@@ -31,16 +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) =>
|
|
39
|
-
if ((0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta).itShould) {
|
|
40
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
41
|
-
}
|
|
42
|
-
return edit;
|
|
43
|
-
});
|
|
40
|
+
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) => (0, utils_js_1.mapEdit)(edit, root, virtualCode.languageId));
|
|
44
41
|
}
|
|
45
42
|
return resolvedCompletion;
|
|
46
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)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapEdit = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
function mapEdit(edit, code, languageId) {
|
|
6
|
+
// Don't attempt to move the edit to the frontmatter if the file isn't the root TSX file, it means it's a script tag
|
|
7
|
+
if (languageId === 'typescriptreact') {
|
|
8
|
+
if ((0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta).itShould) {
|
|
9
|
+
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
// If the edit is at the start of the file, add a newline before it, otherwise we'll get `<script>text`
|
|
14
|
+
if (edit.range.start.line === 0 && edit.range.start.character === 0) {
|
|
15
|
+
edit.newText = '\n' + edit.newText;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return edit;
|
|
19
|
+
}
|
|
20
|
+
exports.mapEdit = mapEdit;
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -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.0",
|
|
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",
|