@astrojs/language-server 2.2.0 → 2.3.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/languageServerPlugin.js +4 -2
- package/dist/plugins/typescript/completions.js +6 -2
- package/dist/plugins/typescript-addons/index.d.ts +2 -0
- package/dist/plugins/typescript-addons/index.js +41 -0
- package/dist/plugins/typescript-addons/snippets.d.ts +3 -0
- package/dist/plugins/typescript-addons/snippets.js +66 -0
- package/package.json +2 -2
|
@@ -15,7 +15,8 @@ const vue_js_1 = require("./core/vue.js");
|
|
|
15
15
|
const importPackage_js_1 = require("./importPackage.js");
|
|
16
16
|
const astro_js_1 = __importDefault(require("./plugins/astro.js"));
|
|
17
17
|
const html_js_1 = __importDefault(require("./plugins/html.js"));
|
|
18
|
-
const index_js_1 =
|
|
18
|
+
const index_js_1 = require("./plugins/typescript-addons/index.js");
|
|
19
|
+
const index_js_2 = __importDefault(require("./plugins/typescript/index.js"));
|
|
19
20
|
const utils_js_1 = require("./utils.js");
|
|
20
21
|
const plugin = (initOptions, modules) => ({
|
|
21
22
|
extraFileExtensions: [
|
|
@@ -55,8 +56,9 @@ const plugin = (initOptions, modules) => ({
|
|
|
55
56
|
config.services.html ??= (0, html_js_1.default)();
|
|
56
57
|
config.services.css ??= (0, volar_service_css_1.default)();
|
|
57
58
|
config.services.emmet ??= (0, volar_service_emmet_1.default)();
|
|
58
|
-
config.services.typescript ??= (0,
|
|
59
|
+
config.services.typescript ??= (0, index_js_2.default)();
|
|
59
60
|
config.services.typescripttwoslash ??= (0, volar_service_typescript_twoslash_queries_1.default)();
|
|
61
|
+
config.services.typescriptaddons ??= (0, index_js_1.createTypescriptAddonsService)();
|
|
60
62
|
config.services.astro ??= (0, astro_js_1.default)();
|
|
61
63
|
if (ctx) {
|
|
62
64
|
const rootDir = ctx.env.uriToFileName(ctx.project.rootUri.toString());
|
|
@@ -6,11 +6,15 @@ function enhancedProvideCompletionItems(completions) {
|
|
|
6
6
|
completions.items = completions.items.filter(isValidCompletion).map((completion) => {
|
|
7
7
|
const source = completion?.data?.originalItem?.source;
|
|
8
8
|
if (source) {
|
|
9
|
-
//
|
|
9
|
+
// Sort completions starting with `astro:` higher than other imports
|
|
10
|
+
if (source.startsWith('astro:')) {
|
|
11
|
+
completion.sortText = '\u0000' + (completion.sortText ?? completion.label);
|
|
12
|
+
}
|
|
13
|
+
// For components import, use the file kind and sort them first, as they're often what the user want over something else
|
|
10
14
|
if (['.astro', '.svelte', '.vue'].some((ext) => source.endsWith(ext))) {
|
|
11
15
|
completion.kind = language_server_1.CompletionItemKind.File;
|
|
12
16
|
completion.detail = completion.detail + '\n\n' + source;
|
|
13
|
-
completion.sortText = '\
|
|
17
|
+
completion.sortText = '\u0001' + (completion.sortText ?? completion.label);
|
|
14
18
|
completion.data.isComponent = true;
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTypescriptAddonsService = void 0;
|
|
4
|
+
const index_js_1 = require("../../core/index.js");
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const snippets_js_1 = require("./snippets.js");
|
|
7
|
+
const createTypescriptAddonsService = () => (context) => {
|
|
8
|
+
return {
|
|
9
|
+
isAdditionalCompletion: true,
|
|
10
|
+
// Q: Why the empty transform and resolve functions?
|
|
11
|
+
// A: Volar will skip mapping the completion items if those functions are defined, as such we can return the snippets
|
|
12
|
+
// completions as-is, this is notably useful for snippets that insert to the frontmatter, since we don't need to map anything.
|
|
13
|
+
transformCompletionItem(item) {
|
|
14
|
+
return item;
|
|
15
|
+
},
|
|
16
|
+
provideCompletionItems(document, position, completionContext, token) {
|
|
17
|
+
if (!context ||
|
|
18
|
+
!utils_js_1.isJSDocument ||
|
|
19
|
+
token.isCancellationRequested ||
|
|
20
|
+
completionContext.triggerKind === 2)
|
|
21
|
+
return null;
|
|
22
|
+
const [_, source] = context.documents.getVirtualFileByUri(document.uri);
|
|
23
|
+
const file = source?.root;
|
|
24
|
+
if (!(file instanceof index_js_1.AstroFile))
|
|
25
|
+
return undefined;
|
|
26
|
+
if (!(0, utils_js_1.isInsideFrontmatter)(document.offsetAt(position), file.astroMeta.frontmatter))
|
|
27
|
+
return null;
|
|
28
|
+
const completionList = {
|
|
29
|
+
items: [],
|
|
30
|
+
isIncomplete: false,
|
|
31
|
+
};
|
|
32
|
+
completionList.items.push(...(0, snippets_js_1.getSnippetCompletions)(file.astroMeta.frontmatter));
|
|
33
|
+
return completionList;
|
|
34
|
+
},
|
|
35
|
+
resolveCompletionItem(item) {
|
|
36
|
+
return item;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.createTypescriptAddonsService = createTypescriptAddonsService;
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSnippetCompletions = void 0;
|
|
4
|
+
const language_server_1 = require("@volar/language-server");
|
|
5
|
+
function getSnippetCompletions(frontmatter) {
|
|
6
|
+
if (frontmatter.status === 'doesnt-exist')
|
|
7
|
+
return [];
|
|
8
|
+
const frontmatterStartPosition = {
|
|
9
|
+
line: frontmatter.position.start.line,
|
|
10
|
+
character: frontmatter.position.start.column - 1,
|
|
11
|
+
};
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
label: 'interface Props',
|
|
15
|
+
kind: language_server_1.CompletionItemKind.Snippet,
|
|
16
|
+
labelDetails: { description: 'Create a new interface to type your props' },
|
|
17
|
+
documentation: {
|
|
18
|
+
kind: 'markdown',
|
|
19
|
+
value: [
|
|
20
|
+
'Create a new interface to type your props.',
|
|
21
|
+
'\n',
|
|
22
|
+
'[Astro reference](https://docs.astro.build/en/guides/typescript/#component-props)',
|
|
23
|
+
].join('\n'),
|
|
24
|
+
},
|
|
25
|
+
insertTextFormat: 2,
|
|
26
|
+
filterText: 'interface props',
|
|
27
|
+
insertText: 'interface Props {\n\t$1\n}',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'getStaticPaths',
|
|
31
|
+
kind: language_server_1.CompletionItemKind.Snippet,
|
|
32
|
+
labelDetails: { description: 'Create a new getStaticPaths function' },
|
|
33
|
+
documentation: {
|
|
34
|
+
kind: 'markdown',
|
|
35
|
+
value: [
|
|
36
|
+
'Create a new getStaticPaths function.',
|
|
37
|
+
'\n',
|
|
38
|
+
'[Astro reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)',
|
|
39
|
+
].join('\n'),
|
|
40
|
+
},
|
|
41
|
+
insertText: 'export const getStaticPaths = (() => {\n\t$1\n\treturn [];\n}) satisfies GetStaticPaths;',
|
|
42
|
+
additionalTextEdits: [
|
|
43
|
+
language_server_1.TextEdit.insert(frontmatterStartPosition, 'import type { GetStaticPaths } from "astro";\n'),
|
|
44
|
+
],
|
|
45
|
+
filterText: 'getstaticpaths',
|
|
46
|
+
insertTextFormat: 2,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: 'prerender',
|
|
50
|
+
kind: language_server_1.CompletionItemKind.Snippet,
|
|
51
|
+
labelDetails: { description: 'Add prerender export' },
|
|
52
|
+
documentation: {
|
|
53
|
+
kind: 'markdown',
|
|
54
|
+
value: [
|
|
55
|
+
'Add prerender export. When [using server-side rendering](https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project), this value will be used to determine whether to prerender the page or not.',
|
|
56
|
+
'\n',
|
|
57
|
+
'[Astro reference](https://docs.astro.build/en/guides/server-side-rendering/#configuring-individual-routes)',
|
|
58
|
+
].join('\n'),
|
|
59
|
+
},
|
|
60
|
+
insertText: 'export const prerender = ${1|true,false,import.meta.env.|}',
|
|
61
|
+
insertTextFormat: 2,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
exports.getSnippetCompletions = getSnippetCompletions;
|
|
66
|
+
//# sourceMappingURL=snippets.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"prettier": "^3.0.0",
|
|
58
|
-
"prettier-plugin-astro": "
|
|
58
|
+
"prettier-plugin-astro": ">=0.11.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependenciesMeta": {
|
|
61
61
|
"prettier": {
|