@astrojs/language-server 0.22.0 → 0.23.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.23.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1dcef68: Automatically type `Astro.props` using the Props interface when available
8
+
9
+ ### Patch Changes
10
+
11
+ - b6c95f2: Fix completions for HTML attributes not working anymore since 0.20.3
12
+
3
13
  ## 0.22.0
4
14
 
5
15
  ### Minor Changes
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
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",