@astrojs/language-server 0.8.7 → 0.8.10
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 +18 -0
- package/README.md +16 -0
- package/dist/plugins/typescript/astro2tsx.js +26 -11
- package/dist/plugins/typescript/languageService.js +19 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.8.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5b16fb4: Fix errors showing on wrong line due to an error in TSX generation
|
|
8
|
+
|
|
9
|
+
## 0.8.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d0485a2: Only apply content transformations for TSX generation in relevant places
|
|
14
|
+
|
|
15
|
+
## 0.8.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 526d5c7: Bring back loading the user js/tsconfig.json, notably, this allow us to support aliases
|
|
20
|
+
|
|
3
21
|
## 0.8.7
|
|
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,27 @@ function escapeTemplateLiteralContent(content) {
|
|
|
17
18
|
return content.replace(/`/g, '\\`');
|
|
18
19
|
}
|
|
19
20
|
function default_1(content) {
|
|
21
|
+
var _a, _b;
|
|
20
22
|
let result = {
|
|
21
|
-
code: ''
|
|
23
|
+
code: '',
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
const htmlBegin = astroDocument.frontmatter.endOffset ? astroDocument.frontmatter.endOffset + 3 : 0;
|
|
40
|
+
let htmlRaw = content
|
|
41
|
+
.substring(htmlBegin)
|
|
30
42
|
// Turn comments into JS comments
|
|
31
43
|
.replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => {
|
|
32
44
|
return `{/*${whole}*/}`;
|
|
@@ -64,9 +76,12 @@ function default_1(content) {
|
|
|
64
76
|
.replace(/<!(doctype html)>/gi, (_whole, main) => {
|
|
65
77
|
return `<${main.toLowerCase()}/>`;
|
|
66
78
|
});
|
|
67
|
-
result.code =
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
result.code =
|
|
80
|
+
frontMatterRaw +
|
|
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
|
-
|
|
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,17 +156,13 @@ async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
|
|
|
142
156
|
return doc;
|
|
143
157
|
}
|
|
144
158
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
159
|
+
function getDefaultCompilerOptions() {
|
|
160
|
+
return {
|
|
147
161
|
maxNodeModuleJsDepth: 2,
|
|
148
162
|
allowSyntheticDefaultImports: true,
|
|
149
163
|
allowJs: true,
|
|
150
164
|
// By providing vite/client here, our users get proper typing on import.meta in .astro files
|
|
151
|
-
types: [
|
|
152
|
-
};
|
|
153
|
-
return {
|
|
154
|
-
compilerOptions,
|
|
155
|
-
exclude: getDefaultExclude(),
|
|
165
|
+
types: ["vite/client"],
|
|
156
166
|
};
|
|
157
167
|
}
|
|
158
168
|
function getDefaultExclude() {
|