@astrojs/language-server 0.8.8 → 0.9.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,23 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6b6b47a: Remove internal astro.d.ts files, instead prefer the one provided by Astro itself
8
+
9
+ ## 0.8.10
10
+
11
+ ### Patch Changes
12
+
13
+ - 5b16fb4: Fix errors showing on wrong line due to an error in TSX generation
14
+
15
+ ## 0.8.9
16
+
17
+ ### Patch Changes
18
+
19
+ - d0485a2: Only apply content transformations for TSX generation in relevant places
20
+
3
21
  ## 0.8.8
4
22
 
5
23
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @astrojs/language-server
2
+
3
+ The Astro language server, implement the [language server protocol](https://microsoft.github.io/language-server-protocol/)
4
+
5
+ ## Folder structure
6
+
7
+ ```plaintext
8
+ ├── bin # .js file used to start the server
9
+ ├── dist # Compiled files, generated by TypeScript
10
+ ├── src # Source files
11
+ │ ├── core # Core code such as .astro file parsing, configuration manager, document definition etc
12
+ │ └── plugins # Modules for the different languages supported in .astro files
13
+ ├── test # Tests
14
+ ├── types # Types
15
+ └── astro.d.ts # Types injected into .astro files by the language server
16
+ ```
@@ -1,32 +1,39 @@
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
- const ASTRO_DEFINITION_BYTES = (0, fs_1.readFileSync)(require.resolve('../../../astro.d.ts'));
6
- const ASTRO_DEFINITION_STR = ASTRO_DEFINITION_BYTES.toString('utf-8');
7
- function addProps(content, dtsContent) {
8
- let defaultExportType = 'AstroBuiltinProps & Record<string, any>';
9
- // Using TypeScript to parse here would cause a double-parse, slowing down the extension
10
- // This needs to be done a different way when the new compiler is added.
4
+ const parseAstro_1 = require("../../core/documents/parseAstro");
5
+ function addProps(content) {
6
+ let defaultExportType = 'Record<string, any>';
11
7
  if (/(interface|type) Props/.test(content)) {
12
- defaultExportType = 'AstroBuiltinProps & Props';
8
+ defaultExportType = 'Props';
13
9
  }
14
- 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>; }`;
15
11
  }
16
12
  function escapeTemplateLiteralContent(content) {
17
13
  return content.replace(/`/g, '\\`');
18
14
  }
19
15
  function default_1(content) {
16
+ var _a, _b;
20
17
  let result = {
21
- code: ''
18
+ code: '',
22
19
  };
23
- // Replace frontmatter marks with comments
24
- let raw = content
25
- // Handle case where semicolons is not used in the frontmatter section
26
- .replace(/((?!^)(?<!;)\n)(---)/g, (_whole, start, _dashes) => {
27
- return start + ';' + '//';
28
- })
29
- .replace(/---/g, '///')
20
+ const astroDocument = (0, parseAstro_1.parseAstro)(content);
21
+ // Frontmatter replacements
22
+ let frontMatterRaw = '';
23
+ if (astroDocument.frontmatter.state === 'closed') {
24
+ frontMatterRaw = content
25
+ .substring((_a = astroDocument.frontmatter.startOffset) !== null && _a !== void 0 ? _a : 0, ((_b = astroDocument.frontmatter.endOffset) !== null && _b !== void 0 ? _b : 0) + 3)
26
+ // Handle case where semicolons is not used in the frontmatter section
27
+ .replace(/((?!^)(?<!;)\n)(---)/g, (_whole, start, _dashes) => {
28
+ return start + ';' + '//';
29
+ })
30
+ // Replace frontmatter marks with comments
31
+ .replace(/---/g, '///');
32
+ }
33
+ // Content replacement
34
+ const htmlBegin = astroDocument.frontmatter.endOffset ? astroDocument.frontmatter.endOffset + 3 : 0;
35
+ let htmlRaw = content
36
+ .substring(htmlBegin)
30
37
  // Turn comments into JS comments
31
38
  .replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => {
32
39
  return `{/*${whole}*/}`;
@@ -64,9 +71,12 @@ function default_1(content) {
64
71
  .replace(/<!(doctype html)>/gi, (_whole, main) => {
65
72
  return `<${main.toLowerCase()}/>`;
66
73
  });
67
- result.code = (raw + os_1.EOL +
68
- // Add TypeScript definitions
69
- addProps(raw, ASTRO_DEFINITION_STR));
74
+ result.code =
75
+ frontMatterRaw +
76
+ htmlRaw +
77
+ os_1.EOL +
78
+ // Add TypeScript definitions
79
+ addProps(frontMatterRaw);
70
80
  return result;
71
81
  }
72
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.8.8",
4
- "author": "Skypack",
3
+ "version": "0.9.0",
4
+ "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
@@ -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;