@astrojs/language-server 2.8.0 → 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
  }
@@ -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");
@@ -37,8 +38,8 @@ function createServerOptions(connection, ts) {
37
38
  (0, html_js_1.create)(),
38
39
  (0, volar_service_css_1.create)(),
39
40
  (0, volar_service_emmet_1.create)(),
40
- (0, index_js_2.create)(ts),
41
- (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),
42
43
  (0, index_js_1.create)(),
43
44
  (0, astro_js_1.create)(ts),
44
45
  getPrettierService(),
@@ -72,11 +73,11 @@ function createServerOptions(connection, ts) {
72
73
  function getPrettierService() {
73
74
  let prettier;
74
75
  let prettierPluginPath;
75
- return (0, volar_service_prettier_1.create)({
76
- getPrettier(env) {
77
- const workspacePath = env.typescript.uriToFileName(env.workspaceFolder);
78
- prettier = (0, importPackage_js_1.importPrettier)(workspacePath);
79
- 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);
80
81
  if (!prettier || !prettierPluginPath) {
81
82
  connection.sendNotification(node_1.ShowMessageNotification.type, {
82
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.",
@@ -84,15 +85,32 @@ function createServerOptions(connection, ts) {
84
85
  });
85
86
  }
86
87
  return prettier;
87
- },
88
- languages: ['astro'],
89
- ignoreIdeOptions: true,
90
- useIdeOptionsFallback: true,
91
- resolveConfigOptions: {
92
- // This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
93
- useCache: false,
94
- },
95
- 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
+ };
96
114
  async function getAstroPrettierPlugin() {
97
115
  if (!prettier || !prettierPluginPath) {
98
116
  return [];
@@ -101,14 +119,7 @@ function createServerOptions(connection, ts) {
101
119
  resolvedConfig.plugins?.includes('prettier-plugin-astro'); // getSupportInfo doesn't seems to work very well in Prettier 3 for plugins
102
120
  return hasPluginLoadedAlready ? [] : [prettierPluginPath];
103
121
  }
104
- const plugins = [...(await getAstroPrettierPlugin()), ...(resolvedConfig.plugins ?? [])];
105
- return {
106
- ...resolvedConfig,
107
- plugins: plugins,
108
- parser: 'astro',
109
- };
110
122
  },
111
- allowImportError: true,
112
123
  });
113
124
  }
114
125
  }
@@ -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.8.0",
3
+ "version": "2.8.1",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,12 +28,12 @@
28
28
  "@volar/language-service": "~2.1.2",
29
29
  "@volar/typescript": "~2.1.2",
30
30
  "fast-glob": "^3.2.12",
31
- "volar-service-css": "0.0.31",
32
- "volar-service-emmet": "0.0.31",
33
- "volar-service-html": "0.0.31",
34
- "volar-service-prettier": "0.0.31-patch.1",
35
- "volar-service-typescript": "0.0.31",
36
- "volar-service-typescript-twoslash-queries": "0.0.31",
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
  },