@astrojs/language-server 0.8.8 → 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 +6 -0
- package/README.md +16 -0
- package/dist/plugins/typescript/astro2tsx.js +26 -11
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
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
|
-
|
|
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
|
+
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 =
|
|
68
|
-
|
|
69
|
-
|
|
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;
|