@analogjs/language-server 0.1.3 → 0.1.4
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/out/languagePlugin.d.ts +3 -3
- package/out/languagePlugin.js +55 -36
- package/package.json +1 -1
package/out/languagePlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type LanguagePlugin, type VirtualCode } from
|
|
2
|
-
import * as html from
|
|
3
|
-
import { URI } from
|
|
1
|
+
import { type LanguagePlugin, type VirtualCode } from "@volar/language-core";
|
|
2
|
+
import * as html from "vscode-html-languageservice";
|
|
3
|
+
import { URI } from "vscode-uri";
|
|
4
4
|
export declare const analogLanguagePlugin: LanguagePlugin<URI>;
|
|
5
5
|
export interface AnalogVirtualCode extends VirtualCode {
|
|
6
6
|
htmlDocument: html.HTMLDocument;
|
package/out/languagePlugin.js
CHANGED
|
@@ -28,44 +28,50 @@ const language_core_1 = require("@volar/language-core");
|
|
|
28
28
|
const html = __importStar(require("vscode-html-languageservice"));
|
|
29
29
|
exports.analogLanguagePlugin = {
|
|
30
30
|
getLanguageId(uri) {
|
|
31
|
-
if (uri.path.endsWith(
|
|
32
|
-
return
|
|
31
|
+
if (uri.path.endsWith(".analog") || uri.path.endsWith(".ag")) {
|
|
32
|
+
return "analog";
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
createVirtualCode(_uri, languageId, snapshot) {
|
|
36
|
-
if (languageId ===
|
|
36
|
+
if (languageId === "analog") {
|
|
37
37
|
return createAnalogCode(snapshot);
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
typescript: {
|
|
41
|
-
extraFileExtensions: [
|
|
41
|
+
extraFileExtensions: [
|
|
42
|
+
{
|
|
43
|
+
extension: "analog",
|
|
44
|
+
isMixedContent: true,
|
|
45
|
+
scriptKind: 3,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
42
48
|
getServiceScript() {
|
|
43
49
|
return undefined;
|
|
44
50
|
},
|
|
45
51
|
getExtraServiceScripts(fileName, root) {
|
|
46
52
|
const scripts = [];
|
|
47
53
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
|
|
48
|
-
if (code.languageId ===
|
|
54
|
+
if (code.languageId === "javascript") {
|
|
49
55
|
scripts.push({
|
|
50
|
-
fileName: fileName +
|
|
56
|
+
fileName: fileName + "." + code.id + ".js",
|
|
51
57
|
code,
|
|
52
|
-
extension:
|
|
58
|
+
extension: ".js",
|
|
53
59
|
scriptKind: 1,
|
|
54
60
|
});
|
|
55
61
|
}
|
|
56
|
-
else if (code.languageId ===
|
|
62
|
+
else if (code.languageId === "typescript") {
|
|
57
63
|
scripts.push({
|
|
58
|
-
fileName: fileName +
|
|
64
|
+
fileName: fileName + "." + code.id + ".ts",
|
|
59
65
|
code,
|
|
60
|
-
extension:
|
|
66
|
+
extension: ".ts",
|
|
61
67
|
scriptKind: 3,
|
|
62
68
|
});
|
|
63
69
|
}
|
|
64
|
-
else if (code.languageId ===
|
|
70
|
+
else if (code.languageId === "typescriptreact") {
|
|
65
71
|
scripts.push({
|
|
66
|
-
fileName: fileName +
|
|
72
|
+
fileName: fileName + "." + code.id + ".tsx",
|
|
67
73
|
code,
|
|
68
|
-
extension:
|
|
74
|
+
extension: ".ts",
|
|
69
75
|
scriptKind: 4,
|
|
70
76
|
});
|
|
71
77
|
}
|
|
@@ -76,13 +82,14 @@ exports.analogLanguagePlugin = {
|
|
|
76
82
|
};
|
|
77
83
|
const htmlLs = html.getLanguageService();
|
|
78
84
|
function createAnalogCode(snapshot) {
|
|
79
|
-
const document = html.TextDocument.create(
|
|
85
|
+
const document = html.TextDocument.create("", "html", 0, snapshot.getText(0, snapshot.getLength()));
|
|
80
86
|
const htmlDocument = htmlLs.parseHTMLDocument(document);
|
|
81
87
|
return {
|
|
82
|
-
id:
|
|
83
|
-
languageId:
|
|
88
|
+
id: "root",
|
|
89
|
+
languageId: "html",
|
|
84
90
|
snapshot,
|
|
85
|
-
mappings: [
|
|
91
|
+
mappings: [
|
|
92
|
+
{
|
|
86
93
|
sourceOffsets: [0],
|
|
87
94
|
generatedOffsets: [0],
|
|
88
95
|
lengths: [snapshot.getLength()],
|
|
@@ -94,7 +101,8 @@ function createAnalogCode(snapshot) {
|
|
|
94
101
|
structure: true,
|
|
95
102
|
verification: true,
|
|
96
103
|
},
|
|
97
|
-
}
|
|
104
|
+
},
|
|
105
|
+
],
|
|
98
106
|
embeddedCodes: [...createEmbeddedCodes()],
|
|
99
107
|
htmlDocument,
|
|
100
108
|
};
|
|
@@ -103,17 +111,20 @@ function createAnalogCode(snapshot) {
|
|
|
103
111
|
let scripts = 0;
|
|
104
112
|
let langs = 0;
|
|
105
113
|
for (const root of htmlDocument.roots) {
|
|
106
|
-
if (root.tag ===
|
|
114
|
+
if (root.tag === "style" &&
|
|
115
|
+
root.startTagEnd !== undefined &&
|
|
116
|
+
root.endTagStart !== undefined) {
|
|
107
117
|
const styleText = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
108
118
|
yield {
|
|
109
|
-
id:
|
|
110
|
-
languageId:
|
|
119
|
+
id: "style_" + styles++,
|
|
120
|
+
languageId: "css",
|
|
111
121
|
snapshot: {
|
|
112
122
|
getText: (start, end) => styleText.substring(start, end),
|
|
113
123
|
getLength: () => styleText.length,
|
|
114
124
|
getChangeRange: () => undefined,
|
|
115
125
|
},
|
|
116
|
-
mappings: [
|
|
126
|
+
mappings: [
|
|
127
|
+
{
|
|
117
128
|
sourceOffsets: [root.startTagEnd],
|
|
118
129
|
generatedOffsets: [0],
|
|
119
130
|
lengths: [styleText.length],
|
|
@@ -125,17 +136,20 @@ function createAnalogCode(snapshot) {
|
|
|
125
136
|
structure: true,
|
|
126
137
|
verification: true,
|
|
127
138
|
},
|
|
128
|
-
}
|
|
139
|
+
},
|
|
140
|
+
],
|
|
129
141
|
embeddedCodes: [],
|
|
130
142
|
};
|
|
131
143
|
}
|
|
132
|
-
if (root.tag ===
|
|
144
|
+
if (root.tag === "script" &&
|
|
145
|
+
root.startTagEnd !== undefined &&
|
|
146
|
+
root.endTagStart !== undefined) {
|
|
133
147
|
const text = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
134
148
|
const lang = root.attributes?.lang;
|
|
135
|
-
const isTs = lang ===
|
|
149
|
+
const isTs = lang === "ts" || lang === '"ts"' || lang === "'ts'";
|
|
136
150
|
yield {
|
|
137
|
-
id:
|
|
138
|
-
languageId: isTs ?
|
|
151
|
+
id: "script_" + scripts++,
|
|
152
|
+
languageId: isTs ? "typescript" : "javascript",
|
|
139
153
|
snapshot: {
|
|
140
154
|
getText: (start, end) => `${text.substring(start, end)}
|
|
141
155
|
/**
|
|
@@ -156,7 +170,8 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
156
170
|
getLength: () => text.length,
|
|
157
171
|
getChangeRange: () => undefined,
|
|
158
172
|
},
|
|
159
|
-
mappings: [
|
|
173
|
+
mappings: [
|
|
174
|
+
{
|
|
160
175
|
sourceOffsets: [root.startTagEnd],
|
|
161
176
|
generatedOffsets: [0],
|
|
162
177
|
lengths: [text.length],
|
|
@@ -168,23 +183,27 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
168
183
|
structure: true,
|
|
169
184
|
verification: true,
|
|
170
185
|
},
|
|
171
|
-
}
|
|
186
|
+
},
|
|
187
|
+
],
|
|
172
188
|
embeddedCodes: [],
|
|
173
189
|
};
|
|
174
190
|
}
|
|
175
|
-
if (root.tag ===
|
|
191
|
+
if (root.tag === "template" &&
|
|
192
|
+
root.startTagEnd !== undefined &&
|
|
193
|
+
root.endTagStart !== undefined) {
|
|
176
194
|
const text = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
177
195
|
const lang = root.attributes?.lang;
|
|
178
|
-
const isMd = lang ===
|
|
196
|
+
const isMd = lang === "md" || lang === '"md"' || lang === "'md'";
|
|
179
197
|
yield {
|
|
180
|
-
id:
|
|
181
|
-
languageId: isMd ?
|
|
198
|
+
id: "lang_" + langs++,
|
|
199
|
+
languageId: isMd ? "markdown" : "html",
|
|
182
200
|
snapshot: {
|
|
183
201
|
getText: (start, end) => text.substring(start, end),
|
|
184
202
|
getLength: () => text.length,
|
|
185
203
|
getChangeRange: () => undefined,
|
|
186
204
|
},
|
|
187
|
-
mappings: [
|
|
205
|
+
mappings: [
|
|
206
|
+
{
|
|
188
207
|
sourceOffsets: [root.startTagEnd],
|
|
189
208
|
generatedOffsets: [0],
|
|
190
209
|
lengths: [text.length],
|
|
@@ -196,12 +215,12 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
196
215
|
structure: true,
|
|
197
216
|
verification: true,
|
|
198
217
|
},
|
|
199
|
-
}
|
|
218
|
+
},
|
|
219
|
+
],
|
|
200
220
|
embeddedCodes: [],
|
|
201
221
|
};
|
|
202
222
|
}
|
|
203
223
|
}
|
|
204
224
|
}
|
|
205
|
-
;
|
|
206
225
|
}
|
|
207
226
|
//# sourceMappingURL=languagePlugin.js.map
|