@astrojs/language-server 2.6.2 → 2.7.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/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
- createVirtualFile(fileName, snapshot) {
9
- if (fileName.endsWith('.vue')) {
10
- return new VueFile(fileName, snapshot);
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
- updateVirtualFile(vueFile, snapshot) {
14
- vueFile.update(snapshot);
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 VueFile {
20
- constructor(sourceFileName, snapshot) {
21
- this.sourceFileName = sourceFileName;
35
+ class VueVirtualCode {
36
+ constructor(fileName, snapshot) {
37
+ this.fileName = fileName;
22
38
  this.snapshot = snapshot;
23
- this.kind = language_core_1.FileKind.TextFile;
24
- this.capabilities = language_core_1.FileCapabilities.full;
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
- sourceRange: [0, this.snapshot.getLength()],
37
- generatedRange: [0, this.snapshot.getLength()],
38
- data: language_core_1.FileRangeCapabilities.full,
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.embeddedFiles = [];
42
- this.embeddedFiles.push((0, utils_js_1.framework2tsx)(this.fileName, this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'vue'));
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 { LanguageServerPlugin } from '@volar/language-server/node';
2
- export declare const plugin: LanguageServerPlugin;
1
+ import { Connection } from '@volar/language-server/node';
2
+ import type { createServerBase, ServerOptions } 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.plugin = void 0;
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
- const plugin = (initOptions, modules) => ({
20
- extraFileExtensions: [
21
- { extension: 'astro', isMixedContent: true, scriptKind: 7 },
22
- { extension: 'vue', isMixedContent: true, scriptKind: 7 },
23
- { extension: 'svelte', isMixedContent: true, scriptKind: 7 },
24
- ],
25
- watchFileExtensions: [
26
- 'js',
27
- 'cjs',
28
- 'mjs',
29
- 'ts',
30
- 'cts',
31
- 'mts',
32
- 'jsx',
33
- 'tsx',
34
- 'json',
35
- 'astro',
36
- 'vue',
37
- 'svelte',
38
- ],
39
- resolveConfig(config, ctx) {
40
- config.languages ??= {};
41
- if (ctx) {
42
- const nearestPackageJson = modules.typescript?.findConfigFile(ctx.project.rootUri.fsPath, modules.typescript.sys.fileExists, 'package.json');
43
- const astroInstall = (0, utils_js_1.getAstroInstall)([ctx.project.rootUri.fsPath], {
44
- nearestPackageJson: nearestPackageJson,
45
- readDirectory: modules.typescript.sys.readDirectory,
46
- });
47
- if (astroInstall === 'not-found') {
48
- ctx.server.connection.sendNotification(node_1.ShowMessageNotification.type, {
49
- message: `Couldn't find Astro in workspace "${ctx.project.rootUri.fsPath}". Experience might be degraded. For the best experience, please make sure Astro is installed into your project and restart the language server.`,
50
- type: node_1.MessageType.Warning,
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
- config.languages.astro = (0, core_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, modules.typescript);
54
- config.languages.vue = (0, vue_js_1.getVueLanguageModule)();
55
- config.languages.svelte = (0, svelte_js_1.getSvelteLanguageModule)();
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
- config.services ??= {};
58
- config.services.html ??= (0, html_js_1.create)();
59
- config.services.css ??= (0, volar_service_css_1.create)();
60
- config.services.emmet ??= (0, volar_service_emmet_1.create)();
61
- config.services.typescript ??= (0, index_js_2.create)();
62
- config.services.typescripttwoslash ??= (0, volar_service_typescript_twoslash_queries_1.create)();
63
- config.services.typescriptaddons ??= (0, index_js_1.create)();
64
- config.services.astro ??= (0, astro_js_1.create)();
65
- if (ctx) {
66
- const rootDir = ctx.env.uriToFileName(ctx.project.rootUri.toString());
67
- const prettier = (0, importPackage_js_1.importPrettier)(rootDir);
68
- const prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(rootDir);
69
- if (prettier && prettierPluginPath) {
70
- config.services.prettier ??= (0, volar_service_prettier_1.create)({
71
- prettier: prettier,
72
- languages: ['astro'],
73
- ignoreIdeOptions: true,
74
- useIdeOptionsFallback: true,
75
- resolveConfigOptions: {
76
- // This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
77
- useCache: false,
78
- },
79
- additionalOptions: async (resolvedConfig) => {
80
- async function getAstroPrettierPlugin() {
81
- if (!prettier || !prettierPluginPath) {
82
- return [];
83
- }
84
- const hasPluginLoadedAlready = (await prettier.getSupportInfo()).languages.some((l) => l.name === 'astro') ||
85
- resolvedConfig.plugins?.includes('prettier-plugin-astro'); // getSupportInfo doesn't seems to work very well in Prettier 3 for plugins
86
- return hasPluginLoadedAlready ? [] : [prettierPluginPath];
87
- }
88
- const plugins = [
89
- ...(await getAstroPrettierPlugin()),
90
- ...(resolvedConfig.plugins ?? []),
91
- ];
92
- return {
93
- ...resolvedConfig,
94
- plugins: plugins,
95
- parser: 'astro',
96
- };
97
- },
98
- });
99
- }
100
- else {
101
- ctx.server.connection.sendNotification(node_1.ShowMessageNotification.type, {
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
@@ -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
- (0, node_1.startLanguageServer)((0, node_1.createConnection)(), languageServerPlugin_js_1.plugin);
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
@@ -1,2 +1,2 @@
1
- import { Service } from '@volar/language-server';
2
- export declare const create: () => Service;
1
+ import { ServicePlugin } from '@volar/language-server';
2
+ export declare const create: (ts: typeof import('typescript')) => ServicePlugin;
@@ -9,70 +9,73 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
9
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 = () => (context, modules) => {
12
+ const create = (ts) => {
13
13
  return {
14
14
  triggerCharacters: ['-'],
15
- provideCompletionItems(document, position, completionContext, token) {
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
- isIncomplete: false,
29
- items: items,
30
- };
31
- },
32
- provideSemanticDiagnostics(document, token) {
33
- if (token.isCancellationRequested)
34
- return [];
35
- const [file] = context.documents.getVirtualFileByUri(document.uri);
36
- if (!(file instanceof index_js_1.AstroFile))
37
- return;
38
- return file.compilerDiagnostics.map(compilerMessageToDiagnostic);
39
- function compilerMessageToDiagnostic(message) {
40
- return {
41
- message: message.text + (message.hint ? '\n\n' + message.hint : ''),
42
- range: language_server_1.Range.create(message.location.line - 1, message.location.column - 1, message.location.line, message.location.length),
43
- code: message.code,
44
- severity: message.severity,
45
- source: 'astro',
46
- };
47
- }
48
- },
49
- provideCodeLenses(document, token) {
50
- if (token.isCancellationRequested)
51
- return;
52
- if (!context || !modules?.typescript || !(0, utils_js_1.isJSDocument)(document.languageId))
53
- return;
54
- const languageService = context.inject('typescript/languageService');
55
- if (!languageService)
56
- return;
57
- const ts = modules?.typescript;
58
- const tsProgram = languageService.getProgram();
59
- if (!tsProgram)
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);
70
28
  }
71
- return ts.forEachChild(node, cb);
72
- });
73
- }
74
- walk();
75
- return globcodeLens;
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
+ };
49
+ }
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
  };
@@ -183,7 +183,17 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
183
183
  },
184
184
  {
185
185
  name: 'transition:name',
186
- description: 'Specifies a `view-transition-name` for this element. The name should be unique on the page.',
186
+ description: 'Specifies a `view-transition-name` for this element. The name must be unique on the page.',
187
+ references: [
188
+ {
189
+ name: 'Astro reference',
190
+ url: 'https://docs.astro.build/en/guides/view-transitions/#transition-directives',
191
+ },
192
+ ],
193
+ },
194
+ {
195
+ name: 'transition:persist',
196
+ description: 'Marks this element to be moved to the next page during view transitions.',
187
197
  references: [
188
198
  {
189
199
  name: 'Astro reference',
@@ -1,2 +1,2 @@
1
- import { Service } from '@volar/language-server';
2
- export declare const create: () => Service;
1
+ import { ServicePlugin } from '@volar/language-server';
2
+ export declare const create: () => ServicePlugin;
@@ -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 = __importDefault(require("volar-service-html"));
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 = () => (context, modules) => {
13
- const htmlPlugin = (0, volar_service_html_1.default)()(context, modules);
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
- ...htmlPlugin,
24
- async provideCompletionItems(document, position, completionContext, token) {
25
- if (document.languageId !== 'html')
26
- return;
27
- const [_, source] = context.documents.getVirtualFileByUri(document.uri);
28
- const rootVirtualFile = source?.root;
29
- if (!(rootVirtualFile instanceof index_js_1.AstroFile))
30
- return;
31
- // Don't return completions if the current node is a component
32
- if ((0, utils_js_1.isInComponentStartTag)(rootVirtualFile.htmlDocument, document.offsetAt(position))) {
33
- return null;
34
- }
35
- const completions = await htmlPlugin.provideCompletionItems(document, position, completionContext, token);
36
- if (!completions) {
37
- return null;
38
- }
39
- // We don't want completions for file references, as they're mostly invalid for Astro
40
- completions.items = completions.items.filter((completion) => completion.kind !== language_server_1.CompletionItemKind.File);
41
- return completions;
42
- },
43
- // Document links provided by `vscode-html-languageservice` are invalid for Astro
44
- provideDocumentLinks() {
45
- return [];
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.getVirtualFileByUri(change.textDocument.uri);
26
- const file = source?.root;
27
- if (!virtualFile || !(file instanceof index_js_1.AstroFile) || !context.host)
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, file.astroMeta);
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, file.astroMeta, '\n');
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.getVirtualFileByUri(resolvedCompletion.data.uri);
35
- const file = source?.root;
36
- if (!virtualFile || !(file instanceof index_js_1.AstroFile) || !context.host)
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, file.astroMeta).itShould) {
40
- edit = (0, utils_js_1.ensureProperEditForFrontmatter)(edit, file.astroMeta, '\n');
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 { Service } from '@volar/language-server';
2
- export declare const create: () => Service;
1
+ import type { ServicePlugin } from '@volar/language-server';
2
+ export declare const create: (ts: typeof import('typescript')) => ServicePlugin;