@astrojs/language-server 0.8.9 → 0.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 7dc85cc: Add support for Emmet inside components, upgrade Emmet version
8
+
9
+ ## 0.9.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 6b6b47a: Remove internal astro.d.ts files, instead prefer the one provided by Astro itself
14
+
15
+ ## 0.8.10
16
+
17
+ ### Patch Changes
18
+
19
+ - 5b16fb4: Fix errors showing on wrong line due to an error in TSX generation
20
+
3
21
  ## 0.8.9
4
22
 
5
23
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { VSCodeEmmetConfig } from 'vscode-emmet-helper';
1
+ import { VSCodeEmmetConfig } from '@vscode/emmet-helper';
2
2
  import { UserPreferences } from 'typescript';
3
3
  /**
4
4
  * Representation of the language server config.
@@ -41,6 +41,8 @@ export declare function isInsideExpression(html: string, tagStart: number, posit
41
41
  */
42
42
  export declare function isInsideFrontmatter(text: string, offset: number): boolean;
43
43
  export declare function isInTag(position: Position, tagInfo: TagInformation | null): tagInfo is TagInformation;
44
+ export declare function isComponentTag(node: Node): boolean;
45
+ export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
44
46
  /**
45
47
  * Get the line and character based on the offset
46
48
  * @param offset The index of the position
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractStyleTag = exports.walk = exports.offsetAt = exports.positionAt = exports.isInTag = exports.isInsideFrontmatter = exports.isInsideExpression = exports.getFirstNonWhitespaceIndex = exports.getWordAt = exports.getWordRangeAt = void 0;
3
+ exports.extractStyleTag = exports.walk = exports.offsetAt = exports.positionAt = exports.isInComponentStartTag = exports.isComponentTag = exports.isInTag = exports.isInsideFrontmatter = exports.isInsideExpression = exports.getFirstNonWhitespaceIndex = exports.getWordAt = exports.getWordRangeAt = void 0;
4
4
  const vscode_html_languageservice_1 = require("vscode-html-languageservice");
5
5
  const vscode_languageserver_1 = require("vscode-languageserver");
6
6
  const utils_1 = require("../../utils");
@@ -76,6 +76,19 @@ function isInTag(position, tagInfo) {
76
76
  return !!tagInfo && (0, utils_1.isInRange)(position, vscode_languageserver_1.Range.create(tagInfo.startPos, tagInfo.endPos));
77
77
  }
78
78
  exports.isInTag = isInTag;
79
+ function isComponentTag(node) {
80
+ if (!node.tag) {
81
+ return false;
82
+ }
83
+ const firstChar = node.tag[0];
84
+ return /[A-Z]/.test(firstChar);
85
+ }
86
+ exports.isComponentTag = isComponentTag;
87
+ function isInComponentStartTag(html, offset) {
88
+ const node = html.findNodeAt(offset);
89
+ return (isComponentTag(node) && (!node.startTagEnd || offset < node.startTagEnd));
90
+ }
91
+ exports.isInComponentStartTag = isInComponentStartTag;
79
92
  /**
80
93
  * Get the line and character based on the offset
81
94
  * @param offset The index of the position
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CSSPlugin = void 0;
4
- const vscode_emmet_helper_1 = require("vscode-emmet-helper");
4
+ const emmet_helper_1 = require("@vscode/emmet-helper");
5
5
  const vscode_languageserver_1 = require("vscode-languageserver");
6
6
  const utils_1 = require("../../core/documents/utils");
7
7
  const CSSDocument_1 = require("./CSSDocument");
@@ -51,7 +51,7 @@ class CSSPlugin {
51
51
  if (isSASS(cssDocument)) {
52
52
  // the css language service does not support sass, still we can use
53
53
  // the emmet helper directly to at least get emmet completions
54
- return (0, vscode_emmet_helper_1.doComplete)(document, position, 'sass', this.configManager.getEmmetConfig());
54
+ return (0, emmet_helper_1.doComplete)(document, position, 'sass', this.configManager.getEmmetConfig()) || null;
55
55
  }
56
56
  const type = extractLanguage(cssDocument);
57
57
  const lang = (0, service_1.getLanguageService)(type);
@@ -59,11 +59,6 @@ class CSSPlugin {
59
59
  isIncomplete: true,
60
60
  items: [],
61
61
  };
62
- if (false /* this.configManager.getConfig().css.completions.emmet */) {
63
- lang.setCompletionParticipants([
64
- (0, vscode_emmet_helper_1.getEmmetCompletionParticipants)(cssDocument, cssDocument.getGeneratedPosition(position), (0, service_1.getLanguage)(type), this.configManager.getEmmetConfig(), emmetResults),
65
- ]);
66
- }
67
62
  const results = lang.doComplete(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
68
63
  return vscode_languageserver_1.CompletionList.create([...(results ? results.items : []), ...emmetResults.items].map((completionItem) => (0, documents_1.mapCompletionItemToOriginal)(cssDocument, completionItem)),
69
64
  // Emmet completions change on every keystroke, so they are never complete
@@ -21,5 +21,4 @@ export declare class HTMLPlugin implements CompletionsProvider, FoldingRangeProv
21
21
  private getLangCompletions;
22
22
  private isInsideExpression;
23
23
  private isInsideFrontmatter;
24
- private isComponentTag;
25
24
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HTMLPlugin = void 0;
4
- const vscode_emmet_helper_1 = require("vscode-emmet-helper");
4
+ const emmet_helper_1 = require("@vscode/emmet-helper");
5
5
  const vscode_html_languageservice_1 = require("vscode-html-languageservice");
6
6
  const vscode_languageserver_1 = require("vscode-languageserver");
7
7
  const utils_1 = require("../../core/documents/utils");
@@ -24,17 +24,17 @@ class HTMLPlugin {
24
24
  if (this.isInsideFrontmatter(document, position) || this.isInsideExpression(html, document, position)) {
25
25
  return null;
26
26
  }
27
- const offset = document.offsetAt(position);
28
- const node = html.findNodeAt(offset);
29
- if (this.isComponentTag(node)) {
30
- return null;
31
- }
32
- const emmetResults = {
27
+ let emmetResults = {
33
28
  isIncomplete: true,
34
29
  items: [],
35
30
  };
36
- this.lang.setCompletionParticipants([(0, vscode_emmet_helper_1.getEmmetCompletionParticipants)(document, position, 'html', this.configManager.getEmmetConfig(), emmetResults)]);
37
- const results = this.lang.doComplete(document, position, html);
31
+ this.lang.setCompletionParticipants([
32
+ {
33
+ onHtmlContent: () => (emmetResults = (0, emmet_helper_1.doComplete)(document, position, 'html', this.configManager.getEmmetConfig()) || emmetResults),
34
+ },
35
+ ]);
36
+ // For components, we only want Emmet completions inside the component (aka slots) because HTML properties are not necessarily valid for a component
37
+ const results = (0, utils_1.isInComponentStartTag)(html, document.offsetAt(position)) ? vscode_languageserver_1.CompletionList.create([]) : this.lang.doComplete(document, position, html);
38
38
  const items = this.toCompletionItems(results.items);
39
39
  return vscode_languageserver_1.CompletionList.create([...this.toCompletionItems(items), ...this.getLangCompletions(items), ...emmetResults.items],
40
40
  // Emmet completions change on every keystroke, so they are never complete
@@ -104,12 +104,5 @@ class HTMLPlugin {
104
104
  isInsideFrontmatter(document, position) {
105
105
  return (0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position));
106
106
  }
107
- isComponentTag(node) {
108
- if (!node.tag) {
109
- return false;
110
- }
111
- const firstChar = node.tag[0];
112
- return /[A-Z]/.test(firstChar);
113
- }
114
107
  }
115
108
  exports.HTMLPlugin = HTMLPlugin;
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
3
  const os_1 = require("os");
5
4
  const parseAstro_1 = require("../../core/documents/parseAstro");
6
- const ASTRO_DEFINITION_BYTES = (0, fs_1.readFileSync)(require.resolve('../../../astro.d.ts'));
7
- const ASTRO_DEFINITION_STR = ASTRO_DEFINITION_BYTES.toString('utf-8');
8
- function addProps(content, dtsContent) {
9
- let defaultExportType = 'AstroBuiltinProps & Record<string, any>';
10
- // Using TypeScript to parse here would cause a double-parse, slowing down the extension
11
- // This needs to be done a different way when the new compiler is added.
5
+ function addProps(content) {
6
+ let defaultExportType = 'Record<string, any>';
12
7
  if (/(interface|type) Props/.test(content)) {
13
- defaultExportType = 'AstroBuiltinProps & Props';
8
+ defaultExportType = 'Props';
14
9
  }
15
- return dtsContent + os_1.EOL + `export default function (_props: ${defaultExportType}) { return <div></div>; }`;
10
+ return os_1.EOL + `export default function (_props: ${defaultExportType}) { return <div></div>; }`;
16
11
  }
17
12
  function escapeTemplateLiteralContent(content) {
18
13
  return content.replace(/`/g, '\\`');
19
14
  }
20
15
  function default_1(content) {
21
- var _a, _b, _c;
16
+ var _a, _b;
22
17
  let result = {
23
18
  code: '',
24
19
  };
@@ -36,8 +31,9 @@ function default_1(content) {
36
31
  .replace(/---/g, '///');
37
32
  }
38
33
  // Content replacement
34
+ const htmlBegin = astroDocument.frontmatter.endOffset ? astroDocument.frontmatter.endOffset + 3 : 0;
39
35
  let htmlRaw = content
40
- .substring((_c = astroDocument.content.firstNonWhitespaceOffset) !== null && _c !== void 0 ? _c : 0)
36
+ .substring(htmlBegin)
41
37
  // Turn comments into JS comments
42
38
  .replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => {
43
39
  return `{/*${whole}*/}`;
@@ -77,11 +73,10 @@ function default_1(content) {
77
73
  });
78
74
  result.code =
79
75
  frontMatterRaw +
80
- '\n' +
81
76
  htmlRaw +
82
77
  os_1.EOL +
83
78
  // Add TypeScript definitions
84
- addProps(frontMatterRaw, ASTRO_DEFINITION_STR);
79
+ addProps(frontMatterRaw);
85
80
  return result;
86
81
  }
87
82
  exports.default = default_1;
@@ -60,10 +60,10 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
60
60
  },
61
61
  };
62
62
  let configJson = (tsconfigPath && ts.readConfigFile(tsconfigPath, ts.sys.readFile).config) || {};
63
- // If our user has types in their config but it doesn't include the types for ImportMeta, let's add them for them
63
+ // If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
64
64
  if (((_a = configJson.compilerOptions) === null || _a === void 0 ? void 0 : _a.types) &&
65
- !((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes("vite/client"))) {
66
- configJson.compilerOptions.types.push("vite/client");
65
+ !((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes("astro/env"))) {
66
+ configJson.compilerOptions.types.push("astro/env");
67
67
  }
68
68
  configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(), configJson.compilerOptions);
69
69
  // If the user supplied exclude, let's use theirs
@@ -161,8 +161,7 @@ function getDefaultCompilerOptions() {
161
161
  maxNodeModuleJsDepth: 2,
162
162
  allowSyntheticDefaultImports: true,
163
163
  allowJs: true,
164
- // By providing vite/client here, our users get proper typing on import.meta in .astro files
165
- types: ["vite/client"],
164
+ types: ["astro/env"]
166
165
  };
167
166
  }
168
167
  function getDefaultExclude() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.8.9",
3
+ "version": "0.9.1",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -25,7 +25,7 @@
25
25
  "ts-morph": "^12.0.0",
26
26
  "typescript": "^4.5.4",
27
27
  "vscode-css-languageservice": "^5.1.1",
28
- "vscode-emmet-helper": "2.1.2",
28
+ "@vscode/emmet-helper": "^2.8.4",
29
29
  "vscode-html-languageservice": "^3.0.3",
30
30
  "vscode-languageserver": "6.1.1",
31
31
  "vscode-languageserver-protocol": "^3.16.0",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/lodash": "^4.14.116",
38
- "astro": "0.19.1",
38
+ "astro": "^0.23.5",
39
39
  "astro-scripts": "0.0.1",
40
40
  "tap": "^15.0.9"
41
41
  }
package/astro.d.ts DELETED
@@ -1,48 +0,0 @@
1
- export {};
2
-
3
- type AstroRenderedHTML = string;
4
-
5
- type AstroElement = any;
6
- type Fragment = (...a: any[]) => AstroElement;
7
-
8
- type FetchContentResultBase = {
9
- astro: {
10
- headers: string[];
11
- source: string;
12
- html: AstroRenderedHTML;
13
- };
14
- url: URL;
15
- };
16
-
17
- type FetchContentResult<T> = FetchContentResultBase & T;
18
-
19
- export type Params = Record<string, string | undefined>;
20
-
21
- interface AstroPageRequest {
22
- url: URL;
23
- canonicalURL: URL;
24
- params: Params;
25
- }
26
-
27
- interface AstroBuiltinProps {
28
- 'client:load'?: boolean;
29
- 'client:idle'?: boolean;
30
- 'client:media'?: string;
31
- 'client:visible'?: boolean;
32
- }
33
-
34
- interface Astro {
35
- isPage: boolean;
36
- fetchContent<T = any>(globStr: string): FetchContentResult<T>[];
37
- props: Record<string, number | string | any>;
38
- request: AstroPageRequest;
39
- resolve: (path: string) => string;
40
- site: URL;
41
- slots: Record<string, true | undefined>;
42
- }
43
-
44
- declare var Astro: Astro;
45
- declare var Fragment: string;
46
-
47
- void Astro;
48
- void Fragment;