@analogjs/language-server 0.1.3 → 0.1.5
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 +84 -40
- 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,29 +136,46 @@ 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 ===
|
|
133
|
-
|
|
144
|
+
if (root.tag === "script" &&
|
|
145
|
+
root.startTagEnd !== undefined &&
|
|
146
|
+
root.endTagStart !== undefined) {
|
|
147
|
+
const text = snapshot.getText(root.startTagEnd, root.endTagStart).replace(/(with(((\n|\s)*).*)})/gm, function (_, _$1, $2) {
|
|
148
|
+
// replace "with { analog: 'imports' }" with "/**with { analog: 'imports' }*/"
|
|
149
|
+
// so its not evaluated inside the script tag
|
|
150
|
+
return `/**${$2}*/`;
|
|
151
|
+
});
|
|
134
152
|
const lang = root.attributes?.lang;
|
|
135
|
-
const isTs = lang ===
|
|
153
|
+
const isTs = lang === "ts" || lang === '"ts"' || lang === "'ts'";
|
|
136
154
|
yield {
|
|
137
|
-
id:
|
|
138
|
-
languageId: isTs ?
|
|
155
|
+
id: "script_" + scripts++,
|
|
156
|
+
languageId: isTs ? "typescript" : "javascript",
|
|
139
157
|
snapshot: {
|
|
140
158
|
getText: (start, end) => `${text.substring(start, end)}
|
|
159
|
+
|
|
160
|
+
type AnalogComponentMetadata = Omit<import('@angular/core').Component, "template" |
|
|
161
|
+
"standalone" |
|
|
162
|
+
"changeDetection" |
|
|
163
|
+
"styles" |
|
|
164
|
+
"outputs" |
|
|
165
|
+
"inputs"> & { exposes: any[] };
|
|
166
|
+
|
|
141
167
|
/**
|
|
142
168
|
* Defines additional metadata for the component such as the
|
|
143
169
|
* selector, providers, and more.
|
|
144
170
|
*/
|
|
145
|
-
declare function defineMetadata(metadata:
|
|
171
|
+
declare function defineMetadata(metadata: AnalogComponentMetadata): void;
|
|
172
|
+
|
|
146
173
|
/**
|
|
147
174
|
* Defines the lifecycle hook(ngOnInit) that is called when the
|
|
148
175
|
* component is initialized.
|
|
149
176
|
*/
|
|
150
|
-
declare function onInit(
|
|
177
|
+
declare function onInit(initFn: () => void): void;
|
|
178
|
+
|
|
151
179
|
/**
|
|
152
180
|
* Defines the lifecycle hook(ngOnDestroy) that is called when the
|
|
153
181
|
* component is destroyed.
|
|
@@ -156,7 +184,8 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
156
184
|
getLength: () => text.length,
|
|
157
185
|
getChangeRange: () => undefined,
|
|
158
186
|
},
|
|
159
|
-
mappings: [
|
|
187
|
+
mappings: [
|
|
188
|
+
{
|
|
160
189
|
sourceOffsets: [root.startTagEnd],
|
|
161
190
|
generatedOffsets: [0],
|
|
162
191
|
lengths: [text.length],
|
|
@@ -168,23 +197,27 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
168
197
|
structure: true,
|
|
169
198
|
verification: true,
|
|
170
199
|
},
|
|
171
|
-
}
|
|
200
|
+
},
|
|
201
|
+
],
|
|
172
202
|
embeddedCodes: [],
|
|
173
203
|
};
|
|
174
204
|
}
|
|
175
|
-
if (root.tag ===
|
|
205
|
+
if (root.tag === "template" &&
|
|
206
|
+
root.startTagEnd !== undefined &&
|
|
207
|
+
root.endTagStart !== undefined) {
|
|
176
208
|
const text = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
177
209
|
const lang = root.attributes?.lang;
|
|
178
|
-
const isMd = lang ===
|
|
210
|
+
const isMd = lang === "md" || lang === '"md"' || lang === "'md'";
|
|
179
211
|
yield {
|
|
180
|
-
id:
|
|
181
|
-
languageId: isMd ?
|
|
212
|
+
id: "lang_" + langs++,
|
|
213
|
+
languageId: isMd ? "markdown" : "html",
|
|
182
214
|
snapshot: {
|
|
183
215
|
getText: (start, end) => text.substring(start, end),
|
|
184
216
|
getLength: () => text.length,
|
|
185
217
|
getChangeRange: () => undefined,
|
|
186
218
|
},
|
|
187
|
-
mappings: [
|
|
219
|
+
mappings: [
|
|
220
|
+
{
|
|
188
221
|
sourceOffsets: [root.startTagEnd],
|
|
189
222
|
generatedOffsets: [0],
|
|
190
223
|
lengths: [text.length],
|
|
@@ -196,12 +229,23 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
196
229
|
structure: true,
|
|
197
230
|
verification: true,
|
|
198
231
|
},
|
|
199
|
-
}
|
|
200
|
-
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
embeddedCodes: [
|
|
235
|
+
{
|
|
236
|
+
id: "lang_" + langs + "_ts",
|
|
237
|
+
languageId: "typescript",
|
|
238
|
+
snapshot: {
|
|
239
|
+
getText: (_start, _end) => `increment();`,
|
|
240
|
+
getLength: () => `void increment;`.length,
|
|
241
|
+
getChangeRange: () => undefined,
|
|
242
|
+
},
|
|
243
|
+
mappings: []
|
|
244
|
+
}
|
|
245
|
+
],
|
|
201
246
|
};
|
|
202
247
|
}
|
|
203
248
|
}
|
|
204
249
|
}
|
|
205
|
-
;
|
|
206
250
|
}
|
|
207
251
|
//# sourceMappingURL=languagePlugin.js.map
|