@astrojs/language-server 0.8.6 → 0.8.9

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.8.9
4
+
5
+ ### Patch Changes
6
+
7
+ - d0485a2: Only apply content transformations for TSX generation in relevant places
8
+
9
+ ## 0.8.8
10
+
11
+ ### Patch Changes
12
+
13
+ - 526d5c7: Bring back loading the user js/tsconfig.json, notably, this allow us to support aliases
14
+
15
+ ## 0.8.7
16
+
17
+ ### Patch Changes
18
+
19
+ - 897ab35: Provide vite client types to Astro files
20
+
3
21
  ## 0.8.6
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
+ ```
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fs_1 = require("fs");
4
4
  const os_1 = require("os");
5
+ const parseAstro_1 = require("../../core/documents/parseAstro");
5
6
  const ASTRO_DEFINITION_BYTES = (0, fs_1.readFileSync)(require.resolve('../../../astro.d.ts'));
6
7
  const ASTRO_DEFINITION_STR = ASTRO_DEFINITION_BYTES.toString('utf-8');
7
8
  function addProps(content, dtsContent) {
@@ -17,16 +18,26 @@ function escapeTemplateLiteralContent(content) {
17
18
  return content.replace(/`/g, '\\`');
18
19
  }
19
20
  function default_1(content) {
21
+ var _a, _b, _c;
20
22
  let result = {
21
- code: ''
23
+ code: '',
22
24
  };
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, '///')
25
+ const astroDocument = (0, parseAstro_1.parseAstro)(content);
26
+ // Frontmatter replacements
27
+ let frontMatterRaw = '';
28
+ if (astroDocument.frontmatter.state === 'closed') {
29
+ frontMatterRaw = content
30
+ .substring((_a = astroDocument.frontmatter.startOffset) !== null && _a !== void 0 ? _a : 0, ((_b = astroDocument.frontmatter.endOffset) !== null && _b !== void 0 ? _b : 0) + 3)
31
+ // Handle case where semicolons is not used in the frontmatter section
32
+ .replace(/((?!^)(?<!;)\n)(---)/g, (_whole, start, _dashes) => {
33
+ return start + ';' + '//';
34
+ })
35
+ // Replace frontmatter marks with comments
36
+ .replace(/---/g, '///');
37
+ }
38
+ // Content replacement
39
+ let htmlRaw = content
40
+ .substring((_c = astroDocument.content.firstNonWhitespaceOffset) !== null && _c !== void 0 ? _c : 0)
30
41
  // Turn comments into JS comments
31
42
  .replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => {
32
43
  return `{/*${whole}*/}`;
@@ -64,9 +75,13 @@ function default_1(content) {
64
75
  .replace(/<!(doctype html)>/gi, (_whole, main) => {
65
76
  return `<${main.toLowerCase()}/>`;
66
77
  });
67
- result.code = (raw + os_1.EOL +
68
- // Add TypeScript definitions
69
- addProps(raw, ASTRO_DEFINITION_STR));
78
+ result.code =
79
+ frontMatterRaw +
80
+ '\n' +
81
+ htmlRaw +
82
+ os_1.EOL +
83
+ // Add TypeScript definitions
84
+ addProps(frontMatterRaw, ASTRO_DEFINITION_STR);
70
85
  return result;
71
86
  }
72
87
  exports.default = default_1;
@@ -52,17 +52,31 @@ async function getLanguageServiceForPath(path, workspaceUris, docContext) {
52
52
  }
53
53
  exports.getLanguageServiceForPath = getLanguageServiceForPath;
54
54
  async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
55
+ var _a, _b, _c;
55
56
  const parseConfigHost = {
56
57
  ...ts.sys,
57
58
  readDirectory: (path, extensions, exclude, include, depth) => {
58
59
  return ts.sys.readDirectory(path, [...extensions, '.vue', '.svelte', '.astro', '.js', '.jsx'], exclude, include, depth);
59
60
  },
60
61
  };
61
- const configJson = getDefaultJsConfig();
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
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");
67
+ }
68
+ configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(), configJson.compilerOptions);
69
+ // If the user supplied exclude, let's use theirs
70
+ (_c = configJson.exclude) !== null && _c !== void 0 ? _c : (configJson.exclude = getDefaultExclude());
71
+ // Delete include so that .astro files don't get mistakenly excluded by the user
72
+ delete configJson.include;
73
+ // Everything here will always, unconditionally, be in the resulting config, not the opposite, tricky
62
74
  const existingCompilerOptions = {
75
+ // Setting strict to true for .astro files leads to a lot of unrelated errors (see language-tools#91) so we force it off for .astro files
76
+ strict: false,
63
77
  jsx: ts.JsxEmit.Preserve,
64
78
  module: ts.ModuleKind.ESNext,
65
- target: ts.ScriptTarget.ESNext
79
+ target: ts.ScriptTarget.ESNext,
66
80
  };
67
81
  const project = ts.parseJsonConfigFileContent(configJson, parseConfigHost, workspaceRoot, existingCompilerOptions, (0, path_1.basename)(tsconfigPath), undefined, [
68
82
  { extension: '.vue', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
@@ -142,15 +156,13 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
142
156
  return doc;
143
157
  }
144
158
  }
145
- function getDefaultJsConfig() {
146
- let compilerOptions = {
159
+ function getDefaultCompilerOptions() {
160
+ return {
147
161
  maxNodeModuleJsDepth: 2,
148
162
  allowSyntheticDefaultImports: true,
149
163
  allowJs: true,
150
- };
151
- return {
152
- compilerOptions,
153
- exclude: getDefaultExclude(),
164
+ // By providing vite/client here, our users get proper typing on import.meta in .astro files
165
+ types: ["vite/client"],
154
166
  };
155
167
  }
156
168
  function getDefaultExclude() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.8.6",
4
- "author": "Skypack",
3
+ "version": "0.8.9",
4
+ "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "lodash": "^4.17.21",
24
24
  "source-map": "^0.7.3",
25
25
  "ts-morph": "^12.0.0",
26
- "typescript": "^4.5.2",
26
+ "typescript": "^4.5.4",
27
27
  "vscode-css-languageservice": "^5.1.1",
28
28
  "vscode-emmet-helper": "2.1.2",
29
29
  "vscode-html-languageservice": "^3.0.3",