@astrojs/language-server 2.6.3 → 2.7.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.d.ts +1 -2
- package/dist/check.js +12 -22
- 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 +106 -76
- 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 +64 -61
- 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/types/jsx-runtime-fallback.d.ts +1 -0
package/dist/core/vue.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 getVueLanguageModule() {
|
|
7
7
|
return {
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
8
|
+
createVirtualCode(fileId, languageId, snapshot) {
|
|
9
|
+
if (languageId === 'vue') {
|
|
10
|
+
const fileName = fileId.includes('://') ? fileId.split('://')[1] : fileId;
|
|
11
|
+
return new VueVirtualCode(fileName, snapshot);
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
updateVirtualCode(_fileId, vueCode, snapshot) {
|
|
15
|
+
vueCode.update(snapshot);
|
|
16
|
+
return vueCode;
|
|
17
|
+
},
|
|
18
|
+
typescript: {
|
|
19
|
+
extraFileExtensions: [{ extension: 'vue', isMixedContent: true, scriptKind: 7 }],
|
|
20
|
+
getScript(vueCode) {
|
|
21
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(vueCode)) {
|
|
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.getVueLanguageModule = getVueLanguageModule;
|
|
19
|
-
class
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
35
|
+
class VueVirtualCode {
|
|
36
|
+
constructor(fileName, snapshot) {
|
|
37
|
+
this.fileName = fileName;
|
|
22
38
|
this.snapshot = snapshot;
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
39
|
+
this.id = 'root';
|
|
40
|
+
this.languageId = 'vue';
|
|
25
41
|
this.codegenStacks = [];
|
|
26
|
-
this.fileName = sourceFileName;
|
|
27
42
|
this.onSnapshotUpdated();
|
|
28
43
|
}
|
|
29
44
|
update(newSnapshot) {
|
|
@@ -33,13 +48,21 @@ class VueFile {
|
|
|
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()), 'vue'));
|
|
43
66
|
}
|
|
44
67
|
}
|
|
45
68
|
//# sourceMappingURL=vue.js.map
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Connection } from '@volar/language-server/node';
|
|
2
|
+
import type { ServerOptions, createServerBase } from '@volar/language-server/lib/server.js';
|
|
3
|
+
export declare function createServerOptions(connection: Connection, server: ReturnType<typeof createServerBase>): ServerOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createServerOptions = void 0;
|
|
4
4
|
const node_1 = require("@volar/language-server/node");
|
|
5
5
|
const core_1 = require("./core");
|
|
6
6
|
const svelte_js_1 = require("./core/svelte.js");
|
|
@@ -16,96 +16,109 @@ const astro_js_1 = require("./plugins/astro.js");
|
|
|
16
16
|
const html_js_1 = require("./plugins/html.js");
|
|
17
17
|
const index_js_1 = require("./plugins/typescript-addons/index.js");
|
|
18
18
|
const index_js_2 = require("./plugins/typescript/index.js");
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
19
|
+
function createServerOptions(connection, server) {
|
|
20
|
+
return {
|
|
21
|
+
watchFileExtensions: [
|
|
22
|
+
'js',
|
|
23
|
+
'cjs',
|
|
24
|
+
'mjs',
|
|
25
|
+
'ts',
|
|
26
|
+
'cts',
|
|
27
|
+
'mts',
|
|
28
|
+
'jsx',
|
|
29
|
+
'tsx',
|
|
30
|
+
'json',
|
|
31
|
+
'astro',
|
|
32
|
+
'vue',
|
|
33
|
+
'svelte',
|
|
34
|
+
],
|
|
35
|
+
getServicePlugins() {
|
|
36
|
+
const ts = getTypeScriptModule();
|
|
37
|
+
return [
|
|
38
|
+
(0, html_js_1.create)(),
|
|
39
|
+
(0, volar_service_css_1.create)(),
|
|
40
|
+
(0, volar_service_emmet_1.create)(),
|
|
41
|
+
(0, index_js_2.create)(ts),
|
|
42
|
+
(0, volar_service_typescript_twoslash_queries_1.create)(),
|
|
43
|
+
(0, index_js_1.create)(),
|
|
44
|
+
(0, astro_js_1.create)(ts),
|
|
45
|
+
getPrettierService(),
|
|
46
|
+
];
|
|
47
|
+
},
|
|
48
|
+
getLanguagePlugins(serviceEnv, projectContext) {
|
|
49
|
+
const ts = getTypeScriptModule();
|
|
50
|
+
const languagePlugins = [
|
|
51
|
+
(0, vue_js_1.getVueLanguageModule)(),
|
|
52
|
+
(0, svelte_js_1.getSvelteLanguageModule)(),
|
|
53
|
+
];
|
|
54
|
+
if (projectContext.typescript) {
|
|
55
|
+
const rootPath = projectContext.typescript.configFileName
|
|
56
|
+
? projectContext.typescript.configFileName.split('/').slice(0, -1).join('/')
|
|
57
|
+
: serviceEnv.typescript.uriToFileName(serviceEnv.workspaceFolder);
|
|
58
|
+
const nearestPackageJson = server.modules.typescript?.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
|
|
59
|
+
const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
|
|
60
|
+
nearestPackageJson: nearestPackageJson,
|
|
61
|
+
readDirectory: ts.sys.readDirectory,
|
|
51
62
|
});
|
|
63
|
+
if (astroInstall === 'not-found') {
|
|
64
|
+
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
65
|
+
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.`,
|
|
66
|
+
type: node_1.MessageType.Warning,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
languagePlugins.unshift((0, core_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
|
|
52
70
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
return languagePlugins;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
function getTypeScriptModule() {
|
|
75
|
+
const tsModule = server.modules.typescript;
|
|
76
|
+
if (!tsModule) {
|
|
77
|
+
throw new Error('TypeScript module is missing');
|
|
56
78
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
|
|
103
|
-
type: node_1.MessageType.Warning,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return config;
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
exports.plugin = plugin;
|
|
79
|
+
return tsModule;
|
|
80
|
+
}
|
|
81
|
+
function getPrettierService() {
|
|
82
|
+
let prettier;
|
|
83
|
+
let prettierPluginPath;
|
|
84
|
+
return (0, volar_service_prettier_1.create)({
|
|
85
|
+
getPrettier(env) {
|
|
86
|
+
const workspacePath = env.typescript.uriToFileName(env.workspaceFolder);
|
|
87
|
+
prettier = (0, importPackage_js_1.importPrettier)(workspacePath);
|
|
88
|
+
prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspacePath);
|
|
89
|
+
if (!prettier || !prettierPluginPath) {
|
|
90
|
+
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
91
|
+
message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
|
|
92
|
+
type: node_1.MessageType.Warning,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return prettier;
|
|
96
|
+
},
|
|
97
|
+
languages: ['astro'],
|
|
98
|
+
ignoreIdeOptions: true,
|
|
99
|
+
useIdeOptionsFallback: true,
|
|
100
|
+
resolveConfigOptions: {
|
|
101
|
+
// This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
|
|
102
|
+
useCache: false,
|
|
103
|
+
},
|
|
104
|
+
additionalOptions: async (resolvedConfig) => {
|
|
105
|
+
async function getAstroPrettierPlugin() {
|
|
106
|
+
if (!prettier || !prettierPluginPath) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
const hasPluginLoadedAlready = (await prettier.getSupportInfo()).languages.some((l) => l.name === 'astro') ||
|
|
110
|
+
resolvedConfig.plugins?.includes('prettier-plugin-astro'); // getSupportInfo doesn't seems to work very well in Prettier 3 for plugins
|
|
111
|
+
return hasPluginLoadedAlready ? [] : [prettierPluginPath];
|
|
112
|
+
}
|
|
113
|
+
const plugins = [...(await getAstroPrettierPlugin()), ...(resolvedConfig.plugins ?? [])];
|
|
114
|
+
return {
|
|
115
|
+
...resolvedConfig,
|
|
116
|
+
plugins: plugins,
|
|
117
|
+
parser: 'astro',
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.createServerOptions = createServerOptions;
|
|
111
124
|
//# sourceMappingURL=languageServerPlugin.js.map
|
package/dist/nodeServer.js
CHANGED
|
@@ -2,5 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_1 = require("@volar/language-server/node");
|
|
4
4
|
const languageServerPlugin_js_1 = require("./languageServerPlugin.js");
|
|
5
|
-
|
|
5
|
+
const connection = (0, node_1.createConnection)();
|
|
6
|
+
const server = (0, node_1.createServer)(connection);
|
|
7
|
+
connection.listen();
|
|
8
|
+
connection.onInitialize((params) => {
|
|
9
|
+
return server.initialize(params, node_1.createTypeScriptProjectProvider, (0, languageServerPlugin_js_1.createServerOptions)(connection, server));
|
|
10
|
+
});
|
|
11
|
+
connection.onInitialized(() => {
|
|
12
|
+
server.initialized();
|
|
13
|
+
});
|
|
6
14
|
//# sourceMappingURL=nodeServer.js.map
|
package/dist/plugins/astro.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const create: () =>
|
|
1
|
+
import { ServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: (ts: typeof import('typescript')) => ServicePlugin;
|
package/dist/plugins/astro.js
CHANGED
|
@@ -4,75 +4,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.create = void 0;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
7
8
|
const language_server_1 = require("@volar/language-server");
|
|
8
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
-
const node_path_1 = require("node:path");
|
|
10
10
|
const index_js_1 = require("../core/index.js");
|
|
11
11
|
const utils_js_1 = require("./utils.js");
|
|
12
|
-
const create = () =>
|
|
12
|
+
const create = (ts) => {
|
|
13
13
|
return {
|
|
14
14
|
triggerCharacters: ['-'],
|
|
15
|
-
|
|
16
|
-
if (token.isCancellationRequested)
|
|
17
|
-
return null;
|
|
18
|
-
let items = [];
|
|
19
|
-
const [file] = context.documents.getVirtualFileByUri(document.uri);
|
|
20
|
-
if (!(file instanceof index_js_1.AstroFile))
|
|
21
|
-
return;
|
|
22
|
-
if (completionContext.triggerCharacter === '-') {
|
|
23
|
-
const frontmatterCompletion = getFrontmatterCompletion(file, document, position);
|
|
24
|
-
if (frontmatterCompletion)
|
|
25
|
-
items.push(frontmatterCompletion);
|
|
26
|
-
}
|
|
15
|
+
create(context) {
|
|
27
16
|
return {
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return;
|
|
61
|
-
const globcodeLens = [];
|
|
62
|
-
const sourceFile = tsProgram.getSourceFile(context.env.uriToFileName(document.uri));
|
|
63
|
-
function walk() {
|
|
64
|
-
return ts.forEachChild(sourceFile, function cb(node) {
|
|
65
|
-
if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
|
|
66
|
-
const globArgument = node.arguments.at(0);
|
|
67
|
-
if (globArgument) {
|
|
68
|
-
globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(context.env.uriToFileName(document.uri)), document.positionAt(node.arguments.pos)));
|
|
69
|
-
}
|
|
17
|
+
provideCompletionItems(document, position, completionContext, token) {
|
|
18
|
+
if (token.isCancellationRequested)
|
|
19
|
+
return null;
|
|
20
|
+
let items = [];
|
|
21
|
+
const [file] = context.documents.getVirtualCodeByUri(document.uri);
|
|
22
|
+
if (!(file instanceof index_js_1.AstroVirtualCode))
|
|
23
|
+
return;
|
|
24
|
+
if (completionContext.triggerCharacter === '-') {
|
|
25
|
+
const frontmatterCompletion = getFrontmatterCompletion(file, document, position);
|
|
26
|
+
if (frontmatterCompletion)
|
|
27
|
+
items.push(frontmatterCompletion);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
isIncomplete: false,
|
|
31
|
+
items: items,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
provideSemanticDiagnostics(document, token) {
|
|
35
|
+
if (token.isCancellationRequested)
|
|
36
|
+
return [];
|
|
37
|
+
const [file] = context.documents.getVirtualCodeByUri(document.uri);
|
|
38
|
+
if (!(file instanceof index_js_1.AstroVirtualCode))
|
|
39
|
+
return;
|
|
40
|
+
return file.compilerDiagnostics.map(compilerMessageToDiagnostic);
|
|
41
|
+
function compilerMessageToDiagnostic(message) {
|
|
42
|
+
return {
|
|
43
|
+
message: message.text + (message.hint ? '\n\n' + message.hint : ''),
|
|
44
|
+
range: language_server_1.Range.create(message.location.line - 1, message.location.column - 1, message.location.line, message.location.length),
|
|
45
|
+
code: message.code,
|
|
46
|
+
severity: message.severity,
|
|
47
|
+
source: 'astro',
|
|
48
|
+
};
|
|
70
49
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
},
|
|
51
|
+
provideCodeLenses(document, token) {
|
|
52
|
+
if (token.isCancellationRequested)
|
|
53
|
+
return;
|
|
54
|
+
if (!(0, utils_js_1.isJSDocument)(document.languageId))
|
|
55
|
+
return;
|
|
56
|
+
const languageService = context.inject('typescript/languageService');
|
|
57
|
+
if (!languageService)
|
|
58
|
+
return;
|
|
59
|
+
const tsProgram = languageService.getProgram();
|
|
60
|
+
if (!tsProgram)
|
|
61
|
+
return;
|
|
62
|
+
const globcodeLens = [];
|
|
63
|
+
const sourceFile = tsProgram.getSourceFile(document.uri);
|
|
64
|
+
function walk() {
|
|
65
|
+
return ts.forEachChild(sourceFile, function cb(node) {
|
|
66
|
+
if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
|
|
67
|
+
const globArgument = node.arguments.at(0);
|
|
68
|
+
if (globArgument) {
|
|
69
|
+
globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(context.env.typescript.uriToFileName(document.uri)), document.positionAt(node.arguments.pos)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return ts.forEachChild(node, cb);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
walk();
|
|
76
|
+
return globcodeLens;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
76
79
|
},
|
|
77
80
|
};
|
|
78
81
|
};
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const create: () =>
|
|
1
|
+
import { ServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: () => ServicePlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.create = void 0;
|
|
7
4
|
const language_server_1 = require("@volar/language-server");
|
|
8
|
-
const volar_service_html_1 =
|
|
5
|
+
const volar_service_html_1 = require("volar-service-html");
|
|
9
6
|
const index_js_1 = require("../core/index.js");
|
|
10
7
|
const html_data_js_1 = require("./html-data.js");
|
|
11
8
|
const utils_js_1 = require("./utils.js");
|
|
12
|
-
const create = () =>
|
|
13
|
-
const
|
|
14
|
-
if (!context) {
|
|
15
|
-
return { triggerCharacters: htmlPlugin.triggerCharacters };
|
|
16
|
-
}
|
|
17
|
-
htmlPlugin.provide['html/updateCustomData']?.([
|
|
18
|
-
html_data_js_1.astroAttributes,
|
|
19
|
-
html_data_js_1.astroElements,
|
|
20
|
-
html_data_js_1.classListAttribute,
|
|
21
|
-
]);
|
|
9
|
+
const create = () => {
|
|
10
|
+
const htmlServicePlugin = (0, volar_service_html_1.create)();
|
|
22
11
|
return {
|
|
23
|
-
...
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
12
|
+
...htmlServicePlugin,
|
|
13
|
+
create(context) {
|
|
14
|
+
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
|
+
return {
|
|
21
|
+
...htmlPlugin,
|
|
22
|
+
async provideCompletionItems(document, position, completionContext, token) {
|
|
23
|
+
if (document.languageId !== 'html')
|
|
24
|
+
return;
|
|
25
|
+
const [_, source] = context.documents.getVirtualCodeByUri(document.uri);
|
|
26
|
+
const code = source?.generated?.code;
|
|
27
|
+
if (!(code instanceof index_js_1.AstroVirtualCode))
|
|
28
|
+
return;
|
|
29
|
+
// Don't return completions if the current node is a component
|
|
30
|
+
if ((0, utils_js_1.isInComponentStartTag)(code.htmlDocument, document.offsetAt(position))) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const completions = await htmlPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
34
|
+
if (!completions) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
// We don't want completions for file references, as they're mostly invalid for Astro
|
|
38
|
+
completions.items = completions.items.filter((completion) => completion.kind !== language_server_1.CompletionItemKind.File);
|
|
39
|
+
return completions;
|
|
40
|
+
},
|
|
41
|
+
// Document links provided by `vscode-html-languageservice` are invalid for Astro
|
|
42
|
+
provideDocumentLinks() {
|
|
43
|
+
return [];
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
};
|
|
@@ -22,14 +22,14 @@ 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 [virtualFile, source] = context.documents.
|
|
26
|
-
const
|
|
27
|
-
if (!virtualFile || !(
|
|
25
|
+
const [virtualFile, source] = context.documents.getVirtualCodeByUri(change.textDocument.uri);
|
|
26
|
+
const code = source?.generated?.code;
|
|
27
|
+
if (!virtualFile || !(code instanceof index_js_1.AstroVirtualCode))
|
|
28
28
|
return change;
|
|
29
29
|
change.edits = change.edits.map((edit) => {
|
|
30
|
-
const shouldModifyEdit = (0, utils_js_1.editShouldBeInFrontmatter)(edit.range,
|
|
30
|
+
const shouldModifyEdit = (0, utils_js_1.editShouldBeInFrontmatter)(edit.range, code.astroMeta);
|
|
31
31
|
if (shouldModifyEdit.itShould) {
|
|
32
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit,
|
|
32
|
+
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, code.astroMeta, '\n');
|
|
33
33
|
}
|
|
34
34
|
return edit;
|
|
35
35
|
});
|
|
@@ -31,13 +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 [virtualFile, source] = context.documents.
|
|
35
|
-
const
|
|
36
|
-
if (!virtualFile || !(
|
|
34
|
+
const [virtualFile, source] = context.documents.getVirtualCodeByUri(resolvedCompletion.data.uri);
|
|
35
|
+
const code = source?.generated?.code;
|
|
36
|
+
if (!virtualFile || !(code instanceof index_js_1.AstroVirtualCode))
|
|
37
37
|
return resolvedCompletion;
|
|
38
38
|
resolvedCompletion.additionalTextEdits = resolvedCompletion.additionalTextEdits.map((edit) => {
|
|
39
|
-
if ((0, utils_js_1.editShouldBeInFrontmatter)(edit.range,
|
|
40
|
-
edit = (0, utils_js_1.ensureProperEditForFrontmatter)(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
41
|
}
|
|
42
42
|
return edit;
|
|
43
43
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const create: () =>
|
|
1
|
+
import type { ServicePlugin } from '@volar/language-server';
|
|
2
|
+
export declare const create: (ts: typeof import('typescript')) => ServicePlugin;
|