@astrojs/language-server 0.23.0 → 0.23.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.23.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 150946c: Publish failed
8
+
9
+ ## 0.23.2
10
+
11
+ ### Patch Changes
12
+
13
+ - b13fb51: Don't use `workspace/configuration` on clients that don't support it
14
+
15
+ ## 0.23.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 422376e: Load settings from the Prettier VS Code extension when available
20
+
3
21
  ## 0.23.0
4
22
 
5
23
  ### Minor Changes
@@ -13,16 +13,18 @@ declare type DeepPartial<T> = T extends Record<string, unknown> ? {
13
13
  * For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
14
14
  */
15
15
  export declare class ConfigManager {
16
+ private connection?;
17
+ private hasConfigurationCapability?;
16
18
  private globalConfig;
17
19
  private documentSettings;
18
20
  shouldRefreshTSServices: boolean;
19
21
  private isTrusted;
20
- private connection;
21
- constructor(connection?: Connection);
22
+ constructor(connection?: Connection | undefined, hasConfigurationCapability?: boolean | undefined);
22
23
  updateConfig(): void;
23
24
  removeDocument(scopeUri: string): void;
24
25
  getConfig<T>(section: string, scopeUri: string): Promise<T | Record<string, any>>;
25
26
  getEmmetConfig(document: TextDocument): Promise<VSCodeEmmetConfig>;
27
+ getPrettierVSConfig(document: TextDocument): Promise<Record<string, any>>;
26
28
  getTSFormatConfig(document: TextDocument, vscodeOptions?: FormattingOptions): Promise<FormatCodeSettings>;
27
29
  getTSPreferences(document: TextDocument): Promise<UserPreferences>;
28
30
  getTSInlayHintsPreferences(document: TextDocument): Promise<InlayHintsOptions>;
@@ -46,13 +46,14 @@ exports.defaultLSConfig = {
46
46
  * For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
47
47
  */
48
48
  class ConfigManager {
49
- constructor(connection) {
49
+ constructor(connection, hasConfigurationCapability) {
50
+ this.connection = connection;
51
+ this.hasConfigurationCapability = hasConfigurationCapability;
50
52
  this.globalConfig = { astro: exports.defaultLSConfig };
51
53
  this.documentSettings = {};
52
54
  // If set to true, the next time we need a TypeScript language service, we'll rebuild it so it gets the new config
53
55
  this.shouldRefreshTSServices = false;
54
56
  this.isTrusted = true;
55
- this.connection = connection;
56
57
  }
57
58
  updateConfig() {
58
59
  // Reset all cached document settings
@@ -63,7 +64,7 @@ class ConfigManager {
63
64
  delete this.documentSettings[scopeUri];
64
65
  }
65
66
  async getConfig(section, scopeUri) {
66
- if (!this.connection) {
67
+ if (!this.connection || !this.hasConfigurationCapability) {
67
68
  return (0, utils_1.get)(this.globalConfig, section) ?? {};
68
69
  }
69
70
  if (!this.documentSettings[scopeUri]) {
@@ -90,6 +91,10 @@ class ConfigManager {
90
91
  showSuggestionsAsSnippets: emmetConfig.showSuggestionsAsSnippets ?? false,
91
92
  };
92
93
  }
94
+ async getPrettierVSConfig(document) {
95
+ const prettierVSConfig = (await this.getConfig('prettier', document.uri)) ?? {};
96
+ return prettierVSConfig;
97
+ }
93
98
  async getTSFormatConfig(document, vscodeOptions) {
94
99
  const formatConfig = (await this.getConfig('typescript.format', document.uri)) ?? {};
95
100
  return {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AstroPlugin = void 0;
4
4
  const vscode_languageserver_1 = require("vscode-languageserver");
5
5
  const importPackage_1 = require("../../importPackage");
6
- const utils_1 = require("../../utils");
7
6
  const CompletionsProvider_1 = require("./features/CompletionsProvider");
8
7
  class AstroPlugin {
9
8
  constructor(configManager, languageServiceManager) {
@@ -22,14 +21,19 @@ class AstroPlugin {
22
21
  return [];
23
22
  }
24
23
  const prettier = (0, importPackage_1.importPrettier)(filePath);
25
- const prettierConfig = await prettier.resolveConfig(filePath, { editorconfig: true, useCache: false });
26
- const editorFormatConfig = options !== undefined
24
+ const prettierConfig = (await prettier.resolveConfig(filePath, { editorconfig: true, useCache: false })) ?? {};
25
+ const prettierVSConfig = await this.configManager.getPrettierVSConfig(document);
26
+ const editorFormatConfig = options !== undefined // We need to check for options existing here because some editors might not have it
27
27
  ? {
28
- tabWidth: prettierConfig?.tabWidth ?? options.tabSize,
29
- useTabs: prettierConfig?.useTabs ?? !options.insertSpaces,
28
+ tabWidth: options.tabSize,
29
+ useTabs: !options.insertSpaces,
30
30
  }
31
31
  : {};
32
- const resultConfig = (0, utils_1.mergeDeep)(prettierConfig ?? {}, editorFormatConfig);
32
+ // Return a config with the following cascade:
33
+ // - Prettier config file should always win if it exists, if it doesn't:
34
+ // - Prettier config from the VS Code extension is used, if it doesn't exist:
35
+ // - Use the editor's basic configuration settings
36
+ const resultConfig = returnObjectIfHasKeys(prettierConfig) || returnObjectIfHasKeys(prettierVSConfig) || editorFormatConfig;
33
37
  const fileInfo = await prettier.getFileInfo(filePath, { ignorePath: '.prettierignore' });
34
38
  if (fileInfo.ignored) {
35
39
  return [];
@@ -74,3 +78,8 @@ class AstroPlugin {
74
78
  }
75
79
  }
76
80
  exports.AstroPlugin = AstroPlugin;
81
+ function returnObjectIfHasKeys(obj) {
82
+ if (Object.keys(obj || {}).length > 0) {
83
+ return obj;
84
+ }
85
+ }
package/dist/server.js CHANGED
@@ -44,7 +44,7 @@ function startLanguageServer(connection) {
44
44
  // Create our managers
45
45
  const documentManager = new DocumentManager_1.DocumentManager();
46
46
  const pluginHost = new PluginHost_1.PluginHost(documentManager);
47
- const configManager = new ConfigManager_1.ConfigManager(connection);
47
+ let configManager;
48
48
  let typescriptPlugin = undefined;
49
49
  let hasConfigurationCapability = false;
50
50
  connection.onInitialize((params) => {
@@ -66,6 +66,7 @@ function startLanguageServer(connection) {
66
66
  }
67
67
  });
68
68
  hasConfigurationCapability = !!(params.capabilities.workspace && !!params.capabilities.workspace.configuration);
69
+ configManager = new ConfigManager_1.ConfigManager(connection, hasConfigurationCapability);
69
70
  pluginHost.initialize({
70
71
  filterIncompleteCompletions: !params.initializationOptions?.dontFilterIncompleteCompletions,
71
72
  definitionLinkSupport: !!params.capabilities.textDocument?.definition?.linkSupport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.23.0",
3
+ "version": "0.23.3",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",