@dialexjs/language-server 0.7.2 → 0.9.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.mjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport {\n analyzeProject,\n clearGitignore,\n createAnalysisCache,\n generateDictionaries,\n readStaticConfig,\n renderGenerated,\n startGenerateWatcher,\n type AnalysisIssue,\n} from \"@dialexjs/cli/api\";\nimport { TextDocument } from \"vscode-languageserver-textdocument\";\nimport {\n CodeActionKind,\n CompletionItemKind,\n DiagnosticSeverity,\n DiagnosticTag,\n DidChangeWatchedFilesNotification,\n FileChangeType,\n TextDocumentSyncKind,\n TextDocuments,\n type CodeAction,\n type CompletionItem,\n type Connection,\n type Diagnostic,\n type Hover,\n type Location,\n type TextEdit,\n type InitializeParams,\n type InitializeResult,\n} from \"vscode-languageserver/node.js\";\n\nimport {\n addMissingKeys,\n addUnknownKey,\n buildHover,\n buildModel,\n completionContextAt,\n completionEntries,\n definitionFor,\n discoverProjects,\n findBindings,\n findReferenceAt,\n modelForFile,\n type CompletionEntry,\n type MissingKey,\n type ProjectModel,\n type ProjectRoot,\n} from \"./features.js\";\n\n/** What the client can configure under the `dialex` section. */\nexport interface Settings {\n /** Turn diagnostics, hover and the other features off. */\n enable: boolean;\n /** Fade out keys and dictionaries that no source file seems to use. */\n unusedKeys: boolean;\n /**\n * Regenerate `dialex.generated.ts` and `dialex-env.d.ts` when a dictionary or config file\n * changes, in projects that already have a generated file.\n */\n autoGenerate: boolean;\n /** Path to the Dialex config file, relative to each project root. */\n configPath?: string;\n}\n\nconst DEFAULT_SETTINGS: Settings = { enable: true, unusedKeys: false, autoGenerate: true };\n\n/** Files whose creation or removal can change the set of Dialex projects or what is scanned. */\nconst WATCHED_GLOBS = [\n \"**/*.content.ts\",\n \"**/dialex.config.*\",\n \"**/i18n.config.*\",\n \"**/.gitignore\",\n];\n\ninterface ProjectState {\n model: ProjectModel;\n issues: AnalysisIssue[];\n}\n\nexport interface DialexServer {\n /** Re-analyze every project now and publish diagnostics. */\n refresh(): Promise<void>;\n /** Regenerate the generated files of every project that has them, now. */\n regenerate(): Promise<void>;\n /** Stop file watchers and timers. */\n dispose(): Promise<void>;\n}\n\nfunction severityOf(issue: AnalysisIssue): DiagnosticSeverity {\n if (issue.code === \"unused-key\" || issue.code === \"unused-dictionary\") {\n return DiagnosticSeverity.Hint;\n }\n switch (issue.level) {\n case \"error\":\n return DiagnosticSeverity.Error;\n case \"warning\":\n return DiagnosticSeverity.Warning;\n default:\n return DiagnosticSeverity.Information;\n }\n}\n\n/** What a quick fix needs from the issue that produced a diagnostic. */\ninterface IssueData {\n code: string;\n path?: string[];\n locale?: string;\n sourceLocale?: string;\n dictionary?: string;\n}\n\nconst COMPLETION_KINDS: Record<CompletionEntry[\"kind\"], CompletionItemKind> = {\n dictionary: CompletionItemKind.Module,\n group: CompletionItemKind.Folder,\n leaf: CompletionItemKind.Text,\n};\n\n/** An edit that replaces a whole document, which is how dictionary files are rewritten. */\nfunction replaceAll(text: string, newText: string): TextEdit {\n const lines = text.split(\"\\n\");\n return {\n range: {\n start: { line: 0, character: 0 },\n end: { line: lines.length - 1, character: lines[lines.length - 1].length },\n },\n newText,\n };\n}\n\nfunction toDiagnostic(issue: AnalysisIssue): Diagnostic {\n const severity = severityOf(issue);\n return {\n range: issue.range\n ? {\n start: { line: issue.range.start.line, character: issue.range.start.column },\n end: { line: issue.range.end.line, character: issue.range.end.column },\n }\n : { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },\n message: issue.message,\n severity,\n source: \"dialex\",\n code: issue.code,\n tags: severity === DiagnosticSeverity.Hint ? [DiagnosticTag.Unnecessary] : undefined,\n data: {\n code: issue.code,\n path: issue.path,\n locale: issue.locale,\n sourceLocale: issue.sourceLocale,\n dictionary: issue.dictionary,\n } satisfies IssueData,\n };\n}\n\nconst uriToPath = (uri: string) => (uri.startsWith(\"file:\") ? fileURLToPath(uri) : undefined);\n\n/**\n * Wires Dialex's editor features to an LSP connection. Nothing in the project is executed:\n * dictionaries and configs are read from the syntax tree (`runtime: false`).\n */\nexport function createServer(connection: Connection): DialexServer {\n const documents = new TextDocuments(TextDocument);\n const cache = createAnalysisCache();\n const states = new Map<string, ProjectState>();\n const projectCache = new Map<string, ProjectRoot[]>();\n\n let folders: string[] = [];\n let canConfigure = false;\n let settings: Settings = { ...DEFAULT_SETTINGS };\n let published = new Set<string>();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let generateTimer: ReturnType<typeof setTimeout> | undefined;\n /** True when the client sends file events itself; otherwise the server watches the disk. */\n let clientWatches = false;\n const watchers = new Map<string, { close(): Promise<void> }>();\n\n const projectsIn = (folder: string): ProjectRoot[] => {\n let projects = projectCache.get(folder);\n if (!projects) {\n projects = discoverProjects(folder);\n projectCache.set(folder, projects);\n }\n return projects;\n };\n\n const forgetLayout = () => {\n projectCache.clear();\n clearGitignore(cache);\n };\n\n async function loadSettings(): Promise<void> {\n settings = { ...DEFAULT_SETTINGS };\n if (!canConfigure) return;\n try {\n const value = (await connection.workspace.getConfiguration(\"dialex\")) as\n | Partial<Settings>\n | null\n | undefined;\n if (value && typeof value === \"object\") {\n if (typeof value.enable === \"boolean\") settings.enable = value.enable;\n if (typeof value.unusedKeys === \"boolean\") settings.unusedKeys = value.unusedKeys;\n if (typeof value.autoGenerate === \"boolean\") settings.autoGenerate = value.autoGenerate;\n if (typeof value.configPath === \"string\" && value.configPath) {\n settings.configPath = value.configPath;\n }\n }\n } catch {\n // the client does not answer configuration requests; keep the defaults\n }\n }\n\n function publish(): void {\n const byFile = new Map<string, Diagnostic[]>();\n for (const { issues } of states.values()) {\n for (const issue of issues) {\n const list = byFile.get(issue.file) ?? [];\n list.push(toDiagnostic(issue));\n byFile.set(issue.file, list);\n }\n }\n\n const next = new Set<string>();\n for (const [file, diagnostics] of byFile) {\n const uri = pathToFileURL(file).href;\n next.add(uri);\n void connection.sendDiagnostics({ uri, diagnostics });\n }\n // Files that had problems before and have none now need an explicit empty list.\n for (const uri of published) {\n if (!next.has(uri)) void connection.sendDiagnostics({ uri, diagnostics: [] });\n }\n published = next;\n }\n\n /** The projects whose generated file exists; the others do not use one. */\n function generatedProjects(): { root: string; options: { config?: string; static: true } }[] {\n const found: { root: string; options: { config?: string; static: true } }[] = [];\n for (const folder of folders) {\n for (const { root } of projectsIn(folder)) {\n const options = { config: settings.configPath, static: true as const };\n try {\n if (fs.existsSync(renderGenerated(root, options).outputPath)) {\n found.push({ root, options });\n }\n } catch (error) {\n connection.console.error(`[${root}] generate failed: ${(error as Error).message}`);\n }\n }\n }\n return found;\n }\n\n /**\n * Keeps `dialex.generated.ts` and `dialex-env.d.ts` current. The config is read from its syntax\n * tree, so no project code runs.\n */\n async function regenerate(): Promise<void> {\n if (!settings.autoGenerate || !settings.enable) return;\n for (const { root, options } of generatedProjects()) {\n try {\n const { outputPath } = renderGenerated(root, options);\n const before = fs.readFileSync(outputPath, \"utf-8\");\n const { files } = generateDictionaries(root, options);\n if (fs.readFileSync(outputPath, \"utf-8\") !== before) {\n connection.console.info(\n `[${root}] regenerated ${outputPath.slice(root.length + 1)} (${files.length} dictionaries)`,\n );\n }\n } catch (error) {\n connection.console.error(`[${root}] generate failed: ${(error as Error).message}`);\n }\n }\n }\n\n /** Without client file events, watch each project that has a generated file ourselves. */\n async function syncWatchers(): Promise<void> {\n const wanted = new Map<string, { config?: string; static: true }>();\n if (!clientWatches && settings.autoGenerate && settings.enable) {\n for (const { root, options } of generatedProjects()) wanted.set(root, options);\n }\n\n for (const [root, watcher] of watchers) {\n if (!wanted.has(root)) {\n watchers.delete(root);\n await watcher.close();\n }\n }\n for (const [root, options] of wanted) {\n if (watchers.has(root)) continue;\n try {\n watchers.set(\n root,\n startGenerateWatcher(\n root,\n options,\n () => {\n void regenerate().then(() => schedule());\n },\n 250,\n (message) => connection.console.info(`[${root}] ${message}`),\n ),\n );\n } catch (error) {\n connection.console.error(`[${root}] could not watch: ${(error as Error).message}`);\n }\n }\n }\n\n async function refresh(): Promise<void> {\n await loadSettings();\n states.clear();\n\n if (settings.enable) {\n for (const folder of folders) {\n for (const { root, ignore } of projectsIn(folder)) {\n try {\n const { config, notes } = readStaticConfig(root, settings.configPath);\n for (const note of notes) connection.console.info(`[${root}] ${note}`);\n\n const result = await analyzeProject({\n root,\n config,\n runtime: false,\n ignore,\n unused: settings.unusedKeys,\n cache,\n });\n states.set(root, {\n model: buildModel(root, config.defaultLocale, result),\n issues: result.issues,\n });\n } catch (error) {\n connection.console.error(`[${root}] analysis failed: ${(error as Error).message}`);\n }\n }\n }\n }\n publish();\n await syncWatchers();\n }\n\n function schedule(): void {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => void refresh(), 300);\n }\n\n function scheduleGenerate(): void {\n if (generateTimer) clearTimeout(generateTimer);\n generateTimer = setTimeout(() => void regenerate(), 250);\n }\n\n connection.onInitialize((params: InitializeParams): InitializeResult => {\n folders = (params.workspaceFolders ?? [])\n .map((folder) => uriToPath(folder.uri))\n .filter((path): path is string => path !== undefined);\n if (folders.length === 0 && params.rootUri) {\n const root = uriToPath(params.rootUri);\n if (root) folders = [root];\n }\n canConfigure = params.capabilities.workspace?.configuration === true;\n clientWatches =\n params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true;\n\n return {\n capabilities: {\n textDocumentSync: {\n openClose: true,\n change: TextDocumentSyncKind.Incremental,\n save: { includeText: false },\n },\n hoverProvider: true,\n definitionProvider: true,\n completionProvider: { triggerCharacters: ['\"', \"'\", \"`\", \".\"] },\n codeActionProvider: { codeActionKinds: [CodeActionKind.QuickFix] },\n },\n serverInfo: { name: \"dialex-language-server\" },\n };\n });\n\n connection.onInitialized(async () => {\n if (clientWatches) {\n try {\n await connection.client.register(DidChangeWatchedFilesNotification.type, {\n watchers: WATCHED_GLOBS.map((globPattern) => ({ globPattern })),\n });\n } catch {\n // the client refused; the server watches the disk itself\n clientWatches = false;\n }\n }\n schedule();\n scheduleGenerate();\n });\n\n connection.onDidChangeConfiguration(() => schedule());\n\n connection.onDidChangeWatchedFiles(({ changes }) => {\n // An edit cannot change which projects exist; a file appearing or disappearing can.\n if (changes.some((change) => change.type !== FileChangeType.Changed)) projectCache.clear();\n if (changes.some((change) => change.uri.endsWith(\".gitignore\"))) forgetLayout();\n schedule();\n scheduleGenerate();\n });\n\n documents.onDidSave(() => {\n schedule();\n scheduleGenerate();\n });\n\n connection.onShutdown(() => dispose());\n\n /** The project model for a file, unless the features are turned off. */\n const modelFor = (file: string): ProjectModel | undefined =>\n settings.enable\n ? modelForFile(\n [...states.values()].map((state) => state.model),\n file,\n )\n : undefined;\n\n /** One line of an open document, without its line break. */\n const lineOf = (document: TextDocument, line: number): string =>\n document\n .getText({ start: { line, character: 0 }, end: { line: line + 1, character: 0 } })\n .replace(/\\r?\\n$/, \"\");\n\n connection.onHover((params): Hover | null => {\n const document = documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? modelFor(file) : undefined;\n if (!document || !model) return null;\n\n const ref = findReferenceAt(\n lineOf(document, params.position.line),\n params.position.character,\n findBindings(document.getText()),\n );\n const markdown = ref ? buildHover(model, ref) : undefined;\n if (!ref || !markdown) return null;\n\n return {\n contents: { kind: \"markdown\", value: markdown },\n range: {\n start: { line: params.position.line, character: ref.start },\n end: { line: params.position.line, character: ref.end },\n },\n };\n });\n\n connection.onDefinition((params): Location | null => {\n const document = documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? modelFor(file) : undefined;\n if (!document || !model) return null;\n\n const ref = findReferenceAt(\n lineOf(document, params.position.line),\n params.position.character,\n findBindings(document.getText()),\n );\n const target = ref ? definitionFor(model, ref) : undefined;\n if (!target) return null;\n\n return {\n uri: pathToFileURL(target.file).href,\n range: {\n start: { line: target.range.start.line, character: target.range.start.column },\n end: { line: target.range.end.line, character: target.range.end.column },\n },\n };\n });\n\n connection.onCompletion((params): CompletionItem[] => {\n const document = documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? modelFor(file) : undefined;\n if (!document || !model) return [];\n\n const before = lineOf(document, params.position.line).slice(0, params.position.character);\n const context = completionContextAt(before, findBindings(document.getText()));\n if (!context) return [];\n\n const range = {\n start: { line: params.position.line, character: params.position.character - context.length },\n end: params.position,\n };\n return completionEntries(model, context).map((entry) => ({\n label: entry.label,\n kind: COMPLETION_KINDS[entry.kind],\n detail: entry.detail,\n documentation: entry.documentation,\n filterText: entry.label,\n textEdit: { range, newText: entry.insertText },\n }));\n });\n\n connection.onCodeAction((params): CodeAction[] => {\n const file = uriToPath(params.textDocument.uri);\n const document = documents.get(params.textDocument.uri);\n if (!file || !document || !settings.enable) return [];\n\n const actions: CodeAction[] = [];\n const text = document.getText();\n const model = modelFor(file);\n\n for (const diagnostic of params.context.diagnostics) {\n const data = diagnostic.data as IssueData | undefined;\n if (diagnostic.source !== \"dialex\" || !data?.path) continue;\n\n if (data.code === \"missing-key\" && data.locale) {\n const updated = addMissingKeys(file, text, [\n { locale: data.locale, path: data.path, sourceLocale: data.sourceLocale },\n ]);\n if (!updated) continue;\n actions.push({\n title: `Add \"${data.path.join(\".\")}\" to ${data.locale} (marked [TODO])`,\n kind: CodeActionKind.QuickFix,\n diagnostics: [diagnostic],\n isPreferred: true,\n edit: { changes: { [params.textDocument.uri]: [replaceAll(text, updated)] } },\n });\n }\n\n if (data.code === \"unknown-path\" && data.dictionary) {\n const dictionary = model?.dictionaries.get(data.dictionary);\n if (!dictionary) continue;\n\n const dictionaryUri = pathToFileURL(dictionary.file).href;\n const open = documents.get(dictionaryUri);\n let dictionaryText: string;\n try {\n dictionaryText = open ? open.getText() : fs.readFileSync(dictionary.file, \"utf-8\");\n } catch {\n continue;\n }\n const updated = addUnknownKey(dictionary.file, dictionaryText, data.path);\n if (!updated) continue;\n actions.push({\n title: `Add \"${data.path.join(\".\")}\" to the \"${dictionary.name}\" dictionary`,\n kind: CodeActionKind.QuickFix,\n diagnostics: [diagnostic],\n edit: { changes: { [dictionaryUri]: [replaceAll(dictionaryText, updated)] } },\n });\n }\n }\n\n // One action for every missing key in this dictionary file\n const missing: MissingKey[] = [...states.values()]\n .flatMap((state) => state.issues)\n .filter((issue) => issue.file === file && issue.code === \"missing-key\")\n .filter((issue) => issue.locale && issue.path)\n .map((issue) => ({\n locale: issue.locale!,\n path: issue.path!,\n sourceLocale: issue.sourceLocale,\n }));\n if (missing.length > 1) {\n const updated = addMissingKeys(file, text, missing);\n if (updated) {\n actions.push({\n title: `Add all ${missing.length} missing keys (marked [TODO])`,\n kind: CodeActionKind.QuickFix,\n edit: { changes: { [params.textDocument.uri]: [replaceAll(text, updated)] } },\n });\n }\n }\n\n return actions;\n });\n\n documents.listen(connection);\n\n async function dispose(): Promise<void> {\n if (timer) clearTimeout(timer);\n if (generateTimer) clearTimeout(generateTimer);\n await Promise.all([...watchers.values()].map((watcher) => watcher.close()));\n watchers.clear();\n }\n\n return { refresh, regenerate, dispose };\n}\n"],"mappings":";;;;;;;AAmEA,MAAM,mBAA6B;CAAE,QAAQ;CAAM,YAAY;CAAO,cAAc;AAAK;;AAGzF,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;AACF;AAgBA,SAAS,WAAW,OAA0C;CAC5D,IAAI,MAAM,SAAS,gBAAgB,MAAM,SAAS,qBAChD,OAAO,mBAAmB;CAE5B,QAAQ,MAAM,OAAd;EACE,KAAK,SACH,OAAO,mBAAmB;EAC5B,KAAK,WACH,OAAO,mBAAmB;EAC5B,SACE,OAAO,mBAAmB;CAC9B;AACF;AAWA,MAAM,mBAAwE;CAC5E,YAAY,mBAAmB;CAC/B,OAAO,mBAAmB;CAC1B,MAAM,mBAAmB;AAC3B;;AAGA,SAAS,WAAW,MAAc,SAA2B;CAC3D,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,OAAO;EACL,OAAO;GACL,OAA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AC/C,SAAS,UAAU,MAAM,MAAM,CAAC,CAChC,QAAQ,UAAU,MAAM,SAAS,QAAQ,MAAM,SAAS,aAAa,CAAC,CACtE,QAAQ,UAAU,MAAM,UAAU,MAAM,IAAI,CAAC,CAC7C,KAAK,WAAW;GACf,QAAQ,MAAM;GACd,MAAM,MAAM;GACZ,cAAc,MAAM;EACtB,EAAE;EACJ,IAAI,QAAQ,SAAS,GAAG;GACtB,MAAM,UAAU,eAAe,MAAM,MAAM,OAAO;GAClD,IAAI,SACF,QAAQ,KAAK;IACX,OAAO,WAAW,QAAQ,OAAO;IACjC,MAAM,eAAe;IACrB,MAAM,EAAE,SAAS,GAAG,OAAO,aAAa,MAAM,CAAC,WAAW,MAAM,OAAO,CAAC,EAAE,EAAE;GAC9E,CAAC;EAEL;EAEA,OAAO;CACT,CAAC;CAED,UAAU,OAAO,UAAU;CAE3B,eAAe,UAAyB;EACtC,IAAI,OAAO,aAAa,KAAK;EAC7B,IAAI,eAAe,aAAa,aAAa;EAC7C,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,QAAQ,MAAM,CAAC,CAAC;EAC1E,SAAS,MAAM;CACjB;CAEA,OAAO;EAAE;EAAS;EAAY;CAAQ;AACxC"}
1
+ {"version":3,"file":"server.mjs","names":[],"sources":["../src/server/convert.ts","../src/server/diagnostics.ts","../src/server/generation.ts","../src/server/handlers.ts","../src/server/settings.ts","../src/server.ts"],"sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nimport type { TextDocument } from \"vscode-languageserver-textdocument\";\nimport { CompletionItemKind, type TextEdit } from \"vscode-languageserver/node.js\";\n\nimport type { CompletionEntry } from \"../features.js\";\n\nexport const COMPLETION_KINDS: Record<CompletionEntry[\"kind\"], CompletionItemKind> = {\n dictionary: CompletionItemKind.Module,\n group: CompletionItemKind.Folder,\n leaf: CompletionItemKind.Text,\n};\n\n/** An edit that replaces a whole document, which is how dictionary files are rewritten. */\nexport function replaceAll(text: string, newText: string): TextEdit {\n const lines = text.split(\"\\n\");\n return {\n range: {\n start: { line: 0, character: 0 },\n end: { line: lines.length - 1, character: lines[lines.length - 1].length },\n },\n newText,\n };\n}\n\nexport const uriToPath = (uri: string) =>\n uri.startsWith(\"file:\") ? fileURLToPath(uri) : undefined;\n\n/** One line of an open document, without its line break. */\nexport const lineOf = (document: TextDocument, line: number): string =>\n document\n .getText({ start: { line, character: 0 }, end: { line: line + 1, character: 0 } })\n .replace(/\\r?\\n$/, \"\");\n","import { pathToFileURL } from \"node:url\";\n\nimport type { AnalysisIssue } from \"@dialexjs/cli/api\";\nimport {\n DiagnosticSeverity,\n DiagnosticTag,\n type Connection,\n type Diagnostic,\n} from \"vscode-languageserver/node.js\";\n\nexport function severityOf(issue: AnalysisIssue): DiagnosticSeverity {\n if (issue.code === \"unused-key\" || issue.code === \"unused-dictionary\") {\n return DiagnosticSeverity.Hint;\n }\n switch (issue.level) {\n case \"error\":\n return DiagnosticSeverity.Error;\n case \"warning\":\n return DiagnosticSeverity.Warning;\n default:\n return DiagnosticSeverity.Information;\n }\n}\n\n/** What a quick fix needs from the issue that produced a diagnostic. */\nexport interface IssueData {\n code: string;\n path?: string[];\n locale?: string;\n sourceLocale?: string;\n dictionary?: string;\n}\n\nexport function toDiagnostic(issue: AnalysisIssue): Diagnostic {\n const severity = severityOf(issue);\n return {\n range: issue.range\n ? {\n start: { line: issue.range.start.line, character: issue.range.start.column },\n end: { line: issue.range.end.line, character: issue.range.end.column },\n }\n : { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },\n message: issue.message,\n severity,\n source: \"dialex\",\n code: issue.code,\n tags: severity === DiagnosticSeverity.Hint ? [DiagnosticTag.Unnecessary] : undefined,\n data: {\n code: issue.code,\n path: issue.path,\n locale: issue.locale,\n sourceLocale: issue.sourceLocale,\n dictionary: issue.dictionary,\n } satisfies IssueData,\n };\n}\n\n/**\n * Publishes the issues of every project, one list per file, and an explicit empty list for\n * files that had problems before and have none now.\n */\nexport function createPublisher(connection: Connection): (issues: AnalysisIssue[]) => void {\n let published = new Set<string>();\n\n return (issues) => {\n const byFile = new Map<string, Diagnostic[]>();\n for (const issue of issues) {\n const list = byFile.get(issue.file) ?? [];\n list.push(toDiagnostic(issue));\n byFile.set(issue.file, list);\n }\n\n const next = new Set<string>();\n for (const [file, diagnostics] of byFile) {\n const uri = pathToFileURL(file).href;\n next.add(uri);\n void connection.sendDiagnostics({ uri, diagnostics });\n }\n // Files that had problems before and have none now need an explicit empty list.\n for (const uri of published) {\n if (!next.has(uri)) void connection.sendDiagnostics({ uri, diagnostics: [] });\n }\n published = next;\n };\n}\n","import fs from \"node:fs\";\n\nimport { generateDictionaries, renderGenerated, startGenerateWatcher } from \"@dialexjs/cli/api\";\nimport type { Connection } from \"vscode-languageserver/node.js\";\n\nimport type { ProjectRoot } from \"../features.js\";\nimport type { Settings } from \"./settings.js\";\n\nexport interface GenerationContext {\n connection: Connection;\n folders(): string[];\n projectsIn(folder: string): ProjectRoot[];\n settings(): Settings;\n /** True when the client sends file events itself; otherwise the server watches the disk. */\n clientWatches(): boolean;\n /** Called after a watcher-triggered regeneration, so the analysis is refreshed. */\n afterWatchRegenerate(): void;\n}\n\n/** Keeps the generated files of the projects that have them current, and watches the disk. */\nexport function createGeneration(context: GenerationContext) {\n const { connection } = context;\n const watchers = new Map<string, { close(): Promise<void> }>();\n\n /** The projects whose generated file exists; the others do not use one. */\n function generatedProjects(): { root: string; options: { config?: string; static: true } }[] {\n const found: { root: string; options: { config?: string; static: true } }[] = [];\n for (const folder of context.folders()) {\n for (const { root } of context.projectsIn(folder)) {\n const options = { config: context.settings().configPath, static: true as const };\n try {\n if (fs.existsSync(renderGenerated(root, options).outputPath)) {\n found.push({ root, options });\n }\n } catch (error) {\n connection.console.error(`[${root}] generate failed: ${(error as Error).message}`);\n }\n }\n }\n return found;\n }\n\n /**\n * Keeps `dialex.generated.ts` and `dialex-env.d.ts` current. The config is read from its syntax\n * tree, so no project code runs.\n */\n async function regenerate(): Promise<void> {\n const settings = context.settings();\n if (!settings.autoGenerate || !settings.enable) return;\n for (const { root, options } of generatedProjects()) {\n try {\n const { outputPath } = renderGenerated(root, options);\n const before = fs.readFileSync(outputPath, \"utf-8\");\n const { files } = generateDictionaries(root, options);\n if (fs.readFileSync(outputPath, \"utf-8\") !== before) {\n connection.console.info(\n `[${root}] regenerated ${outputPath.slice(root.length + 1)} (${files.length} dictionaries)`,\n );\n }\n } catch (error) {\n connection.console.error(`[${root}] generate failed: ${(error as Error).message}`);\n }\n }\n }\n\n /** Without client file events, watch each project that has a generated file ourselves. */\n async function syncWatchers(): Promise<void> {\n const wanted = new Map<string, { config?: string; static: true }>();\n const settings = context.settings();\n if (!context.clientWatches() && settings.autoGenerate && settings.enable) {\n for (const { root, options } of generatedProjects()) wanted.set(root, options);\n }\n\n for (const [root, watcher] of watchers) {\n if (!wanted.has(root)) {\n watchers.delete(root);\n await watcher.close();\n }\n }\n for (const [root, options] of wanted) {\n if (watchers.has(root)) continue;\n try {\n watchers.set(\n root,\n startGenerateWatcher(\n root,\n options,\n () => {\n void regenerate().then(() => context.afterWatchRegenerate());\n },\n 250,\n (message) => connection.console.info(`[${root}] ${message}`),\n ),\n );\n } catch (error) {\n connection.console.error(`[${root}] could not watch: ${(error as Error).message}`);\n }\n }\n }\n\n async function dispose(): Promise<void> {\n await Promise.all([...watchers.values()].map((watcher) => watcher.close()));\n watchers.clear();\n }\n\n return { regenerate, syncWatchers, dispose };\n}\n","import fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\n\nimport type { AnalysisIssue } from \"@dialexjs/cli/api\";\nimport type { TextDocument } from \"vscode-languageserver-textdocument\";\nimport {\n CodeActionKind,\n type CodeAction,\n type CodeActionParams,\n type CompletionParams,\n type DefinitionParams,\n type HoverParams,\n type CompletionItem,\n type Hover,\n type Location,\n type TextDocuments,\n} from \"vscode-languageserver/node.js\";\n\nimport {\n addMissingKeys,\n addUnknownKey,\n buildHover,\n completionContextAt,\n completionEntries,\n definitionFor,\n findBindings,\n findReferenceAt,\n type MissingKey,\n type ProjectModel,\n} from \"../features.js\";\nimport { COMPLETION_KINDS, lineOf, replaceAll, uriToPath } from \"./convert.js\";\nimport type { IssueData } from \"./diagnostics.js\";\n\n/** What the request handlers read from the server. */\nexport interface HandlerContext {\n documents: TextDocuments<TextDocument>;\n /** The project model for a file, unless the features are turned off. */\n modelFor(file: string): ProjectModel | undefined;\n /** The issues of every project, in project order. */\n issues(): AnalysisIssue[];\n enabled(): boolean;\n}\n\nexport const hoverHandler =\n (ctx: HandlerContext) =>\n (params: HoverParams): Hover | null => {\n const document = ctx.documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? ctx.modelFor(file) : undefined;\n if (!document || !model) return null;\n\n const ref = findReferenceAt(\n lineOf(document, params.position.line),\n params.position.character,\n findBindings(document.getText()),\n );\n const markdown = ref ? buildHover(model, ref) : undefined;\n if (!ref || !markdown) return null;\n\n return {\n contents: { kind: \"markdown\", value: markdown },\n range: {\n start: { line: params.position.line, character: ref.start },\n end: { line: params.position.line, character: ref.end },\n },\n };\n };\n\nexport const definitionHandler =\n (ctx: HandlerContext) =>\n (params: DefinitionParams): Location | null => {\n const document = ctx.documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? ctx.modelFor(file) : undefined;\n if (!document || !model) return null;\n\n const ref = findReferenceAt(\n lineOf(document, params.position.line),\n params.position.character,\n findBindings(document.getText()),\n );\n const target = ref ? definitionFor(model, ref) : undefined;\n if (!target) return null;\n\n return {\n uri: pathToFileURL(target.file).href,\n range: {\n start: { line: target.range.start.line, character: target.range.start.column },\n end: { line: target.range.end.line, character: target.range.end.column },\n },\n };\n };\n\nexport const completionHandler =\n (ctx: HandlerContext) =>\n (params: CompletionParams): CompletionItem[] => {\n const document = ctx.documents.get(params.textDocument.uri);\n const file = uriToPath(params.textDocument.uri);\n const model = document && file ? ctx.modelFor(file) : undefined;\n if (!document || !model) return [];\n\n const before = lineOf(document, params.position.line).slice(0, params.position.character);\n const context = completionContextAt(before, findBindings(document.getText()));\n if (!context) return [];\n\n const range = {\n start: { line: params.position.line, character: params.position.character - context.length },\n end: params.position,\n };\n return completionEntries(model, context).map((entry) => ({\n label: entry.label,\n kind: COMPLETION_KINDS[entry.kind],\n detail: entry.detail,\n documentation: entry.documentation,\n filterText: entry.label,\n textEdit: { range, newText: entry.insertText },\n }));\n };\n\nexport const codeActionHandler =\n (ctx: HandlerContext) =>\n (params: CodeActionParams): CodeAction[] => {\n const file = uriToPath(params.textDocument.uri);\n const document = ctx.documents.get(params.textDocument.uri);\n if (!file || !document || !ctx.enabled()) return [];\n\n const actions: CodeAction[] = [];\n const text = document.getText();\n const model = ctx.modelFor(file);\n\n for (const diagnostic of params.context.diagnostics) {\n const data = diagnostic.data as IssueData | undefined;\n if (diagnostic.source !== \"dialex\" || !data?.path) continue;\n\n if (data.code === \"missing-key\" && data.locale) {\n const updated = addMissingKeys(file, text, [\n { locale: data.locale, path: data.path, sourceLocale: data.sourceLocale },\n ]);\n if (!updated) continue;\n actions.push({\n title: `Add \"${data.path.join(\".\")}\" to ${data.locale} (marked [TODO])`,\n kind: CodeActionKind.QuickFix,\n diagnostics: [diagnostic],\n isPreferred: true,\n edit: { changes: { [params.textDocument.uri]: [replaceAll(text, updated)] } },\n });\n }\n\n if (data.code === \"unknown-path\" && data.dictionary) {\n const dictionary = model?.dictionaries.get(data.dictionary);\n if (!dictionary) continue;\n\n const dictionaryUri = pathToFileURL(dictionary.file).href;\n const open = ctx.documents.get(dictionaryUri);\n let dictionaryText: string;\n try {\n dictionaryText = open ? open.getText() : fs.readFileSync(dictionary.file, \"utf-8\");\n } catch {\n continue;\n }\n const updated = addUnknownKey(dictionary.file, dictionaryText, data.path);\n if (!updated) continue;\n actions.push({\n title: `Add \"${data.path.join(\".\")}\" to the \"${dictionary.name}\" dictionary`,\n kind: CodeActionKind.QuickFix,\n diagnostics: [diagnostic],\n edit: { changes: { [dictionaryUri]: [replaceAll(dictionaryText, updated)] } },\n });\n }\n }\n\n // One action for every missing key in this dictionary file\n const missing: MissingKey[] = ctx\n .issues()\n .filter((issue) => issue.file === file && issue.code === \"missing-key\")\n .filter((issue) => issue.locale && issue.path)\n .map((issue) => ({\n locale: issue.locale!,\n path: issue.path!,\n sourceLocale: issue.sourceLocale,\n }));\n if (missing.length > 1) {\n const updated = addMissingKeys(file, text, missing);\n if (updated) {\n actions.push({\n title: `Add all ${missing.length} missing keys (marked [TODO])`,\n kind: CodeActionKind.QuickFix,\n edit: { changes: { [params.textDocument.uri]: [replaceAll(text, updated)] } },\n });\n }\n }\n\n return actions;\n };\n","/** What the client can configure under the `dialex` section. */\nexport interface Settings {\n /** Turn diagnostics, hover and the other features off. */\n enable: boolean;\n /**\n * Publish problems. Turn off when the ESLint or oxlint plugin reports them, to avoid showing\n * each twice; hover, completion and quick fixes keep working.\n */\n diagnostics: boolean;\n /** Fade out keys and dictionaries that no source file seems to use. */\n unusedKeys: boolean;\n /**\n * Regenerate `dialex.generated.ts` and `dialex-env.d.ts` when a dictionary or config file\n * changes, in projects that already have a generated file.\n */\n autoGenerate: boolean;\n /** Path to the Dialex config file, relative to each project root. */\n configPath?: string;\n}\n\nexport const DEFAULT_SETTINGS: Settings = {\n enable: true,\n diagnostics: true,\n unusedKeys: false,\n autoGenerate: true,\n};\n\n/** Files whose creation or removal can change the set of Dialex projects or what is scanned. */\nexport const WATCHED_GLOBS = [\n \"**/*.content.ts\",\n \"**/dialex.config.*\",\n \"**/i18n.config.*\",\n \"**/.gitignore\",\n];\n\n/** Copies the values the client sent for the `dialex` section onto `settings`. */\nexport function applyClientSettings(settings: Settings, value: unknown): void {\n const sent = value as Partial<Settings> | null | undefined;\n if (sent && typeof sent === \"object\") {\n if (typeof sent.enable === \"boolean\") settings.enable = sent.enable;\n if (typeof sent.diagnostics === \"boolean\") settings.diagnostics = sent.diagnostics;\n if (typeof sent.unusedKeys === \"boolean\") settings.unusedKeys = sent.unusedKeys;\n if (typeof sent.autoGenerate === \"boolean\") settings.autoGenerate = sent.autoGenerate;\n if (typeof sent.configPath === \"string\" && sent.configPath) {\n settings.configPath = sent.configPath;\n }\n }\n}\n","import {\n analyzeProject,\n clearGitignore,\n createAnalysisCache,\n readStaticConfig,\n type AnalysisIssue,\n} from \"@dialexjs/cli/api\";\nimport { TextDocument } from \"vscode-languageserver-textdocument\";\nimport {\n CodeActionKind,\n DidChangeWatchedFilesNotification,\n FileChangeType,\n TextDocumentSyncKind,\n TextDocuments,\n type Connection,\n type InitializeParams,\n type InitializeResult,\n} from \"vscode-languageserver/node.js\";\n\nimport {\n buildModel,\n discoverProjects,\n modelForFile,\n type ProjectModel,\n type ProjectRoot,\n} from \"./features.js\";\nimport { uriToPath } from \"./server/convert.js\";\nimport { createPublisher } from \"./server/diagnostics.js\";\nimport { createGeneration } from \"./server/generation.js\";\nimport {\n codeActionHandler,\n completionHandler,\n definitionHandler,\n hoverHandler,\n} from \"./server/handlers.js\";\nimport {\n applyClientSettings,\n DEFAULT_SETTINGS,\n WATCHED_GLOBS,\n type Settings,\n} from \"./server/settings.js\";\n\nexport type { Settings } from \"./server/settings.js\";\n\ninterface ProjectState {\n model: ProjectModel;\n issues: AnalysisIssue[];\n}\n\nexport interface DialexServer {\n /** Re-analyze every project now and publish diagnostics. */\n refresh(): Promise<void>;\n /** Regenerate the generated files of every project that has them, now. */\n regenerate(): Promise<void>;\n /** Stop file watchers and timers. */\n dispose(): Promise<void>;\n}\n\n/**\n * Wires Dialex's editor features to an LSP connection. Nothing in the project is executed:\n * dictionaries and configs are read from the syntax tree (`runtime: false`).\n */\nexport function createServer(connection: Connection): DialexServer {\n const documents = new TextDocuments(TextDocument);\n const cache = createAnalysisCache();\n const states = new Map<string, ProjectState>();\n const projectCache = new Map<string, ProjectRoot[]>();\n const publish = createPublisher(connection);\n\n let folders: string[] = [];\n let canConfigure = false;\n let settings: Settings = { ...DEFAULT_SETTINGS };\n let timer: ReturnType<typeof setTimeout> | undefined;\n let generateTimer: ReturnType<typeof setTimeout> | undefined;\n /** True when the client sends file events itself; otherwise the server watches the disk. */\n let clientWatches = false;\n\n const projectsIn = (folder: string): ProjectRoot[] => {\n let projects = projectCache.get(folder);\n if (!projects) {\n projects = discoverProjects(folder);\n projectCache.set(folder, projects);\n }\n return projects;\n };\n\n const forgetLayout = () => {\n projectCache.clear();\n clearGitignore(cache);\n };\n\n const generation = createGeneration({\n connection,\n folders: () => folders,\n projectsIn,\n settings: () => settings,\n clientWatches: () => clientWatches,\n afterWatchRegenerate: () => schedule(),\n });\n\n async function loadSettings(): Promise<void> {\n settings = { ...DEFAULT_SETTINGS };\n if (!canConfigure) return;\n try {\n applyClientSettings(settings, await connection.workspace.getConfiguration(\"dialex\"));\n } catch {\n // the client does not answer configuration requests; keep the defaults\n }\n }\n\n async function refresh(): Promise<void> {\n await loadSettings();\n states.clear();\n\n if (settings.enable) {\n for (const folder of folders) {\n for (const { root, ignore } of projectsIn(folder)) {\n try {\n const { config, notes } = readStaticConfig(root, settings.configPath);\n for (const note of notes) connection.console.info(`[${root}] ${note}`);\n\n const result = await analyzeProject({\n root,\n config,\n runtime: false,\n ignore,\n unused: settings.unusedKeys,\n cache,\n });\n states.set(root, {\n model: buildModel(root, config.defaultLocale, result),\n issues: result.issues,\n });\n } catch (error) {\n connection.console.error(`[${root}] analysis failed: ${(error as Error).message}`);\n }\n }\n }\n }\n publish(settings.diagnostics ? allIssues() : []);\n await generation.syncWatchers();\n }\n\n function schedule(): void {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => void refresh(), 300);\n }\n\n function scheduleGenerate(): void {\n if (generateTimer) clearTimeout(generateTimer);\n generateTimer = setTimeout(() => void generation.regenerate(), 250);\n }\n\n connection.onInitialize((params: InitializeParams): InitializeResult => {\n folders = (params.workspaceFolders ?? [])\n .map((folder) => uriToPath(folder.uri))\n .filter((path): path is string => path !== undefined);\n if (folders.length === 0 && params.rootUri) {\n const root = uriToPath(params.rootUri);\n if (root) folders = [root];\n }\n canConfigure = params.capabilities.workspace?.configuration === true;\n clientWatches =\n params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true;\n\n return {\n capabilities: {\n textDocumentSync: {\n openClose: true,\n change: TextDocumentSyncKind.Incremental,\n save: { includeText: false },\n },\n hoverProvider: true,\n definitionProvider: true,\n completionProvider: { triggerCharacters: ['\"', \"'\", \"`\", \".\"] },\n codeActionProvider: { codeActionKinds: [CodeActionKind.QuickFix] },\n },\n serverInfo: { name: \"dialex-language-server\" },\n };\n });\n\n connection.onInitialized(async () => {\n if (clientWatches) {\n try {\n await connection.client.register(DidChangeWatchedFilesNotification.type, {\n watchers: WATCHED_GLOBS.map((globPattern) => ({ globPattern })),\n });\n } catch {\n // the client refused; the server watches the disk itself\n clientWatches = false;\n }\n }\n schedule();\n scheduleGenerate();\n });\n\n connection.onDidChangeConfiguration(() => schedule());\n\n connection.onDidChangeWatchedFiles(({ changes }) => {\n // An edit cannot change which projects exist; a file appearing or disappearing can.\n if (changes.some((change) => change.type !== FileChangeType.Changed)) projectCache.clear();\n if (changes.some((change) => change.uri.endsWith(\".gitignore\"))) forgetLayout();\n schedule();\n scheduleGenerate();\n });\n\n documents.onDidSave(() => {\n schedule();\n scheduleGenerate();\n });\n\n connection.onShutdown(() => dispose());\n\n /** The project model for a file, unless the features are turned off. */\n const modelFor = (file: string): ProjectModel | undefined =>\n settings.enable\n ? modelForFile(\n [...states.values()].map((state) => state.model),\n file,\n )\n : undefined;\n\n /** The issues of every project, in project order. */\n const allIssues = (): AnalysisIssue[] => [...states.values()].flatMap((state) => state.issues);\n\n const handlers = { documents, modelFor, issues: allIssues, enabled: () => settings.enable };\n connection.onHover(hoverHandler(handlers));\n connection.onDefinition(definitionHandler(handlers));\n connection.onCompletion(completionHandler(handlers));\n connection.onCodeAction(codeActionHandler(handlers));\n\n documents.listen(connection);\n\n async function dispose(): Promise<void> {\n if (timer) clearTimeout(timer);\n if (generateTimer) clearTimeout(generate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
4
4
  "description": "Language server (LSP) for Dialex translations: diagnostics, hover, go to definition, completion and quick fixes",
5
5
  "keywords": [
6
6
  "dialex",
@@ -43,7 +43,7 @@
43
43
  "check": "vp check"
44
44
  },
45
45
  "dependencies": {
46
- "@dialexjs/cli": "0.7.2",
46
+ "@dialexjs/cli": "0.9.2",
47
47
  "vscode-languageserver": "^9.0.1",
48
48
  "vscode-languageserver-textdocument": "^1.0.12"
49
49
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"features.mjs","names":[],"sources":["../src/features/model.ts","../src/features/bindings.ts","../src/features/references.ts","../src/features/hover.ts","../src/features/definition.ts","../src/features/completion.ts","../src/features/quickfix.ts","../src/features/projects.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport type { AnalysisResult, AnalyzedDictionary } from \"@dialexjs/cli/api\";\n\n/** What the editor features know about one Dialex project (a folder with its own config). */\nexport interface ProjectModel {\n root: string;\n defaultLocale: string;\n dictionaries: Map<string, AnalyzedDictionary>;\n}\n\nexport function buildModel(\n root: string,\n defaultLocale: string,\n result: Pick<AnalysisResult, \"dictionaries\">,\n): ProjectModel {\n return {\n root,\n defaultLocale,\n dictionaries: new Map(result.dictionaries.map((d) => [d.name, d])),\n };\n}\n\n/** The model whose root contains `file`, preferring the deepest (nested projects). */\nexport function modelForFile(\n models: Iterable<ProjectModel>,\n file: string,\n): ProjectModel | undefined {\n let best: ProjectModel | undefined;\n for (const model of models) {\n const rel = path.relative(model.root, file);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) continue;\n if (!best || model.root.length > best.root.length) best = model;\n }\n return best;\n}\n\n/** Locales with the default locale first. */\nexport function orderedLocales(model: ProjectModel, dictionary: AnalyzedDictionary): string[] {\n return [\n ...dictionary.locales.filter((l) => l === model.defaultLocale),\n ...dictionary.locales.filter((l) => l !== model.defaultLocale),\n ];\n}\n","/** Variable name -> dictionary name, for `const s = useDictionary(\"showcase\")`. */\nexport type Bindings = ReadonlyMap<string, string>;\n\n/**\n * `const s = useDictionary(\"showcase\")`, `const home = await getDictionary(\"home\", locale)`,\n * `let t: Home = injectDictionary<Home>(\"home\")`: a variable that holds a dictionary.\n */\nconst DECLARATION =\n /\\b(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=\\n]+)?=\\s*(?:await\\s+)?(?:[A-Za-z_$][\\w$]*\\.)*(?:getDictionary|useDictionary|injectDictionary)\\s*(?:<[^()]*?>)?\\(\\s*([\"'`])([^\"'`$\\n]+)\\2/g;\n\n/**\n * Finds the variables in a file that hold a dictionary, so `s.nav.features` can be resolved to\n * `showcase.nav.features`. It is a text match: a variable that is reassigned or shadowed in another\n * scope may resolve to the wrong dictionary, which only affects editor hints.\n */\nexport function findBindings(text: string): Bindings {\n const bindings = new Map<string, string>();\n for (const match of text.matchAll(DECLARATION)) {\n bindings.set(match[1], match[3]);\n }\n return bindings;\n}\n","import { scanReferences, type AnalyzedDictionary, type Reference } from \"@dialexjs/cli/api\";\n\nimport type { Bindings } from \"./bindings.js\";\nimport type { ProjectModel } from \"./model.js\";\n\n/** `getDictionary(\"home\").nav.about` -> the `.nav.about` member chain after the call. */\nconst MEMBER_CHAIN =\n /(?:getDictionary|useDictionary)\\(\\s*([\"'`])([^\"'`$\\n]+)\\1[^()\\n]*\\)((?:\\??\\.[A-Za-z_$][\\w$]*)+)/dg;\n\nconst escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/**\n * The Dialex reference under the cursor on one line of code: a dictionary name, a `t(\"a.b.c\")`\n * path, a member of `getDictionary(\"a\")` such as `.title`, or, with `bindings`, a member of a\n * variable that holds a dictionary (`s.nav.features` after `const s = useDictionary(\"showcase\")`).\n * Offsets are into `lineText`.\n */\nexport function findReferenceAt(\n lineText: string,\n character: number,\n bindings?: Bindings,\n): Reference | undefined {\n const direct = scanReferences(lineText).find((r) => character >= r.start && character <= r.end);\n if (direct) return direct;\n\n for (const match of lineText.matchAll(MEMBER_CHAIN)) {\n const dictionary = match[2];\n const [chainStart] = match.indices![3] as [number, number];\n const members = /\\??\\.([A-Za-z_$][\\w$]*)/g;\n const keys: string[] = [];\n for (const member of match[3].matchAll(members)) {\n const start = chainStart + member.index! + member[0].length - member[1].length;\n const end = start + member[1].length;\n keys.push(member[1]);\n if (character >= start && character <= end) {\n return { kind: \"path\", value: [dictionary, ...keys].join(\".\"), start, end };\n }\n }\n }\n\n for (const [name, dictionary] of bindings ?? []) {\n const chain = new RegExp(\n `(?<![\\\\w$.])${escapeRegExp(name)}(?![\\\\w$])((?:\\\\??\\\\.[A-Za-z_$][\\\\w$]*)*)`,\n \"dg\",\n );\n for (const match of lineText.matchAll(chain)) {\n const nameStart = match.index!;\n const nameEnd = nameStart + name.length;\n if (character >= nameStart && character <= nameEnd) {\n return { kind: \"dictionary\", value: dictionary, start: nameStart, end: nameEnd };\n }\n\n const [chainStart] = match.indices![1] as [number, number];\n const keys: string[] = [];\n for (const member of match[1].matchAll(/\\??\\.([A-Za-z_$][\\w$]*)/g)) {\n const start = chainStart + member.index! + member[0].length - member[1].length;\n const end = start + member[1].length;\n keys.push(member[1]);\n if (character >= start && character <= end) {\n return { kind: \"path\", value: [dictionary, ...keys].join(\".\"), start, end };\n }\n }\n }\n }\n return undefined;\n}\n\nexport interface ResolvedReference {\n dictionary: AnalyzedDictionary;\n /** Empty for a reference to the dictionary itself. */\n keyPath: string[];\n}\n\nexport function resolveReference(\n model: ProjectModel,\n ref: Reference,\n): ResolvedReference | undefined {\n if (ref.kind === \"dictionary\") {\n const dictionary = model.dictionaries.get(ref.value);\n return dictionary ? { dictionary, keyPath: [] } : undefined;\n }\n const [name, ...keyPath] = ref.value.split(\".\");\n const dictionary = model.dictionaries.get(name);\n return dictionary ? { dictionary, keyPath } : undefined;\n}\n\n/** Whether `keyPath` is a leaf, a group of leaves, or nothing in this dictionary. */\nexport function classifyPath(\n dictionary: AnalyzedDictionary,\n keyPath: string[],\n): \"leaf\" | \"group\" | \"missing\" {\n const joined = keyPath.join(\".\");\n if (dictionary.paths.includes(joined)) return \"leaf\";\n return dictionary.paths.some((p) => p.startsWith(`${joined}.`)) ? \"group\" : \"missing\";\n}\n","import path from \"node:path\";\n\nimport { getLeafSource, type AnalyzedDictionary, type Reference } from \"@dialexjs/cli/api\";\n\nimport { orderedLocales, type ProjectModel } from \"./model.js\";\nimport { classifyPath, resolveReference } from \"./references.js\";\n\n/** Escapes Markdown so translation text cannot change the hover's formatting. */\nexport function escapeMarkdown(text: string): string {\n return text\n .replace(/[\\\\`*_{}[\\]()#+!|<>~]/g, \"\\\\$&\")\n .replace(/\\r?\\n/g, \"<br>\")\n .slice(0, 400);\n}\n\nfunction cell(dictionary: AnalyzedDictionary, locale: string, keyPath: string[]): string {\n const leaf = dictionary.leaves.get(locale)?.get(keyPath.join(\".\"));\n if (!leaf) return \"_missing_\";\n if (leaf.kind === \"string\") return escapeMarkdown(leaf.value ?? \"\");\n if (leaf.kind === \"function\") {\n const source = dictionary.df ? getLeafSource(dictionary.df, locale, keyPath) : undefined;\n return source\n ? `\\`${source.replace(/`/g, \"'\").replace(/\\s+/g, \" \").slice(0, 160)}\\``\n : \"_function_\";\n }\n return \"_value_\";\n}\n\n/**\n * Markdown for a hover over a Dialex reference: every locale's text for a key, or a summary of a\n * dictionary. Returns `undefined` for unknown references (diagnostics already flag those).\n */\nexport function buildHover(model: ProjectModel, ref: Reference): string | undefined {\n const resolved = resolveReference(model, ref);\n if (!resolved) return undefined;\n const { dictionary, keyPath } = resolved;\n const file = path.basename(dictionary.file);\n\n if (keyPath.length === 0) {\n return [\n `**${dictionary.name}** · ${file}`,\n \"\",\n `${dictionary.paths.length} key${dictionary.paths.length === 1 ? \"\" : \"s\"} · locales: ${dictionary.locales.join(\", \")}`,\n ].join(\"\\n\");\n }\n\n const kind = classifyPath(dictionary, keyPath);\n const title = `**${dictionary.name}.${keyPath.join(\".\")}** · ${file}`;\n\n if (kind === \"missing\") return undefined;\n\n if (kind === \"group\") {\n const prefix = `${keyPath.join(\".\")}.`;\n const children = new Set(\n dictionary.paths\n .filter((p) => p.startsWith(prefix))\n .map((p) => p.slice(prefix.length).split(\".\")[0]),\n );\n return `${title}\\n\\n${children.size} key${children.size === 1 ? \"\" : \"s\"}: ${[...children].map((c) => `\\`${c}\\``).join(\", \")}`;\n }\n\n const rows = orderedLocales(model, dictionary).map(\n (locale) => `| ${locale} | ${cell(dictionary, locale, keyPath)} |`,\n );\n return [title, \"\", \"| Locale | Text |\", \"| --- | --- |\", ...rows].join(\"\\n\");\n}\n","import { dictionaryLocation, locationOf, type SourceRange } from \"@dialexjs/cli/api\";\nimport type { Reference } from \"@dialexjs/cli/api\";\n\nimport { orderedLocales, type ProjectModel } from \"./model.js\";\nimport { resolveReference } from \"./references.js\";\n\nexport interface DefinitionTarget {\n file: string;\n range: SourceRange;\n}\n\nconst START: SourceRange = { start: { line: 0, column: 0 }, end: { line: 0, column: 0 } };\n\n/**\n * Where a reference is defined: the key in the default locale if it has one, otherwise in the\n * first locale that does. A dictionary reference points at the dictionary object.\n */\nexport function definitionFor(model: ProjectModel, ref: Reference): DefinitionTarget | undefined {\n const resolved = resolveReference(model, ref);\n if (!resolved) return undefined;\n const { dictionary, keyPath } = resolved;\n const { df } = dictionary;\n if (!df) return { file: dictionary.file, range: START };\n\n if (keyPath.length === 0) {\n return { file: dictionary.file, range: dictionaryLocation(df) ?? START };\n }\n\n for (const locale of orderedLocales(model, dictionary)) {\n const range = locationOf(df, locale, keyPath);\n if (range) return { file: dictionary.file, range };\n }\n return undefined;\n}\n","import type { AnalyzedDictionary } from \"@dialexjs/cli/api\";\n\nimport type { Bindings } from \"./bindings.js\";\nimport type { ProjectModel } from \"./model.js\";\n\nexport type CompletionContext =\n | { kind: \"dictionary\"; call: string; typed: string; length: number }\n | { kind: \"path\"; dictionary: string; parent: string[]; typed: string; length: number };\n\nconst CALL = /(?<![\\w$.])(t|getDictionary|useDictionary|DialexDictionary)\\(\\s*([\"'`])([^\"'`\\n]*)$/;\n\n/**\n * Whether the cursor is inside the string argument of a Dialex call, and what is being typed.\n * `textBeforeCursor` is the line up to the cursor. `length` is how many characters before the\n * cursor a completion replaces.\n */\nexport function completionContextAt(\n textBeforeCursor: string,\n bindings?: Bindings,\n): CompletionContext | undefined {\n const match = CALL.exec(textBeforeCursor);\n if (!match) return bindings ? memberContextAt(textBeforeCursor, bindings) : undefined;\n const [, call, , value] = match;\n\n if (call === \"t\" && value.includes(\".\")) {\n const segments = value.split(\".\");\n const typed = segments.pop()!;\n const [dictionary, ...parent] = segments;\n return { kind: \"path\", dictionary, parent, typed, length: typed.length };\n }\n return { kind: \"dictionary\", call, typed: value, length: value.length };\n}\n\n/** `s.nav.fe|` where `s` holds a dictionary: the keys under `nav` that start with `fe`. */\nfunction memberContextAt(\n textBeforeCursor: string,\n bindings: Bindings,\n): CompletionContext | undefined {\n for (const [name, dictionary] of bindings) {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const match = new RegExp(\n `(?<![\\\\w$.])${escaped}((?:\\\\??\\\\.[A-Za-z_$][\\\\w$]*)*)\\\\??\\\\.([A-Za-z_$][\\\\w$]*)?$`,\n ).exec(textBeforeCursor);\n if (!match) continue;\n\n const parent = [...match[1].matchAll(/\\??\\.([A-Za-z_$][\\w$]*)/g)].map((m) => m[1]);\n const typed = match[2] ?? \"\";\n return { kind: \"path\", dictionary, parent, typed, length: typed.length };\n }\n return undefined;\n}\n\nexport interface CompletionEntry {\n label: string;\n kind: \"dictionary\" | \"group\" | \"leaf\";\n detail: string;\n /** Text to insert in place of what was typed. */\n insertText: string;\n /** Re-open the suggestion list after inserting (after `home.` or `nav.`). */\n retrigger: boolean;\n documentation?: string;\n}\n\nconst preview = (text: string | undefined) =>\n text === undefined ? undefined : text.length > 60 ? `${text.slice(0, 57)}...` : text;\n\nfunction dictionaryEntries(\n model: ProjectModel,\n context: Extract<CompletionContext, { kind: \"dictionary\" }>,\n) {\n return [...model.dictionaries.values()]\n .filter((d) => d.name.startsWith(context.typed))\n .map<CompletionEntry>((d) => {\n // t(\"home.title\") continues with a dot; getDictionary(\"home\") is complete as is\n const continues = context.call === \"t\";\n return {\n label: d.name,\n kind: \"dictionary\",\n detail: `${d.paths.length} keys · ${d.locales.join(\", \")}`,\n insertText: continues ? `${d.name}.` : d.name,\n retrigger: continues,\n };\n });\n}\n\nfunction pathEntries(\n model: ProjectModel,\n dictionary: AnalyzedDictionary,\n context: Extract<CompletionContext, { kind: \"path\" }>,\n) {\n const prefix = context.parent.length > 0 ? `${context.parent.join(\".\")}.` : \"\";\n const children = new Map<string, { leaf: boolean }>();\n\n for (const keyPath of dictionary.paths) {\n if (!keyPath.startsWith(prefix)) continue;\n const rest = keyPath.slice(prefix.length).split(\".\");\n const name = rest[0];\n if (!name.startsWith(context.typed)) continue;\n const entry = children.get(name) ?? { leaf: true };\n if (rest.length > 1) entry.leaf = false;\n children.set(name, entry);\n }\n\n return [...children].map<CompletionEntry>(([name, { leaf }]) => {\n const full = `${prefix}${name}`;\n const holder = [model.defaultLocale, ...dictionary.locales].find((l) =>\n dictionary.leaves.get(l)?.has(full),\n );\n const text = holder ? dictionary.leaves.get(holder)!.get(full)! : undefined;\n return {\n label: name,\n kind: leaf ? \"leaf\" : \"group\",\n detail: leaf\n ? (preview(text?.kind === \"string\" ? text.value : text ? `(${text.kind})` : undefined) ??\n \"\")\n : \"keys…\",\n insertText: leaf ? name : `${name}.`,\n retrigger: !leaf,\n };\n });\n}\n\n/** Suggestions for the string being typed, filtered by what is already there. */\nexport function completionEntries(\n model: ProjectModel,\n context: CompletionContext,\n): CompletionEntry[] {\n if (context.kind === \"dictionary\") return dictionaryEntries(model, context);\n const dictionary = model.dictionaries.get(context.dictionary);\n return dictionary ? pathEntries(model, dictionary, context) : [];\n}\n","import {\n TODO_PREFIX,\n copyLeaf,\n hasPath,\n listLocales,\n parseDictionaryText,\n renderDictionaryFile,\n setString,\n} from \"@dialexjs/cli/api\";\n\nexport interface MissingKey {\n locale: string;\n path: string[];\n /** A locale that has the key, to copy its value from. */\n sourceLocale?: string;\n}\n\n/**\n * New text for a dictionary file with `missing` keys added to their locales, copied from the\n * source locale (strings get the `[TODO] ` marker, like `dialex check --fix`). Returns\n * `undefined` if nothing could be added.\n */\nexport function addMissingKeys(\n file: string,\n text: string,\n missing: MissingKey[],\n): string | undefined {\n const df = parseDictionaryText(file, text);\n if (!df) return undefined;\n\n let changed = false;\n for (const { locale, path, sourceLocale } of missing) {\n if (!sourceLocale) continue;\n if (copyLeaf(df, sourceLocale, locale, path, (value) => `${TODO_PREFIX}${value}`))\n changed = true;\n }\n return changed ? renderDictionaryFile(df) : undefined;\n}\n\n/**\n * New text for a dictionary file with a key that code refers to but the dictionary lacks, added\n * to every locale as a `[TODO]` placeholder named after the key.\n */\nexport function addUnknownKey(file: string, text: string, keyPath: string[]): string | undefined {\n const df = parseDictionaryText(file, text);\n if (!df) return undefined;\n\n const placeholder = `${TODO_PREFIX}${keyPath[keyPath.length - 1]}`;\n let changed = false;\n for (const locale of listLocales(df)) {\n if (\n !hasPath(df, locale, keyPath) &&\n setString(df, locale, keyPath, placeholder) !== \"skipped\"\n ) {\n changed = true;\n }\n }\n return changed ? renderDictionaryFile(df) : undefined;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { scanFiles } from \"@dialexjs/cli/api\";\n\nexport interface ProjectRoot {\n root: string;\n /** Globs (relative to `root`) for nested projects that belong to someone else. */\n ignore: string[];\n}\n\n// On top of the CLI's built-in list and the project's `.gitignore` files.\nconst IGNORE = [\"**/.git/**\", \"**/.nuxt/**\"];\n\n/** The nearest folder at or above `dir` (but inside `folder`) that has a package.json. */\nfunction packageRoot(folder: string, dir: string): string {\n for (let current = dir; current.startsWith(folder); current = path.dirname(current)) {\n if (fs.existsSync(path.join(current, \"package.json\"))) return current;\n if (current === folder) break;\n }\n return folder;\n}\n\n/**\n * Finds the Dialex projects inside a workspace folder.\n *\n * - Every directory with a `dialex.config.*` or `i18n.config.*` is a project.\n * - A `*.content.ts` file that no such project contains belongs to the nearest folder with a\n * `package.json` (or the workspace folder), which then uses the default settings. This covers\n * monorepos where only some packages have a config file.\n * - A project excludes the projects nested inside it, so one dictionary is never reported twice.\n */\nexport function discoverProjects(folder: string): ProjectRoot[] {\n const configs = scanFiles(folder, [\"**/dialex.config.*\", \"**/i18n.config.*\"], {\n ignore: IGNORE,\n });\n const configured = [...new Set(configs.map((f) => path.dirname(f)))];\n const roots = new Set(configured);\n\n // Judge coverage against the configured projects only; a fallback root must not hide others.\n const dictionaries = scanFiles(folder, \"**/*.content.ts\", { ignore: IGNORE });\n for (const file of dictionaries) {\n if (!configured.some((root) => file.startsWith(root + path.sep))) {\n roots.add(packageRoot(folder, path.dirname(file)));\n }\n }\n\n const all = [...roots].sort((a, b) => a.length - b.length);\n return all.map((root) => ({\n root,\n ignore: all\n .filter((other) => other !== root && other.startsWith(root + path.sep))\n .map((other) => `${path.relative(root, other).split(path.sep).join(\"/\")}/**`),\n }));\n}\n"],"mappings":";;;;AAWA,SAAgB,WACd,MACA,eACA,QACc;CACd,OAAO;EACL;EACA;EACA,cAAc,IAAI,IAAI,OAAO,aAAa,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CACnE;AACF;;AAGA,SAAgB,aACd,QACA,MAC0B;CAC1B,IAAI;CACJ,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,MAAM,KAAK,SAAS,MAAM,MAAM,IAAI;EAC1C,IAAI,IAAI,WAAW,IAAI,KAAK,KAAK,WAAW,GAAG,GAAG;EAClD,IAAI,CAAC,QAAQ,MAAM,KAAK,SAAS,KAAK,KAAK,QAAQ,OAAO;CAC5D;CACA,OAAO;AACT;;AAGA,SAAgB,eAAe,OAAqB,YAA0C;CAC5F,OAAO,CACL,GAAG,WAAW,QAAQ,QAAQ,MAAM,MAAM,MAAM,aAAa,GAC7D,GAAG,WAAW,QAAQ,QAAQ,MAAM,MAAM,MAAM,aAAa,CAC/D;AACF;;;;;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