@astrojs/language-server 0.22.0 → 0.23.2

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,27 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.23.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b13fb51: Don't use `workspace/configuration` on clients that don't support it
8
+
9
+ ## 0.23.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 422376e: Load settings from the Prettier VS Code extension when available
14
+
15
+ ## 0.23.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 1dcef68: Automatically type `Astro.props` using the Props interface when available
20
+
21
+ ### Patch Changes
22
+
23
+ - b6c95f2: Fix completions for HTML attributes not working anymore since 0.20.3
24
+
3
25
  ## 0.22.0
4
26
 
5
27
  ### 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
+ }
@@ -76,12 +76,16 @@ class HTMLPlugin {
76
76
  const inTagName = (0, utils_1.isInTagName)(html, offset);
77
77
  const results = inComponentTag && !inTagName
78
78
  ? (0, utils_2.removeDataAttrCompletion)(this.attributeOnlyLang.doComplete(document, position, html).items)
79
- : // We filter items with no documentation to prevent duplicates with our own defined script and style tags
80
- this.lang.doComplete(document, position, html).items.filter((item) => item.documentation !== undefined);
79
+ : this.lang.doComplete(document, position, html).items.filter(isNoAddedTagWithNoDocumentation);
81
80
  const langCompletions = inComponentTag ? [] : this.getLangCompletions(results);
82
81
  return vscode_languageserver_1.CompletionList.create([...results, ...langCompletions, ...emmetResults.items],
83
82
  // Emmet completions change on every keystroke, so they are never complete
84
83
  emmetResults.items.length > 0);
84
+ // Filter script and style completions with no documentation to prevent duplicates
85
+ // due to our added definitions for those tags
86
+ function isNoAddedTagWithNoDocumentation(item) {
87
+ return !(['script', 'style'].includes(item.label) && item.documentation === undefined);
88
+ }
85
89
  }
86
90
  getFoldingRanges(document) {
87
91
  const html = document.html;
@@ -4,10 +4,24 @@ const os_1 = require("os");
4
4
  const parseAstro_1 = require("../../core/documents/parseAstro");
5
5
  function addProps(content, className) {
6
6
  let defaultExportType = 'Record<string, any>';
7
+ let shouldAddGlobal = false;
8
+ let astroGlobal = "type AstroGlobal = import('astro').AstroGlobal";
9
+ const astroGlobalConstDef = `
10
+ /**
11
+ * Astro global available in all contexts in .astro files
12
+ *
13
+ * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global)
14
+ */
15
+ declare const Astro: Readonly<AstroGlobal>;
16
+ `;
7
17
  if (/(interface|type) Props/.test(content)) {
8
18
  defaultExportType = 'Props';
19
+ shouldAddGlobal = true;
20
+ astroGlobal += ' & { props: Props }';
9
21
  }
10
- return os_1.EOL + `export default function ${className}__AstroComponent_(_props: ${defaultExportType}): any {}`;
22
+ return (os_1.EOL +
23
+ (shouldAddGlobal ? astroGlobal + os_1.EOL + astroGlobalConstDef : '') +
24
+ `export default function ${className}__AstroComponent_(_props: ${defaultExportType}): any {}`);
11
25
  }
12
26
  function escapeTemplateLiteralContent(content) {
13
27
  return content.replace(/`/g, '\\`');
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.22.0",
3
+ "version": "0.23.2",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@vscode/emmet-helper": "^2.8.4",
23
23
  "prettier": "^2.7.1",
24
- "prettier-plugin-astro": "^0.5.0",
24
+ "prettier-plugin-astro": "^0.5.3",
25
25
  "source-map": "^0.7.3",
26
26
  "typescript": "~4.6.4",
27
27
  "vscode-css-languageservice": "^6.0.1",