@astrojs/language-server 2.9.1 → 2.11.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.
@@ -0,0 +1,3 @@
1
+ import type { Mapping } from '@volar/language-core';
2
+ import type { Segment } from 'muggle-string';
3
+ export declare function buildMappings<T>(chunks: Segment<T>[]): Mapping<T>[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildMappings = void 0;
4
+ function buildMappings(chunks) {
5
+ let length = 0;
6
+ const mappings = [];
7
+ for (const segment of chunks) {
8
+ if (typeof segment === 'string') {
9
+ length += segment.length;
10
+ }
11
+ else {
12
+ mappings.push({
13
+ sourceOffsets: [segment[2]],
14
+ generatedOffsets: [length],
15
+ lengths: [segment[0].length],
16
+ data: segment[3],
17
+ });
18
+ length += segment[0].length;
19
+ }
20
+ }
21
+ return mappings;
22
+ }
23
+ exports.buildMappings = buildMappings;
24
+ //# sourceMappingURL=buildMappings.js.map
package/dist/check.js CHANGED
@@ -56,9 +56,7 @@ 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
60
- ? fileNames
61
- : this.linter.language.typescript.projectHost.getScriptFileNames()).filter((file) => {
59
+ let files = (fileNames !== undefined ? fileNames : this.linter.projectHost.getScriptFileNames()).filter((file) => {
62
60
  // We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
63
61
  // So we don't want to check them here
64
62
  return !file.endsWith('.vue') && !file.endsWith('.svelte');
@@ -94,7 +92,7 @@ class AstroCheck {
94
92
  if (logErrors !== undefined && errorText) {
95
93
  console.info(errorText);
96
94
  }
97
- const fileSnapshot = this.linter.language.typescript.projectHost.getScriptSnapshot(file);
95
+ const fileSnapshot = this.linter.projectHost.getScriptSnapshot(file);
98
96
  const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
99
97
  result.fileResult.push({
100
98
  errors: fileDiagnostics,
@@ -115,17 +113,17 @@ class AstroCheck {
115
113
  this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
116
114
  const tsconfigPath = this.getTsconfig();
117
115
  const astroInstall = (0, utils_js_1.getAstroInstall)([this.workspacePath]);
118
- const languages = [
119
- (0, index_js_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts),
120
- (0, svelte_js_1.getSvelteLanguageModule)(),
121
- (0, vue_js_1.getVueLanguageModule)(),
116
+ const languagePlugins = [
117
+ (0, index_js_1.getAstroLanguagePlugin)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts),
118
+ (0, svelte_js_1.getSvelteLanguagePlugin)(),
119
+ (0, vue_js_1.getVueLanguagePlugin)(),
122
120
  ];
123
121
  const services = [...(0, index_js_2.create)(this.ts), (0, astro_js_1.create)(this.ts)];
124
122
  if (tsconfigPath) {
125
- this.linter = kit.createTypeScriptChecker(languages, services, tsconfigPath);
123
+ this.linter = kit.createTypeScriptChecker(languagePlugins, services, tsconfigPath);
126
124
  }
127
125
  else {
128
- this.linter = kit.createTypeScriptInferredChecker(languages, services, () => {
126
+ this.linter = kit.createTypeScriptInferredChecker(languagePlugins, services, () => {
129
127
  return fast_glob_1.default.sync('**/*.astro', {
130
128
  cwd: this.workspacePath,
131
129
  ignore: ['node_modules'],
@@ -2,9 +2,10 @@ import type { DiagnosticMessage } from '@astrojs/compiler/types';
2
2
  import { type CodeMapping, type LanguagePlugin, type VirtualCode } from '@volar/language-core';
3
3
  import type ts from 'typescript';
4
4
  import type { HTMLDocument } from 'vscode-html-languageservice';
5
+ import type { URI } from 'vscode-uri';
5
6
  import { type AstroInstall } from '../utils.js';
6
7
  import { AstroMetadata } from './parseAstro';
7
- export declare function getLanguageModule(astroInstall: AstroInstall | undefined, ts: typeof import('typescript')): LanguagePlugin<AstroVirtualCode>;
8
+ export declare function getAstroLanguagePlugin(astroInstall: AstroInstall | undefined, ts: typeof import('typescript')): LanguagePlugin<URI, AstroVirtualCode>;
8
9
  export declare class AstroVirtualCode implements VirtualCode {
9
10
  fileName: string;
10
11
  snapshot: ts.IScriptSnapshot;
@@ -19,6 +20,4 @@ export declare class AstroVirtualCode implements VirtualCode {
19
20
  codegenStacks: never[];
20
21
  constructor(fileName: string, snapshot: ts.IScriptSnapshot);
21
22
  get hasCompilationErrors(): boolean;
22
- update(newSnapshot: ts.IScriptSnapshot): void;
23
- onSnapshotUpdated(): void;
24
23
  }
@@ -23,35 +23,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.AstroVirtualCode = exports.getLanguageModule = void 0;
26
+ exports.AstroVirtualCode = exports.getAstroLanguagePlugin = void 0;
27
27
  const path = __importStar(require("node:path"));
28
28
  const language_core_1 = require("@volar/language-core");
29
- const vscode_uri_1 = require("vscode-uri");
30
29
  const utils_js_1 = require("../utils.js");
31
30
  const astro2tsx_1 = require("./astro2tsx");
32
31
  const parseAstro_1 = require("./parseAstro");
33
32
  const parseCSS_1 = require("./parseCSS");
34
33
  const parseHTML_1 = require("./parseHTML");
35
34
  const parseJS_js_1 = require("./parseJS.js");
36
- function getLanguageModule(astroInstall, ts) {
35
+ function getAstroLanguagePlugin(astroInstall, ts) {
37
36
  return {
38
- getLanguageId(scriptId) {
39
- if (scriptId.endsWith('.astro')) {
37
+ getLanguageId(uri) {
38
+ if (uri.path.endsWith('.astro')) {
40
39
  return 'astro';
41
40
  }
42
41
  },
43
- createVirtualCode(scriptId, languageId, snapshot) {
42
+ createVirtualCode(uri, languageId, snapshot) {
44
43
  if (languageId === 'astro') {
45
- const fileName = scriptId.includes('://')
46
- ? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
47
- : scriptId;
44
+ const fileName = uri.fsPath.replace(/\\/g, '/');
48
45
  return new AstroVirtualCode(fileName, snapshot);
49
46
  }
50
47
  },
51
- updateVirtualCode(_scriptId, astroCode, snapshot) {
52
- astroCode.update(snapshot);
53
- return astroCode;
54
- },
55
48
  typescript: {
56
49
  extraFileExtensions: [{ extension: 'astro', isMixedContent: true, scriptKind: 7 }],
57
50
  getServiceScript(astroCode) {
@@ -129,7 +122,7 @@ function getLanguageModule(astroInstall, ts) {
129
122
  },
130
123
  };
131
124
  }
132
- exports.getLanguageModule = getLanguageModule;
125
+ exports.getAstroLanguagePlugin = getAstroLanguagePlugin;
133
126
  class AstroVirtualCode {
134
127
  constructor(fileName, snapshot) {
135
128
  this.fileName = fileName;
@@ -137,16 +130,6 @@ class AstroVirtualCode {
137
130
  this.id = 'root';
138
131
  this.languageId = 'astro';
139
132
  this.codegenStacks = [];
140
- this.onSnapshotUpdated();
141
- }
142
- get hasCompilationErrors() {
143
- return this.compilerDiagnostics.filter((diag) => diag.severity === 1).length > 0;
144
- }
145
- update(newSnapshot) {
146
- this.snapshot = newSnapshot;
147
- this.onSnapshotUpdated();
148
- }
149
- onSnapshotUpdated() {
150
133
  this.mappings = [
151
134
  {
152
135
  sourceOffsets: [0],
@@ -182,6 +165,9 @@ class AstroVirtualCode {
182
165
  this.compilerDiagnostics.push(...tsx.diagnostics);
183
166
  this.embeddedCodes.push(tsx.virtualCode);
184
167
  }
168
+ get hasCompilationErrors() {
169
+ return this.compilerDiagnostics.filter((diag) => diag.severity === 1).length > 0;
170
+ }
185
171
  }
186
172
  exports.AstroVirtualCode = AstroVirtualCode;
187
173
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import type { ParseResult } from '@astrojs/compiler/types';
2
- import { type VirtualCode } from '@volar/language-core';
2
+ import type { VirtualCode } from '@volar/language-core';
3
3
  import type ts from 'typescript';
4
4
  import type { HTMLDocument } from 'vscode-html-languageservice';
5
5
  export declare function extractStylesheets(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.collectClassesAndIdsFromDocument = exports.extractStylesheets = void 0;
4
4
  const utils_1 = require("@astrojs/compiler/utils");
5
- const language_core_1 = require("@volar/language-core");
5
+ const muggle_string_1 = require("muggle-string");
6
+ const buildMappings_js_1 = require("../buildMappings.js");
6
7
  function extractStylesheets(snapshot, htmlDocument, ast) {
7
8
  const embeddedCSSCodes = findEmbeddedStyles(snapshot, htmlDocument.roots);
8
9
  const inlineStyles = findInlineStyles(ast);
@@ -25,8 +26,8 @@ function extractStylesheets(snapshot, htmlDocument, ast) {
25
26
  ]);
26
27
  codes.push(' }\n');
27
28
  }
28
- const mappings = (0, language_core_1.buildMappings)(codes);
29
- const text = (0, language_core_1.toString)(codes);
29
+ const mappings = (0, buildMappings_js_1.buildMappings)(codes);
30
+ const text = (0, muggle_string_1.toString)(codes);
30
31
  embeddedCSSCodes.push({
31
32
  id: 'inline.css',
32
33
  languageId: 'css',
@@ -1,5 +1,5 @@
1
1
  import type { ParseResult } from '@astrojs/compiler/types';
2
- import { type VirtualCode } from '@volar/language-core';
2
+ import type { VirtualCode } from '@volar/language-core';
3
3
  import type ts from 'typescript';
4
4
  import type { HTMLDocument } from 'vscode-html-languageservice';
5
5
  export declare function extractScriptTags(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractScriptTags = void 0;
4
4
  const utils_1 = require("@astrojs/compiler/utils");
5
- const language_core_1 = require("@volar/language-core");
5
+ const muggle_string_1 = require("muggle-string");
6
+ const buildMappings_1 = require("../buildMappings");
6
7
  function extractScriptTags(snapshot, htmlDocument, ast) {
7
8
  const embeddedJSCodes = findModuleScripts(snapshot, htmlDocument.roots);
8
9
  const javascriptContexts = [
@@ -168,8 +169,8 @@ function mergeJSContexts(javascriptContexts) {
168
169
  },
169
170
  ]);
170
171
  }
171
- const mappings = (0, language_core_1.buildMappings)(codes);
172
- const text = (0, language_core_1.toString)(codes);
172
+ const mappings = (0, buildMappings_1.buildMappings)(codes);
173
+ const text = (0, muggle_string_1.toString)(codes);
173
174
  return {
174
175
  id: 'inline.mjs',
175
176
  languageId: 'javascript',
@@ -1,6 +1,7 @@
1
1
  import { type CodeInformation, type LanguagePlugin, type Mapping, type VirtualCode } from '@volar/language-core';
2
2
  import type ts from 'typescript';
3
- export declare function getSvelteLanguageModule(): LanguagePlugin<SvelteVirtualCode>;
3
+ import type { URI } from 'vscode-uri';
4
+ export declare function getSvelteLanguagePlugin(): LanguagePlugin<URI, SvelteVirtualCode>;
4
5
  declare class SvelteVirtualCode implements VirtualCode {
5
6
  fileName: string;
6
7
  snapshot: ts.IScriptSnapshot;
@@ -10,7 +11,5 @@ declare class SvelteVirtualCode implements VirtualCode {
10
11
  embeddedCodes: VirtualCode[];
11
12
  codegenStacks: never[];
12
13
  constructor(fileName: string, snapshot: ts.IScriptSnapshot);
13
- update(newSnapshot: ts.IScriptSnapshot): void;
14
- private onSnapshotUpdated;
15
14
  }
16
15
  export {};
@@ -1,28 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSvelteLanguageModule = void 0;
3
+ exports.getSvelteLanguagePlugin = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const utils_js_1 = require("./utils.js");
7
- function getSvelteLanguageModule() {
6
+ function getSvelteLanguagePlugin() {
8
7
  return {
9
- getLanguageId(scriptId) {
10
- if (scriptId.endsWith('.svelte')) {
8
+ getLanguageId(uri) {
9
+ if (uri.path.endsWith('.svelte')) {
11
10
  return 'svelte';
12
11
  }
13
12
  },
14
- createVirtualCode(scriptId, languageId, snapshot) {
13
+ createVirtualCode(uri, languageId, snapshot) {
15
14
  if (languageId === 'svelte') {
16
- const fileName = scriptId.includes('://')
17
- ? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
18
- : scriptId;
15
+ const fileName = uri.fsPath.replace(/\\/g, '/');
19
16
  return new SvelteVirtualCode(fileName, snapshot);
20
17
  }
21
18
  },
22
- updateVirtualCode(_scriptId, svelteCode, snapshot) {
23
- svelteCode.update(snapshot);
24
- return svelteCode;
25
- },
26
19
  typescript: {
27
20
  extraFileExtensions: [{ extension: 'svelte', isMixedContent: true, scriptKind: 7 }],
28
21
  getServiceScript(svelteCode) {
@@ -39,7 +32,7 @@ function getSvelteLanguageModule() {
39
32
  },
40
33
  };
41
34
  }
42
- exports.getSvelteLanguageModule = getSvelteLanguageModule;
35
+ exports.getSvelteLanguagePlugin = getSvelteLanguagePlugin;
43
36
  class SvelteVirtualCode {
44
37
  constructor(fileName, snapshot) {
45
38
  this.fileName = fileName;
@@ -47,13 +40,6 @@ class SvelteVirtualCode {
47
40
  this.id = 'root';
48
41
  this.languageId = 'svelte';
49
42
  this.codegenStacks = [];
50
- this.onSnapshotUpdated();
51
- }
52
- update(newSnapshot) {
53
- this.snapshot = newSnapshot;
54
- this.onSnapshotUpdated();
55
- }
56
- onSnapshotUpdated() {
57
43
  this.mappings = [];
58
44
  this.embeddedCodes = [];
59
45
  this.embeddedCodes.push((0, utils_js_1.framework2tsx)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'svelte'));
@@ -1,6 +1,7 @@
1
1
  import { type CodeInformation, type LanguagePlugin, type Mapping, type VirtualCode } from '@volar/language-core';
2
2
  import type ts from 'typescript';
3
- export declare function getVueLanguageModule(): LanguagePlugin<VueVirtualCode>;
3
+ import type { URI } from 'vscode-uri';
4
+ export declare function getVueLanguagePlugin(): LanguagePlugin<URI, VueVirtualCode>;
4
5
  declare class VueVirtualCode implements VirtualCode {
5
6
  fileName: string;
6
7
  snapshot: ts.IScriptSnapshot;
@@ -10,7 +11,5 @@ declare class VueVirtualCode implements VirtualCode {
10
11
  embeddedCodes: VirtualCode[];
11
12
  codegenStacks: never[];
12
13
  constructor(fileName: string, snapshot: ts.IScriptSnapshot);
13
- update(newSnapshot: ts.IScriptSnapshot): void;
14
- private onSnapshotUpdated;
15
14
  }
16
15
  export {};
package/dist/core/vue.js CHANGED
@@ -1,28 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVueLanguageModule = void 0;
3
+ exports.getVueLanguagePlugin = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const utils_js_1 = require("./utils.js");
7
- function getVueLanguageModule() {
6
+ function getVueLanguagePlugin() {
8
7
  return {
9
- getLanguageId(scriptId) {
10
- if (scriptId.endsWith('.vue')) {
8
+ getLanguageId(uri) {
9
+ if (uri.path.endsWith('.vue')) {
11
10
  return 'vue';
12
11
  }
13
12
  },
14
- createVirtualCode(scriptId, languageId, snapshot) {
13
+ createVirtualCode(uri, languageId, snapshot) {
15
14
  if (languageId === 'vue') {
16
- const fileName = scriptId.includes('://')
17
- ? vscode_uri_1.URI.parse(scriptId).fsPath.replace(/\\/g, '/')
18
- : scriptId;
15
+ const fileName = uri.fsPath.replace(/\\/g, '/');
19
16
  return new VueVirtualCode(fileName, snapshot);
20
17
  }
21
18
  },
22
- updateVirtualCode(_scriptId, vueCode, snapshot) {
23
- vueCode.update(snapshot);
24
- return vueCode;
25
- },
26
19
  typescript: {
27
20
  extraFileExtensions: [{ extension: 'vue', isMixedContent: true, scriptKind: 7 }],
28
21
  getServiceScript(vueCode) {
@@ -39,7 +32,7 @@ function getVueLanguageModule() {
39
32
  },
40
33
  };
41
34
  }
42
- exports.getVueLanguageModule = getVueLanguageModule;
35
+ exports.getVueLanguagePlugin = getVueLanguagePlugin;
43
36
  class VueVirtualCode {
44
37
  constructor(fileName, snapshot) {
45
38
  this.fileName = fileName;
@@ -47,13 +40,6 @@ class VueVirtualCode {
47
40
  this.id = 'root';
48
41
  this.languageId = 'vue';
49
42
  this.codegenStacks = [];
50
- this.onSnapshotUpdated();
51
- }
52
- update(newSnapshot) {
53
- this.snapshot = newSnapshot;
54
- this.onSnapshotUpdated();
55
- }
56
- onSnapshotUpdated() {
57
43
  this.mappings = [];
58
44
  this.embeddedCodes = [];
59
45
  this.embeddedCodes.push((0, utils_js_1.framework2tsx)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'vue'));
@@ -1,3 +1,4 @@
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>[];
1
+ import { Connection, LanguagePlugin, LanguageServiceEnvironment } from '@volar/language-server/node';
2
+ import { URI } from 'vscode-uri';
3
+ export declare function getLanguagePlugins(connection: Connection, ts: typeof import('typescript'), serviceEnv: LanguageServiceEnvironment, tsconfig: string | undefined): LanguagePlugin<URI, import("@volar/language-server/node").VirtualCode>[];
3
4
  export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript')): import("@volar/language-server/node").LanguageServicePlugin<any>[];
@@ -19,12 +19,12 @@ const index_js_1 = require("./plugins/typescript-addons/index.js");
19
19
  const index_js_2 = require("./plugins/typescript/index.js");
20
20
  function getLanguagePlugins(connection, ts, serviceEnv, tsconfig) {
21
21
  const languagePlugins = [
22
- (0, vue_js_1.getVueLanguageModule)(),
23
- (0, svelte_js_1.getSvelteLanguageModule)(),
22
+ (0, vue_js_1.getVueLanguagePlugin)(),
23
+ (0, svelte_js_1.getSvelteLanguagePlugin)(),
24
24
  ];
25
25
  const rootPath = tsconfig
26
26
  ? tsconfig.split('/').slice(0, -1).join('/')
27
- : serviceEnv.typescript.uriToFileName(serviceEnv.workspaceFolder);
27
+ : serviceEnv.workspaceFolders[0].fsPath;
28
28
  const nearestPackageJson = ts.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
29
29
  const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
30
30
  nearestPackageJson: nearestPackageJson,
@@ -36,7 +36,7 @@ function getLanguagePlugins(connection, ts, serviceEnv, tsconfig) {
36
36
  type: node_1.MessageType.Warning,
37
37
  });
38
38
  }
39
- languagePlugins.unshift((0, core_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
39
+ languagePlugins.unshift((0, core_1.getAstroLanguagePlugin)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
40
40
  return languagePlugins;
41
41
  }
42
42
  exports.getLanguagePlugins = getLanguagePlugins;
@@ -56,24 +56,26 @@ function getLanguageServicePlugins(connection, ts) {
56
56
  let prettierPluginPath;
57
57
  let hasShownNotification = false;
58
58
  return (0, volar_service_prettier_1.create)((context) => {
59
- const workspaceUri = vscode_uri_1.URI.parse(context.env.workspaceFolder);
60
- if (workspaceUri.scheme === 'file') {
61
- prettier = (0, importPackage_js_1.importPrettier)(workspaceUri.fsPath);
62
- prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspaceUri.fsPath);
63
- if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
64
- connection.sendNotification(node_1.ShowMessageNotification.type, {
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.",
66
- type: node_1.MessageType.Warning,
67
- });
68
- hasShownNotification = true;
59
+ for (const workspaceFolder of context.env.workspaceFolders) {
60
+ if (workspaceFolder.scheme === 'file') {
61
+ prettier = (0, importPackage_js_1.importPrettier)(workspaceFolder.fsPath);
62
+ prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspaceFolder.fsPath);
63
+ if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
64
+ connection.sendNotification(node_1.ShowMessageNotification.type, {
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.",
66
+ type: node_1.MessageType.Warning,
67
+ });
68
+ hasShownNotification = true;
69
+ }
70
+ return prettier;
69
71
  }
70
- return prettier;
71
72
  }
72
73
  }, {
73
74
  documentSelector: ['astro'],
74
75
  getFormattingOptions: async (prettierInstance, document, formatOptions, context) => {
75
- const documentUri = context.decodeEmbeddedDocumentUri(document.uri)?.[0] ?? document.uri;
76
- const filePath = vscode_uri_1.URI.parse(documentUri).fsPath;
76
+ const uri = vscode_uri_1.URI.parse(document.uri);
77
+ const documentUri = context.decodeEmbeddedDocumentUri(uri)?.[0] ?? uri;
78
+ const filePath = documentUri.fsPath;
77
79
  if (!filePath) {
78
80
  return {};
79
81
  }
@@ -11,7 +11,12 @@ 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, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript), (0, node_1.createTypeScriptProjectProvider)(typescript, diagnosticMessages, (env, project) => (0, languageServerPlugin_js_1.getLanguagePlugins)(connection, typescript, env, project.configFileName)));
14
+ return server.initialize(params, (0, node_1.createTypeScriptProject)(typescript, diagnosticMessages, ({ env, configFileName }) => {
15
+ return {
16
+ languagePlugins: (0, languageServerPlugin_js_1.getLanguagePlugins)(connection, typescript, env, configFileName),
17
+ setup() { },
18
+ };
19
+ }), (0, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript), { pullModelDiagnostics: params.initializationOptions?.pullModelDiagnostics });
15
20
  });
16
21
  connection.onInitialized(() => {
17
22
  server.initialized();
@@ -7,18 +7,25 @@ exports.create = void 0;
7
7
  const node_path_1 = require("node:path");
8
8
  const language_server_1 = require("@volar/language-server");
9
9
  const fast_glob_1 = __importDefault(require("fast-glob"));
10
+ const vscode_uri_1 = require("vscode-uri");
10
11
  const index_js_1 = require("../core/index.js");
11
12
  const utils_js_1 = require("./utils.js");
12
13
  const create = (ts) => {
13
14
  return {
14
- triggerCharacters: ['-'],
15
+ capabilities: {
16
+ completionProvider: {
17
+ triggerCharacters: ['-'],
18
+ },
19
+ diagnosticProvider: {},
20
+ codeLensProvider: {},
21
+ },
15
22
  create(context) {
16
23
  return {
17
24
  provideCompletionItems(document, position, completionContext, token) {
18
25
  if (token.isCancellationRequested)
19
26
  return null;
20
27
  let items = [];
21
- const decoded = context.decodeEmbeddedDocumentUri(document.uri);
28
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
22
29
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
23
30
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
24
31
  if (!(virtualCode instanceof index_js_1.AstroVirtualCode))
@@ -36,7 +43,7 @@ const create = (ts) => {
36
43
  provideSemanticDiagnostics(document, token) {
37
44
  if (token.isCancellationRequested)
38
45
  return [];
39
- const decoded = context.decodeEmbeddedDocumentUri(document.uri);
46
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
40
47
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
41
48
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
42
49
  if (!(virtualCode instanceof index_js_1.AstroVirtualCode))
@@ -59,6 +66,9 @@ const create = (ts) => {
59
66
  return;
60
67
  if (!(0, utils_js_1.isJSDocument)(document.languageId))
61
68
  return;
69
+ if (!context.project.typescript)
70
+ return;
71
+ const { uriConverter } = context.project.typescript;
62
72
  const languageService = context.inject('typescript/languageService');
63
73
  if (!languageService)
64
74
  return;
@@ -72,7 +82,7 @@ const create = (ts) => {
72
82
  if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
73
83
  const globArgument = node.arguments.at(0);
74
84
  if (globArgument) {
75
- globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(context.env.typescript.uriToFileName(document.uri)), document.positionAt(node.arguments.pos)));
85
+ globcodeLens.push(getGlobResultAsCodeLens(globArgument.getText().slice(1, -1), (0, node_path_1.dirname)(uriConverter.asFileName(vscode_uri_1.URI.parse(document.uri))), document.positionAt(node.arguments.pos)));
76
86
  }
77
87
  }
78
88
  return ts.forEachChild(node, cb);
@@ -32,20 +32,23 @@ const index_js_1 = require("../core/index.js");
32
32
  const html_data_js_1 = require("./html-data.js");
33
33
  const utils_js_1 = require("./utils.js");
34
34
  const create = () => {
35
- const htmlServicePlugin = (0, volar_service_html_1.create)({
35
+ const htmlPlugin = (0, volar_service_html_1.create)({
36
36
  getCustomData: async (context) => {
37
37
  const customData = (await context.env.getConfiguration?.('html.customData')) ?? [];
38
38
  const newData = [];
39
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);
40
+ for (const workspaceFolder of context.env.workspaceFolders) {
41
+ const uri = vscode_uri_1.Utils.resolvePath(workspaceFolder, customDataPath);
42
+ const json = await context.env.fs?.readFile?.(uri);
43
+ if (json) {
44
+ try {
45
+ const data = JSON.parse(json);
46
+ newData.push(html.newHTMLDataProvider(customDataPath, data));
47
+ }
48
+ catch (error) {
49
+ console.error(error);
50
+ }
51
+ break;
49
52
  }
50
53
  }
51
54
  }
@@ -53,15 +56,15 @@ const create = () => {
53
56
  },
54
57
  });
55
58
  return {
56
- ...htmlServicePlugin,
59
+ ...htmlPlugin,
57
60
  create(context) {
58
- const htmlPlugin = htmlServicePlugin.create(context);
61
+ const htmlPluginInstance = htmlPlugin.create(context);
59
62
  return {
60
- ...htmlPlugin,
63
+ ...htmlPluginInstance,
61
64
  async provideCompletionItems(document, position, completionContext, token) {
62
65
  if (document.languageId !== 'html')
63
66
  return;
64
- const decoded = context.decodeEmbeddedDocumentUri(document.uri);
67
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
65
68
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
66
69
  const root = sourceScript?.generated?.root;
67
70
  if (!(root instanceof index_js_1.AstroVirtualCode))
@@ -70,7 +73,7 @@ const create = () => {
70
73
  if ((0, utils_js_1.isInComponentStartTag)(root.htmlDocument, document.offsetAt(position))) {
71
74
  return null;
72
75
  }
73
- const completions = await htmlPlugin.provideCompletionItems(document, position, completionContext, token);
76
+ const completions = await htmlPluginInstance.provideCompletionItems(document, position, completionContext, token);
74
77
  if (!completions) {
75
78
  return null;
76
79
  }
@@ -1,3 +1,3 @@
1
- import type { CodeAction, ServiceContext } from '@volar/language-service';
2
- export declare function enhancedProvideCodeActions(codeActions: CodeAction[], context: ServiceContext): CodeAction[];
3
- export declare function enhancedResolveCodeAction(codeAction: CodeAction, context: ServiceContext): CodeAction;
1
+ import type { CodeAction, LanguageServiceContext } from '@volar/language-service';
2
+ export declare function enhancedProvideCodeActions(codeActions: CodeAction[], context: LanguageServiceContext): CodeAction[];
3
+ export declare function enhancedResolveCodeAction(codeAction: CodeAction, context: LanguageServiceContext): CodeAction;
@@ -2,6 +2,7 @@
2
2
  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
+ const vscode_uri_1 = require("vscode-uri");
5
6
  const index_js_1 = require("../../core/index.js");
6
7
  const utils_js_1 = require("./utils.js");
7
8
  function enhancedProvideCodeActions(codeActions, context) {
@@ -22,7 +23,7 @@ function mapCodeAction(codeAction, context) {
22
23
  return codeAction;
23
24
  codeAction.edit.documentChanges = codeAction.edit.documentChanges.map((change) => {
24
25
  if (language_server_1.TextDocumentEdit.is(change)) {
25
- const decoded = context.decodeEmbeddedDocumentUri(change.textDocument.uri);
26
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(change.textDocument.uri));
26
27
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
27
28
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
28
29
  const root = sourceScript?.generated?.root;
@@ -1,3 +1,3 @@
1
- import { CompletionItem, CompletionList, ServiceContext } from '@volar/language-server';
1
+ import { CompletionItem, CompletionList, LanguageServiceContext } from '@volar/language-server';
2
2
  export declare function enhancedProvideCompletionItems(completions: CompletionList): CompletionList;
3
- export declare function enhancedResolveCompletionItem(resolvedCompletion: CompletionItem, context: ServiceContext): CompletionItem;
3
+ export declare function enhancedResolveCompletionItem(resolvedCompletion: CompletionItem, context: LanguageServiceContext): CompletionItem;
@@ -2,6 +2,7 @@
2
2
  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
+ const vscode_uri_1 = require("vscode-uri");
5
6
  const index_js_1 = require("../../core/index.js");
6
7
  const utils_js_1 = require("./utils.js");
7
8
  function enhancedProvideCompletionItems(completions) {
@@ -31,7 +32,7 @@ function enhancedResolveCompletionItem(resolvedCompletion, context) {
31
32
  resolvedCompletion.detail = getDetailForFileCompletion(resolvedCompletion.detail ?? '', resolvedCompletion.data.originalItem.source);
32
33
  }
33
34
  if (resolvedCompletion.additionalTextEdits) {
34
- const decoded = context.decodeEmbeddedDocumentUri(resolvedCompletion.data.uri);
35
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(resolvedCompletion.data.uri));
35
36
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
36
37
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
37
38
  const root = sourceScript?.generated?.root;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
4
  const volar_service_typescript_1 = require("volar-service-typescript");
5
+ const vscode_uri_1 = require("vscode-uri");
5
6
  const index_js_1 = require("../../core/index.js");
6
7
  const codeActions_js_1 = require("./codeActions.js");
7
8
  const completions_js_1 = require("./completions.js");
@@ -41,7 +42,7 @@ const create = (ts) => {
41
42
  return (0, codeActions_js_1.enhancedResolveCodeAction)(resolvedCodeAction, context);
42
43
  },
43
44
  async provideSemanticDiagnostics(document, token) {
44
- const decoded = context.decodeEmbeddedDocumentUri(document.uri);
45
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
45
46
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
46
47
  const root = sourceScript?.generated?.root;
47
48
  let tsxLineCount = undefined;
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
+ const vscode_uri_1 = require("vscode-uri");
4
5
  const index_js_1 = require("../../core/index.js");
5
6
  const utils_js_1 = require("../utils.js");
6
7
  const snippets_js_1 = require("./snippets.js");
7
8
  const create = () => {
8
9
  return {
10
+ capabilities: {
11
+ completionProvider: {
12
+ resolveProvider: true,
13
+ },
14
+ },
9
15
  create(context) {
10
16
  return {
11
17
  isAdditionalCompletion: true,
@@ -21,7 +27,7 @@ const create = () => {
21
27
  token.isCancellationRequested ||
22
28
  completionContext.triggerKind === 2)
23
29
  return null;
24
- const decoded = context.decodeEmbeddedDocumentUri(document.uri);
30
+ const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
25
31
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
26
32
  const root = sourceScript?.generated?.root;
27
33
  if (!(root instanceof index_js_1.AstroVirtualCode))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "2.9.1",
3
+ "version": "2.11.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,32 +22,33 @@
22
22
  "dependencies": {
23
23
  "@astrojs/compiler": "^2.7.0",
24
24
  "@jridgewell/sourcemap-codec": "^1.4.15",
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",
25
+ "@volar/kit": "~2.4.0-alpha.15",
26
+ "@volar/language-core": "~2.4.0-alpha.15",
27
+ "@volar/language-server": "~2.4.0-alpha.15",
28
+ "@volar/language-service": "~2.4.0-alpha.15",
29
+ "@volar/typescript": "~2.4.0-alpha.15",
30
30
  "fast-glob": "^3.2.12",
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",
31
+ "muggle-string": "^0.4.1",
32
+ "volar-service-css": "volar-2.4",
33
+ "volar-service-emmet": "volar-2.4",
34
+ "volar-service-html": "volar-2.4",
35
+ "volar-service-prettier": "volar-2.4",
36
+ "volar-service-typescript": "volar-2.4",
37
+ "volar-service-typescript-twoslash-queries": "volar-2.4",
37
38
  "vscode-html-languageservice": "^5.2.0",
38
39
  "vscode-uri": "^3.0.8"
39
40
  },
40
41
  "devDependencies": {
41
- "svelte": "^4.2.10",
42
42
  "@astrojs/svelte": "^5.0.3",
43
43
  "@astrojs/vue": "^4.0.8",
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.2.1",
47
+ "@volar/test-utils": "~2.4.0-alpha.15",
48
48
  "astro": "^4.3.5",
49
49
  "chai": "^4.3.7",
50
50
  "mocha": "^10.2.0",
51
+ "svelte": "^4.2.10",
51
52
  "tsx": "^3.12.7",
52
53
  "typescript": "^5.2.2",
53
54
  "vscode-languageserver-protocol": "^3.17.5",