@analogjs/language-server 0.1.5 → 0.1.7
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.js +52 -15
- package/package.json +1 -1
package/out/languagePlugin.js
CHANGED
|
@@ -106,6 +106,45 @@ function createAnalogCode(snapshot) {
|
|
|
106
106
|
embeddedCodes: [...createEmbeddedCodes()],
|
|
107
107
|
htmlDocument,
|
|
108
108
|
};
|
|
109
|
+
function extractAnalogImports(code) {
|
|
110
|
+
const importRegex = /import\s*{(.*?)}\s+from\s+['"](.*?)['"];?/g;
|
|
111
|
+
const symbolMap = new Map();
|
|
112
|
+
const lines = code.split('\n');
|
|
113
|
+
lines.forEach(line => {
|
|
114
|
+
if (line.includes('analog:')) {
|
|
115
|
+
let match;
|
|
116
|
+
while ((match = importRegex.exec(line)) !== null) {
|
|
117
|
+
const symbols = match[1].split(',').map(symbol => symbol.trim());
|
|
118
|
+
const modulePath = match[2];
|
|
119
|
+
symbols.forEach(symbol => {
|
|
120
|
+
if (!symbolMap.has(symbol)) {
|
|
121
|
+
symbolMap.set(symbol, new Set());
|
|
122
|
+
}
|
|
123
|
+
symbolMap.get(symbol).add(modulePath);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
let symbols = [];
|
|
129
|
+
symbolMap.forEach((_, symbol) => {
|
|
130
|
+
symbols.push(symbol);
|
|
131
|
+
});
|
|
132
|
+
return symbols;
|
|
133
|
+
}
|
|
134
|
+
function extractTemplateVariables(code) {
|
|
135
|
+
const regex = /^(?!export\s)(let|const)\s+(\w+)\s*=\s*(.+?);|^(?!export\s)function\s+(\w+)\s*\(\s*\)\s*{/gm;
|
|
136
|
+
const matches = code.matchAll(regex);
|
|
137
|
+
let vars = [];
|
|
138
|
+
for (const match of matches) {
|
|
139
|
+
if (match[1]) {
|
|
140
|
+
vars.push(`${match[2]}`);
|
|
141
|
+
}
|
|
142
|
+
else if (match[4]) {
|
|
143
|
+
vars.push(`${match[4]}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return vars;
|
|
147
|
+
}
|
|
109
148
|
function* createEmbeddedCodes() {
|
|
110
149
|
let styles = 0;
|
|
111
150
|
let scripts = 0;
|
|
@@ -144,11 +183,14 @@ function createAnalogCode(snapshot) {
|
|
|
144
183
|
if (root.tag === "script" &&
|
|
145
184
|
root.startTagEnd !== undefined &&
|
|
146
185
|
root.endTagStart !== undefined) {
|
|
147
|
-
const
|
|
186
|
+
const originalText = snapshot.getText(root.startTagEnd, root.endTagStart);
|
|
187
|
+
const text = originalText.replace(/(with(((\n|\s)*).*)})/gm, function (_, _$1, $2) {
|
|
148
188
|
// replace "with { analog: 'imports' }" with "/**with { analog: 'imports' }*/"
|
|
149
189
|
// so its not evaluated inside the script tag
|
|
150
190
|
return `/**${$2}*/`;
|
|
151
191
|
});
|
|
192
|
+
const imports = extractAnalogImports(originalText);
|
|
193
|
+
const templateVars = extractTemplateVariables(originalText);
|
|
152
194
|
const lang = root.attributes?.lang;
|
|
153
195
|
const isTs = lang === "ts" || lang === '"ts"' || lang === "'ts'";
|
|
154
196
|
yield {
|
|
@@ -162,7 +204,7 @@ type AnalogComponentMetadata = Omit<import('@angular/core').Component, "template
|
|
|
162
204
|
"changeDetection" |
|
|
163
205
|
"styles" |
|
|
164
206
|
"outputs" |
|
|
165
|
-
"inputs"> & { exposes
|
|
207
|
+
"inputs"> & { exposes?: any[] };
|
|
166
208
|
|
|
167
209
|
/**
|
|
168
210
|
* Defines additional metadata for the component such as the
|
|
@@ -180,7 +222,13 @@ declare function onInit(initFn: () => void): void;
|
|
|
180
222
|
* Defines the lifecycle hook(ngOnDestroy) that is called when the
|
|
181
223
|
* component is destroyed.
|
|
182
224
|
*/
|
|
183
|
-
declare function onDestroy(destroyFn: () => void): void
|
|
225
|
+
declare function onDestroy(destroyFn: () => void): void;
|
|
226
|
+
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
[${templateVars.join(',')}];
|
|
229
|
+
|
|
230
|
+
// @ts-ignore
|
|
231
|
+
[${imports.join(',')}];`,
|
|
184
232
|
getLength: () => text.length,
|
|
185
233
|
getChangeRange: () => undefined,
|
|
186
234
|
},
|
|
@@ -231,18 +279,7 @@ declare function onDestroy(destroyFn: () => void): void;`,
|
|
|
231
279
|
},
|
|
232
280
|
},
|
|
233
281
|
],
|
|
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
|
-
],
|
|
282
|
+
embeddedCodes: [],
|
|
246
283
|
};
|
|
247
284
|
}
|
|
248
285
|
}
|