@x18n/lsp 0.0.3 → 0.0.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/dist/src.mjs +39 -15
- package/package.json +10 -10
package/dist/src.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const commands = {
|
|
|
28
28
|
};
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region package.json
|
|
31
|
-
var version = "0.0.
|
|
31
|
+
var version = "0.0.5";
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/server.ts
|
|
34
34
|
const severities = {
|
|
@@ -43,6 +43,24 @@ function truncate(text, max) {
|
|
|
43
43
|
function display(value) {
|
|
44
44
|
return value === void 0 ? void 0 : typeof value === "string" ? value : JSON.stringify(value);
|
|
45
45
|
}
|
|
46
|
+
const timeUnits = [
|
|
47
|
+
["year", 31536e6],
|
|
48
|
+
["month", 2592e6],
|
|
49
|
+
["week", 6048e5],
|
|
50
|
+
["day", 864e5],
|
|
51
|
+
["hour", 36e5],
|
|
52
|
+
["minute", 6e4]
|
|
53
|
+
];
|
|
54
|
+
function changedAt(change) {
|
|
55
|
+
if (!Number.isFinite(change.updatedAt)) return "changed locally";
|
|
56
|
+
const diff = change.updatedAt - Date.now();
|
|
57
|
+
const [unit, size] = timeUnits.find(([, size]) => Math.abs(diff) >= size) ?? ["minute", 6e4];
|
|
58
|
+
return [
|
|
59
|
+
new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(Math.round(diff / size), unit),
|
|
60
|
+
change.revision?.slice(0, 7),
|
|
61
|
+
change.author
|
|
62
|
+
].filter(Boolean).join(" · ");
|
|
63
|
+
}
|
|
46
64
|
const posix = (path) => sep === "\\" ? path.replace(/\\/g, "/") : path;
|
|
47
65
|
var Server = class {
|
|
48
66
|
connection;
|
|
@@ -140,14 +158,17 @@ var Server = class {
|
|
|
140
158
|
});
|
|
141
159
|
});
|
|
142
160
|
}
|
|
143
|
-
for (const entry of this.projects)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
for (const entry of this.projects) {
|
|
162
|
+
entry.project.onChange((change) => {
|
|
163
|
+
this.connection.sendNotification(methods.changed, {
|
|
164
|
+
project: entry.name,
|
|
165
|
+
revision: change.revision,
|
|
166
|
+
keys: change.keys
|
|
167
|
+
});
|
|
168
|
+
this.publishDiagnostics();
|
|
148
169
|
});
|
|
149
|
-
|
|
150
|
-
}
|
|
170
|
+
entry.project.loadHistory({ watch: true });
|
|
171
|
+
}
|
|
151
172
|
}
|
|
152
173
|
async initialize(params) {
|
|
153
174
|
const folders = params.workspaceFolders?.map((folder) => fileURLToPath(folder.uri)) ?? (params.rootUri ? [fileURLToPath(params.rootUri)] : []);
|
|
@@ -285,9 +306,7 @@ var Server = class {
|
|
|
285
306
|
const target = at && at.entry.project.keyAt(at.path, at.offset);
|
|
286
307
|
if (!at || !target) return null;
|
|
287
308
|
const { project } = at.entry;
|
|
288
|
-
|
|
289
|
-
const entries = params.context.includeDeclaration || target.source === "usage" ? project.locations(target.key).map((node) => this.entryLocation(at.entry, node)) : [];
|
|
290
|
-
return [...usages, ...entries];
|
|
309
|
+
return (target.type === "subtree" ? project.usages({ prefix: target.key }) : project.usages({ key: target.key })).map((m) => this.location(at.entry, m.usage.path, m.usage.range));
|
|
291
310
|
}
|
|
292
311
|
async prepareRename(params) {
|
|
293
312
|
await this.ready;
|
|
@@ -382,11 +401,16 @@ var Server = class {
|
|
|
382
401
|
const { project } = at.entry;
|
|
383
402
|
const lines = [`**x18n** \`${target.key}\``, ""];
|
|
384
403
|
if (target.type === "key") {
|
|
385
|
-
|
|
386
|
-
|
|
404
|
+
const changes = project.locales.map((locale) => project.history(target.key, locale));
|
|
405
|
+
const dated = changes.some(Boolean);
|
|
406
|
+
const outdated = new Set(project.analyze().coverage.filter((c) => c.outdated.includes(target.key)).map((c) => c.locale));
|
|
407
|
+
lines.push(dated ? "| | | |" : "| | |", dated ? "| --- | --- | --- |" : "| --- | --- |");
|
|
408
|
+
project.locales.forEach((locale, i) => {
|
|
387
409
|
const value = display(project.lookup(target.key, locale)?.value);
|
|
388
|
-
|
|
389
|
-
|
|
410
|
+
const change = changes[i];
|
|
411
|
+
const changed = dated ? ` ${change ? changedAt(change).replace(/\|/g, "\\|") : ""}${outdated.has(locale) ? " · **outdated**" : ""} |` : "";
|
|
412
|
+
lines.push(`| ${project.localeInfo(locale).flag ?? ""} ${locale} | ${value === void 0 ? "_missing_" : value === "" ? "_empty_" : value.replace(/\|/g, "\\|").replace(/\n/g, " ")} |${changed}`);
|
|
413
|
+
});
|
|
390
414
|
}
|
|
391
415
|
const usages = target.type === "subtree" ? project.usages({ prefix: target.key }) : project.usages({ key: target.key });
|
|
392
416
|
const args = encodeURIComponent(JSON.stringify([{
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x18n/lsp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "x18n language server for any LSP editor",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://github.com/
|
|
8
|
+
"homepage": "https://github.com/x18n-dev/x18n#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/x18n-dev/x18n.git",
|
|
12
12
|
"directory": "packages/lsp"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://github.com/
|
|
14
|
+
"bugs": "https://github.com/x18n-dev/x18n/issues",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"exports": {
|
|
17
17
|
".": "./dist/index.mjs",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"node": ">=22"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@x18n/builtins": "0.0.
|
|
33
|
-
"@x18n/core": "0.0.
|
|
34
|
-
"@x18n/node": "0.0.
|
|
35
|
-
"@x18n/ui": "0.0.
|
|
36
|
-
"devframe": "^1.2.
|
|
32
|
+
"@x18n/builtins": "0.0.5",
|
|
33
|
+
"@x18n/core": "0.0.5",
|
|
34
|
+
"@x18n/node": "0.0.5",
|
|
35
|
+
"@x18n/ui": "0.0.5",
|
|
36
|
+
"devframe": "^1.2.6",
|
|
37
37
|
"vscode-languageserver": "^10.1.2",
|
|
38
38
|
"vscode-languageserver-textdocument": "^1.0.15"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"vscode-jsonrpc": "^9.0.
|
|
41
|
+
"vscode-jsonrpc": "^9.0.3"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsdown",
|