@astrojs/language-server 2.7.7 → 2.8.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.js CHANGED
@@ -118,7 +118,7 @@ class AstroCheck {
118
118
  (0, svelte_js_1.getSvelteLanguageModule)(),
119
119
  (0, vue_js_1.getVueLanguageModule)(),
120
120
  ];
121
- const services = [(0, index_js_2.create)(this.ts), (0, astro_js_1.create)(this.ts)];
121
+ const services = [...(0, index_js_2.create)(this.ts), (0, astro_js_1.create)(this.ts)];
122
122
  if (tsconfigPath) {
123
123
  this.linter = kit.createTypeScriptChecker(languages, services, tsconfigPath);
124
124
  }
@@ -40,7 +40,7 @@ export declare function safeConvertToTSX(content: string, options: ConvertToTSXO
40
40
  };
41
41
  export declare function getTSXRangesAsLSPRanges(tsx: TSXResult): LSPTSXRanges;
42
42
  export declare function astro2tsx(input: string, fileName: string, htmlDocument: HTMLDocument): {
43
- virtualCode: VirtualCode<string>;
43
+ virtualCode: VirtualCode;
44
44
  diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {
45
45
  code: 1000;
46
46
  location: {
@@ -168,6 +168,7 @@ class AstroVirtualCode {
168
168
  this.htmlDocument = htmlDocument;
169
169
  const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.snapshot, htmlDocument, astroMetadata.ast);
170
170
  this.scriptCodeIds = scriptTags.map((scriptTag) => scriptTag.id);
171
+ htmlVirtualCode.embeddedCodes = [];
171
172
  htmlVirtualCode.embeddedCodes.push(...(0, parseCSS_1.extractStylesheets)(this.snapshot, htmlDocument, astroMetadata.ast), ...scriptTags);
172
173
  this.embeddedCodes = [];
173
174
  this.embeddedCodes.push(htmlVirtualCode);
@@ -1,3 +1,3 @@
1
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;
2
+ import type { ServerOptions } from '@volar/language-server/lib/server.js';
3
+ export declare function createServerOptions(connection: Connection, ts: typeof import('typescript')): ServerOptions;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createServerOptions = void 0;
4
4
  const node_1 = require("@volar/language-server/node");
5
+ const vscode_uri_1 = require("vscode-uri");
5
6
  const core_1 = require("./core");
6
7
  const svelte_js_1 = require("./core/svelte.js");
7
8
  const vue_js_1 = require("./core/vue.js");
@@ -16,7 +17,7 @@ const astro_js_1 = require("./plugins/astro.js");
16
17
  const html_js_1 = require("./plugins/html.js");
17
18
  const index_js_1 = require("./plugins/typescript-addons/index.js");
18
19
  const index_js_2 = require("./plugins/typescript/index.js");
19
- function createServerOptions(connection, server) {
20
+ function createServerOptions(connection, ts) {
20
21
  return {
21
22
  watchFileExtensions: [
22
23
  'js',
@@ -33,20 +34,18 @@ function createServerOptions(connection, server) {
33
34
  'svelte',
34
35
  ],
35
36
  getServicePlugins() {
36
- const ts = getTypeScriptModule();
37
37
  return [
38
38
  (0, html_js_1.create)(),
39
39
  (0, volar_service_css_1.create)(),
40
40
  (0, volar_service_emmet_1.create)(),
41
- (0, index_js_2.create)(ts),
42
- (0, volar_service_typescript_twoslash_queries_1.create)(),
41
+ ...(0, index_js_2.create)(ts),
42
+ (0, volar_service_typescript_twoslash_queries_1.create)(ts),
43
43
  (0, index_js_1.create)(),
44
44
  (0, astro_js_1.create)(ts),
45
45
  getPrettierService(),
46
46
  ];
47
47
  },
48
48
  getLanguagePlugins(serviceEnv, projectContext) {
49
- const ts = getTypeScriptModule();
50
49
  const languagePlugins = [
51
50
  (0, vue_js_1.getVueLanguageModule)(),
52
51
  (0, svelte_js_1.getSvelteLanguageModule)(),
@@ -55,7 +54,7 @@ function createServerOptions(connection, server) {
55
54
  const rootPath = projectContext.typescript.configFileName
56
55
  ? projectContext.typescript.configFileName.split('/').slice(0, -1).join('/')
57
56
  : serviceEnv.typescript.uriToFileName(serviceEnv.workspaceFolder);
58
- const nearestPackageJson = server.modules.typescript?.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
57
+ const nearestPackageJson = ts.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
59
58
  const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
60
59
  nearestPackageJson: nearestPackageJson,
61
60
  readDirectory: ts.sys.readDirectory,
@@ -71,21 +70,14 @@ function createServerOptions(connection, server) {
71
70
  return languagePlugins;
72
71
  },
73
72
  };
74
- function getTypeScriptModule() {
75
- const tsModule = server.modules.typescript;
76
- if (!tsModule) {
77
- throw new Error('TypeScript module is missing');
78
- }
79
- return tsModule;
80
- }
81
73
  function getPrettierService() {
82
74
  let prettier;
83
75
  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);
76
+ return (0, volar_service_prettier_1.create)((context) => {
77
+ const workspaceUri = vscode_uri_1.URI.parse(context.env.workspaceFolder);
78
+ if (workspaceUri.scheme === 'file') {
79
+ prettier = (0, importPackage_js_1.importPrettier)(workspaceUri.fsPath);
80
+ prettierPluginPath = (0, importPackage_js_1.getPrettierPluginPath)(workspaceUri.fsPath);
89
81
  if (!prettier || !prettierPluginPath) {
90
82
  connection.sendNotification(node_1.ShowMessageNotification.type, {
91
83
  message: "Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
@@ -93,15 +85,32 @@ function createServerOptions(connection, server) {
93
85
  });
94
86
  }
95
87
  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) => {
88
+ }
89
+ }, {
90
+ documentSelector: ['astro'],
91
+ getFormattingOptions: async (prettier, document, formatOptions, context) => {
92
+ const filePath = vscode_uri_1.URI.parse(document.uri).fsPath;
93
+ const configOptions = await prettier.resolveConfig(filePath, {
94
+ // This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
95
+ useCache: false,
96
+ });
97
+ const editorOptions = await context.env.getConfiguration?.('prettier', document.uri);
98
+ // Return a config with the following cascade:
99
+ // - Prettier config file should always win if it exists, if it doesn't:
100
+ // - Prettier config from the VS Code extension is used, if it doesn't exist:
101
+ // - Use the editor's basic configuration settings
102
+ const resolvedConfig = {
103
+ filepath: filePath,
104
+ tabWidth: formatOptions.tabSize,
105
+ useTabs: !formatOptions.insertSpaces,
106
+ ...editorOptions,
107
+ ...configOptions,
108
+ };
109
+ return {
110
+ ...resolvedConfig,
111
+ plugins: [...(await getAstroPrettierPlugin()), ...(resolvedConfig.plugins ?? [])],
112
+ parser: 'astro',
113
+ };
105
114
  async function getAstroPrettierPlugin() {
106
115
  if (!prettier || !prettierPluginPath) {
107
116
  return [];
@@ -110,12 +119,6 @@ function createServerOptions(connection, server) {
110
119
  resolvedConfig.plugins?.includes('prettier-plugin-astro'); // getSupportInfo doesn't seems to work very well in Prettier 3 for plugins
111
120
  return hasPluginLoadedAlready ? [] : [prettierPluginPath];
112
121
  }
113
- const plugins = [...(await getAstroPrettierPlugin()), ...(resolvedConfig.plugins ?? [])];
114
- return {
115
- ...resolvedConfig,
116
- plugins: plugins,
117
- parser: 'astro',
118
- };
119
122
  },
120
123
  });
121
124
  }
@@ -6,7 +6,12 @@ const connection = (0, node_1.createConnection)();
6
6
  const server = (0, node_1.createServer)(connection);
7
7
  connection.listen();
8
8
  connection.onInitialize((params) => {
9
- return server.initialize(params, node_1.createTypeScriptProjectProvider, (0, languageServerPlugin_js_1.createServerOptions)(connection, server));
9
+ const tsdk = params.initializationOptions?.typescript?.tsdk;
10
+ if (!tsdk) {
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
+ }
13
+ const { typescript, diagnosticMessages } = (0, node_1.loadTsdkByPath)(tsdk, params.locale);
14
+ return server.initialize(params, (0, node_1.createTypeScriptProjectProviderFactory)(typescript, diagnosticMessages), (0, languageServerPlugin_js_1.createServerOptions)(connection, typescript));
10
15
  });
11
16
  connection.onInitialized(() => {
12
17
  server.initialized();
@@ -1,2 +1,2 @@
1
1
  import type { ServicePlugin } from '@volar/language-server';
2
- export declare const create: (ts: typeof import('typescript')) => ServicePlugin;
2
+ export declare const create: (ts: typeof import('typescript')) => ServicePlugin[];
@@ -7,56 +7,61 @@ const codeActions_js_1 = require("./codeActions.js");
7
7
  const completions_js_1 = require("./completions.js");
8
8
  const diagnostics_js_1 = require("./diagnostics.js");
9
9
  const create = (ts) => {
10
- const tsServicePlugin = (0, volar_service_typescript_1.create)(ts);
11
- return {
12
- ...tsServicePlugin,
13
- create(context) {
14
- const typeScriptPlugin = tsServicePlugin.create(context);
10
+ const tsServicePlugins = (0, volar_service_typescript_1.create)(ts, {});
11
+ return tsServicePlugins.map((plugin) => {
12
+ if (plugin.name === 'typescript-semantic') {
15
13
  return {
16
- ...typeScriptPlugin,
17
- async provideCompletionItems(document, position, completionContext, token) {
18
- const originalCompletions = await typeScriptPlugin.provideCompletionItems(document, position, completionContext, token);
19
- if (!originalCompletions)
20
- return null;
21
- return (0, completions_js_1.enhancedProvideCompletionItems)(originalCompletions);
22
- },
23
- async resolveCompletionItem(item, token) {
24
- const resolvedCompletionItem = await typeScriptPlugin.resolveCompletionItem(item, token);
25
- if (!resolvedCompletionItem)
26
- return item;
27
- return (0, completions_js_1.enhancedResolveCompletionItem)(resolvedCompletionItem, context);
28
- },
29
- async provideCodeActions(document, range, codeActionContext, token) {
30
- const originalCodeActions = await typeScriptPlugin.provideCodeActions(document, range, codeActionContext, token);
31
- if (!originalCodeActions)
32
- return null;
33
- return (0, codeActions_js_1.enhancedProvideCodeActions)(originalCodeActions, context);
34
- },
35
- async resolveCodeAction(codeAction, token) {
36
- const resolvedCodeAction = await typeScriptPlugin.resolveCodeAction(codeAction, token);
37
- if (!resolvedCodeAction)
38
- return codeAction;
39
- return (0, codeActions_js_1.enhancedResolveCodeAction)(resolvedCodeAction, context);
40
- },
41
- async provideSemanticDiagnostics(document, token) {
42
- const [_, source] = context.documents.getVirtualCodeByUri(document.uri);
43
- const code = source?.generated?.code;
44
- let tsxLineCount = undefined;
45
- if (code instanceof index_js_1.AstroVirtualCode) {
46
- // If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
47
- if (code.hasCompilationErrors)
48
- return null;
49
- // We'll use this to filter out diagnostics that are outside the mapped range of the TSX
50
- tsxLineCount = code.astroMeta.tsxRanges.body.end.line;
51
- }
52
- const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics(document, token);
53
- if (!diagnostics)
54
- return null;
55
- return (0, diagnostics_js_1.enhancedProvideSemanticDiagnostics)(diagnostics, tsxLineCount);
14
+ ...plugin,
15
+ create(context) {
16
+ const typeScriptPlugin = plugin.create(context);
17
+ return {
18
+ ...typeScriptPlugin,
19
+ async provideCompletionItems(document, position, completionContext, token) {
20
+ const originalCompletions = await typeScriptPlugin.provideCompletionItems(document, position, completionContext, token);
21
+ if (!originalCompletions)
22
+ return null;
23
+ return (0, completions_js_1.enhancedProvideCompletionItems)(originalCompletions);
24
+ },
25
+ async resolveCompletionItem(item, token) {
26
+ const resolvedCompletionItem = await typeScriptPlugin.resolveCompletionItem(item, token);
27
+ if (!resolvedCompletionItem)
28
+ return item;
29
+ return (0, completions_js_1.enhancedResolveCompletionItem)(resolvedCompletionItem, context);
30
+ },
31
+ async provideCodeActions(document, range, codeActionContext, token) {
32
+ const originalCodeActions = await typeScriptPlugin.provideCodeActions(document, range, codeActionContext, token);
33
+ if (!originalCodeActions)
34
+ return null;
35
+ return (0, codeActions_js_1.enhancedProvideCodeActions)(originalCodeActions, context);
36
+ },
37
+ async resolveCodeAction(codeAction, token) {
38
+ const resolvedCodeAction = await typeScriptPlugin.resolveCodeAction(codeAction, token);
39
+ if (!resolvedCodeAction)
40
+ return codeAction;
41
+ return (0, codeActions_js_1.enhancedResolveCodeAction)(resolvedCodeAction, context);
42
+ },
43
+ async provideSemanticDiagnostics(document, token) {
44
+ const [_, source] = context.documents.getVirtualCodeByUri(document.uri);
45
+ const code = source?.generated?.code;
46
+ let tsxLineCount = undefined;
47
+ if (code instanceof index_js_1.AstroVirtualCode) {
48
+ // If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
49
+ if (code.hasCompilationErrors)
50
+ return null;
51
+ // We'll use this to filter out diagnostics that are outside the mapped range of the TSX
52
+ tsxLineCount = code.astroMeta.tsxRanges.body.end.line;
53
+ }
54
+ const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics(document, token);
55
+ if (!diagnostics)
56
+ return null;
57
+ return (0, diagnostics_js_1.enhancedProvideSemanticDiagnostics)(diagnostics, tsxLineCount);
58
+ },
59
+ };
56
60
  },
57
61
  };
58
- },
59
- };
62
+ }
63
+ return plugin;
64
+ });
60
65
  };
61
66
  exports.create = create;
62
67
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "2.7.7",
3
+ "version": "2.8.1",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,20 +20,20 @@
20
20
  "astro-ls": "./bin/nodeServer.js"
21
21
  },
22
22
  "dependencies": {
23
- "@astrojs/compiler": "^2.4.0",
23
+ "@astrojs/compiler": "^2.7.0",
24
24
  "@jridgewell/sourcemap-codec": "^1.4.15",
25
- "@volar/kit": "~2.0.4",
26
- "@volar/language-core": "~2.0.4",
27
- "@volar/language-server": "~2.0.4",
28
- "@volar/language-service": "~2.0.4",
29
- "@volar/typescript": "~2.0.4",
25
+ "@volar/kit": "~2.1.2",
26
+ "@volar/language-core": "~2.1.2",
27
+ "@volar/language-server": "~2.1.2",
28
+ "@volar/language-service": "~2.1.2",
29
+ "@volar/typescript": "~2.1.2",
30
30
  "fast-glob": "^3.2.12",
31
- "volar-service-css": "0.0.30",
32
- "volar-service-emmet": "0.0.30",
33
- "volar-service-html": "0.0.30",
34
- "volar-service-prettier": "0.0.30",
35
- "volar-service-typescript": "0.0.30",
36
- "volar-service-typescript-twoslash-queries": "0.0.30",
31
+ "volar-service-css": "0.0.32",
32
+ "volar-service-emmet": "0.0.32",
33
+ "volar-service-html": "0.0.32",
34
+ "volar-service-prettier": "0.0.32",
35
+ "volar-service-typescript": "0.0.32",
36
+ "volar-service-typescript-twoslash-queries": "0.0.32",
37
37
  "vscode-html-languageservice": "^5.1.2",
38
38
  "vscode-uri": "^3.0.8"
39
39
  },
@@ -44,7 +44,7 @@
44
44
  "@types/chai": "^4.3.5",
45
45
  "@types/mocha": "^10.0.1",
46
46
  "@types/node": "^18.17.8",
47
- "@volar/test-utils": "~2.0.4",
47
+ "@volar/test-utils": "~2.1.2",
48
48
  "astro": "^4.3.5",
49
49
  "chai": "^4.3.7",
50
50
  "mocha": "^10.2.0",