@x18n/lsp 0.0.12 → 0.0.14

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/index.d.mts CHANGED
@@ -97,6 +97,8 @@ export interface UsageReportResult {
97
97
  }
98
98
  export interface Decoration {
99
99
  readonly range: Range;
100
+ /** The whole call holding the key, when the scanner knows it. */
101
+ readonly expression?: Range | undefined;
100
102
  readonly key: string;
101
103
  readonly value: string | undefined;
102
104
  readonly state: "ok" | "missing" | "dynamic";
package/dist/src.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { relative, resolve, sep } from "node:path";
2
2
  import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { extractItems, findCandidates } from "@x18n/builtins/extractors";
4
- import { createLineIndex, createOverlayHost, isX18nError, renderPrompt } from "@x18n/core";
4
+ import { createLineIndex, createOverlayHost, isX18nError, joinKey, renderPrompt, splitKey } from "@x18n/core";
5
5
  import { loadWorkspace, migrateI18nAlly } from "@x18n/node";
6
6
  import { CodeActionKind, CompletionItemKind, DiagnosticSeverity, DidChangeWatchedFilesNotification, FileChangeType, ResponseError, SymbolKind, TextDocumentSyncKind, TextDocuments } from "vscode-languageserver";
7
7
  import { TextDocument } from "vscode-languageserver-textdocument";
@@ -28,7 +28,7 @@ const commands = {
28
28
  };
29
29
  //#endregion
30
30
  //#region package.json
31
- var version = "0.0.12";
31
+ var version = "0.0.14";
32
32
  //#endregion
33
33
  //#region src/server.ts
34
34
  const severities = {
@@ -61,7 +61,9 @@ function changedAt(change) {
61
61
  change.author
62
62
  ].filter(Boolean).join(" · ");
63
63
  }
64
- const posix = (path) => sep === "\\" ? path.replace(/\\/g, "/") : path;
64
+ function posix(path) {
65
+ return sep === "\\" ? path.replace(/\\/g, "/") : path;
66
+ }
65
67
  var Server = class {
66
68
  connection;
67
69
  options;
@@ -72,7 +74,8 @@ var Server = class {
72
74
  settings = {
73
75
  annotationMaxLength: 40,
74
76
  displayLocale: void 0,
75
- codeLens: false
77
+ codeLens: false,
78
+ showFlags: true
76
79
  };
77
80
  ready = Promise.resolve();
78
81
  folders = [];
@@ -178,6 +181,7 @@ var Server = class {
178
181
  if (typeof settings?.displayLocale === "string") this.settings.displayLocale = settings.displayLocale;
179
182
  if (typeof settings?.annotationMaxLength === "number") this.settings.annotationMaxLength = settings.annotationMaxLength;
180
183
  if (typeof settings?.codeLens === "boolean") this.settings.codeLens = settings.codeLens;
184
+ if (typeof settings?.showFlags === "boolean") this.settings.showFlags = settings.showFlags;
181
185
  return {
182
186
  serverInfo: {
183
187
  name: "x18n",
@@ -409,7 +413,8 @@ var Server = class {
409
413
  const value = display(project.lookup(target.key, locale)?.value);
410
414
  const change = changes[i];
411
415
  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}`);
416
+ const flag = this.settings.showFlags ? project.localeInfo(locale).flag : void 0;
417
+ lines.push(`| ${flag ?? ""} ${locale} | ${value === void 0 ? "_missing_" : value === "" ? "_empty_" : value.replace(/\|/g, "\\|").replace(/\n/g, " ")} |${changed}`);
413
418
  });
414
419
  }
415
420
  const usages = target.type === "subtree" ? project.usages({ prefix: target.key }) : project.usages({ key: target.key });
@@ -417,7 +422,7 @@ var Server = class {
417
422
  project: at.entry.name,
418
423
  key: target.key
419
424
  }]));
420
- lines.push("", `${usages.length} usage${usages.length === 1 ? "" : "s"} · [Open in UI](command:x18n.openKey?${args}) · [Copy translate prompt](command:x18n.copyTranslatePrompt?${args})`);
425
+ lines.push("", `${usages.length} usage${usages.length === 1 ? "" : "s"} · [Open in UI](command:x18n.openKey?${args}) · [Copy translate prompt](command:x18n.copyTranslatePrompt?${args}) · [Translate with agent](command:x18n.translateWithAgent?${args})`);
421
426
  return {
422
427
  contents: {
423
428
  kind: "markdown",
@@ -458,9 +463,16 @@ var Server = class {
458
463
  const scopeNs = usage?.scopeNamespace ?? project.config.namespace.default;
459
464
  const prefix = usage?.scopePrefix ? `${usage.scopePrefix}.` : "";
460
465
  const range = this.range(at.entry, at.path, slot);
461
- return project.keys().flatMap((key) => {
466
+ const { separator, fallback } = project.config.namespace;
467
+ const keys = project.keys();
468
+ const known = new Set(keys);
469
+ return keys.flatMap((key) => {
462
470
  let insert = key;
463
- if (project.namespaced && key.startsWith(`${scopeNs}:`)) insert = key.slice(scopeNs.length + 1);
471
+ if (project.namespaced) {
472
+ const { namespace, path } = splitKey(key);
473
+ const bare = path.join(".");
474
+ insert = namespace === scopeNs || namespace !== void 0 && fallback.includes(namespace) && !known.has(joinKey(scopeNs, path)) || namespace === void 0 ? bare : `${namespace}${separator}${bare}`;
475
+ }
464
476
  if (prefix) {
465
477
  if (!insert.startsWith(prefix)) return [];
466
478
  insert = insert.slice(prefix.length);
@@ -819,6 +831,7 @@ var Server = class {
819
831
  const state = usage.dynamic !== false ? "dynamic" : value === void 0 ? "missing" : "ok";
820
832
  return [{
821
833
  range: this.range(entry, path, usage.range),
834
+ ...usage.expression ? { expression: this.range(entry, path, usage.expression) } : {},
822
835
  key: usage.key,
823
836
  value,
824
837
  state
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x18n/lsp",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.14",
5
5
  "description": "x18n language server for any LSP editor",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -29,10 +29,10 @@
29
29
  "node": ">=22"
30
30
  },
31
31
  "dependencies": {
32
- "@x18n/builtins": "0.0.12",
33
- "@x18n/core": "0.0.12",
34
- "@x18n/node": "0.0.12",
35
- "@x18n/ui": "0.0.12",
32
+ "@x18n/builtins": "0.0.14",
33
+ "@x18n/core": "0.0.14",
34
+ "@x18n/node": "0.0.14",
35
+ "@x18n/ui": "0.0.14",
36
36
  "devframe": "^1.2.6",
37
37
  "vscode-languageserver": "^10.1.2",
38
38
  "vscode-languageserver-textdocument": "^1.0.15"