@intlayer/lsp 8.11.3 → 9.0.0-canary.12
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/esm/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/esm/callers/index.mjs +12 -0
- package/dist/esm/callers/index.mjs.map +1 -0
- package/dist/esm/callers/patterns.mjs +37 -0
- package/dist/esm/callers/patterns.mjs.map +1 -0
- package/dist/esm/dictionaryUtils.mjs +84 -0
- package/dist/esm/dictionaryUtils.mjs.map +1 -0
- package/dist/esm/findFieldInFile.mjs +53 -0
- package/dist/esm/findFieldInFile.mjs.map +1 -0
- package/dist/esm/findKeyAtOffset.mjs +20 -10
- package/dist/esm/findKeyAtOffset.mjs.map +1 -1
- package/dist/esm/findKeyInContentFile.mjs +350 -0
- package/dist/esm/findKeyInContentFile.mjs.map +1 -0
- package/dist/esm/findTCallAtOffset.mjs +33 -0
- package/dist/esm/findTCallAtOffset.mjs.map +1 -0
- package/dist/esm/findUsageFieldAtOffset.mjs +33 -0
- package/dist/esm/findUsageFieldAtOffset.mjs.map +1 -0
- package/dist/esm/index.mjs +533 -38
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/oxcUtils.mjs +130 -0
- package/dist/esm/oxcUtils.mjs.map +1 -0
- package/dist/esm/usageAnalyzer.mjs +692 -0
- package/dist/esm/usageAnalyzer.mjs.map +1 -0
- package/dist/esm/utils.mjs +17 -0
- package/dist/types/callers/index.d.ts +8 -0
- package/dist/types/callers/index.d.ts.map +1 -0
- package/dist/types/callers/patterns.d.ts +30 -0
- package/dist/types/callers/patterns.d.ts.map +1 -0
- package/dist/types/dictionaryUtils.d.ts +12 -0
- package/dist/types/dictionaryUtils.d.ts.map +1 -0
- package/dist/types/findFieldInFile.d.ts +28 -0
- package/dist/types/findFieldInFile.d.ts.map +1 -0
- package/dist/types/findKeyAtOffset.d.ts +14 -3
- package/dist/types/findKeyAtOffset.d.ts.map +1 -1
- package/dist/types/findKeyInContentFile.d.ts +33 -0
- package/dist/types/findKeyInContentFile.d.ts.map +1 -0
- package/dist/types/findTCallAtOffset.d.ts +24 -0
- package/dist/types/findTCallAtOffset.d.ts.map +1 -0
- package/dist/types/findUsageFieldAtOffset.d.ts +23 -0
- package/dist/types/findUsageFieldAtOffset.d.ts.map +1 -0
- package/dist/types/oxcUtils.d.ts +53 -0
- package/dist/types/oxcUtils.d.ts.map +1 -0
- package/dist/types/usageAnalyzer.d.ts +129 -0
- package/dist/types/usageAnalyzer.d.ts.map +1 -0
- package/dist/types/utils.d.ts +19 -0
- package/package.json +18 -24
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync, readFileSync } from 'node:fs';\nimport { isAbsolute, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { getConfiguration } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n createConnection,\n type InitializeParams,\n type InitializeResult,\n Location,\n Position,\n ProposedFeatures,\n Range,\n TextDocumentSyncKind,\n TextDocuments,\n} from 'vscode-languageserver/node.js';\nimport { TextDocument } from 'vscode-languageserver-textdocument';\nimport { findKeyAtOffset } from './findKeyAtOffset';\n\n// Create a connection for the server, using Node's IPC as a transport.\n// Also include all preview / proposed LSP features.\nconst connection = createConnection(ProposedFeatures.all);\n\n// Create a simple text document manager.\nconst documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\nlet workspaceRoot: string | null | undefined;\n\n/**\n * Resolve (and cache) the Intlayer configuration for the current workspace.\n * The LSP process cwd is not the project root, so we must resolve the config\n * from `workspaceRoot` to get the right `system`/`build` paths.\n */\nlet cachedConfig: Pick<IntlayerConfig, 'system' | 'build'> | null = null;\nconst getWorkspaceConfig = () => {\n if (cachedConfig) return cachedConfig;\n if (!workspaceRoot) return null;\n\n const { system, build } = getConfiguration({ baseDir: workspaceRoot });\n cachedConfig = { system, build };\n return cachedConfig;\n};\n\n/**\n * Return every `.content` file location that declares the given key.\n * A key can be split across several content files (merged dictionaries), so we\n * return one `Location` per source file, pointing at the `key:` declaration.\n */\nconst getContentDeclarationLocations = (key: string): Location[] => {\n const config = getWorkspaceConfig();\n if (!config) return [];\n\n const unmergedDictionaries = getUnmergedDictionaries(config);\n\n const dictionaries = Object.values(unmergedDictionaries)\n .flat()\n .filter((dictionary) => dictionary?.key === key && dictionary.filePath);\n\n const locations: Location[] = [];\n\n for (const dictionary of dictionaries) {\n const filePath = dictionary.filePath!;\n const absolutePath = isAbsolute(filePath)\n ? filePath\n : join(config.system.baseDir, filePath);\n\n if (!existsSync(absolutePath)) continue;\n\n locations.push(\n Location.create(\n pathToFileURL(absolutePath).href,\n getKeyRange(absolutePath, key)\n )\n );\n }\n\n return locations;\n};\n\n/** Find the `key: \"<key>\"` line inside a content file so the cursor lands on it. */\nconst getKeyRange = (absolutePath: string, key: string): Range => {\n try {\n const content = readFileSync(absolutePath, 'utf-8');\n const lines = content.split(/\\r?\\n/);\n const keyRegex = new RegExp(\n `key\\\\s*:\\\\s*['\"\\`]${key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}['\"\\`]`\n );\n\n for (let line = 0; line < lines.length; line++) {\n const column = lines[line].search(keyRegex);\n if (column !== -1) {\n return Range.create(\n Position.create(line, column),\n Position.create(line, lines[line].length)\n );\n }\n }\n } catch {\n // fall through to the top of the file\n }\n\n return Range.create(Position.create(0, 0), Position.create(0, 0));\n};\n\nconnection.onInitialize((params: InitializeParams): InitializeResult => {\n workspaceRoot =\n params.rootPath ||\n (params.workspaceFolders?.[0]?.uri\n ? decodeURIComponent(new URL(params.workspaceFolders[0].uri).pathname)\n : undefined);\n cachedConfig = null;\n\n return {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n // Declare that this server provides \"Go to Definition\" support\n definitionProvider: true,\n },\n };\n});\n\nconnection.onDefinition((params) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) return null;\n\n const text = document.getText();\n const offset = document.offsetAt(params.position);\n\n const key = findKeyAtOffset(text, offset);\n if (key) {\n const locations = getContentDeclarationLocations(key);\n return locations.length ? locations : null;\n }\n\n return null;\n});\n\n// Make the text document manager listen on the connection\n// for open, change and close text document events\ndocuments.listen(connection);\n\n// Listen on the connection\nconnection.listen();\n"],"mappings":";;;;;;;;;;;AAuBA,MAAM,aAAa,iBAAiB,iBAAiB,GAAG;AAGxD,MAAM,YAAyC,IAAI,cAAc,YAAY;AAE7E,IAAI;;;;;;AAOJ,IAAI,eAAgE;AACpE,MAAM,2BAA2B;CAC/B,IAAI,cAAc,OAAO;CACzB,IAAI,CAAC,eAAe,OAAO;CAE3B,MAAM,EAAE,QAAQ,UAAU,iBAAiB,EAAE,SAAS,cAAc,CAAC;CACrE,eAAe;EAAE;EAAQ;CAAM;CAC/B,OAAO;AACT;;;;;;AAOA,MAAM,kCAAkC,QAA4B;CAClE,MAAM,SAAS,mBAAmB;CAClC,IAAI,CAAC,QAAQ,OAAO,CAAC;CAErB,MAAM,uBAAuB,wBAAwB,MAAM;CAE3D,MAAM,eAAe,OAAO,OAAO,oBAAoB,EACpD,KAAK,EACL,QAAQ,eAAe,YAAY,QAAQ,OAAO,WAAW,QAAQ;CAExE,MAAM,YAAwB,CAAC;CAE/B,KAAK,MAAM,cAAc,cAAc;EACrC,MAAM,WAAW,WAAW;EAC5B,MAAM,eAAe,WAAW,QAAQ,IACpC,WACA,KAAK,OAAO,OAAO,SAAS,QAAQ;EAExC,IAAI,CAAC,WAAW,YAAY,GAAG;EAE/B,UAAU,KACR,SAAS,OACP,cAAc,YAAY,EAAE,MAC5B,YAAY,cAAc,GAAG,CAC/B,CACF;CACF;CAEA,OAAO;AACT;;AAGA,MAAM,eAAe,cAAsB,QAAuB;CAChE,IAAI;EAEF,MAAM,QADU,aAAa,cAAc,OACvB,EAAE,MAAM,OAAO;EACnC,MAAM,WAAW,IAAI,OACnB,qBAAqB,IAAI,QAAQ,uBAAuB,MAAM,EAAE,OAClE;EAEA,KAAK,IAAI,OAAO,GAAG,OAAO,MAAM,QAAQ,QAAQ;GAC9C,MAAM,SAAS,MAAM,MAAM,OAAO,QAAQ;GAC1C,IAAI,WAAW,IACb,OAAO,MAAM,OACX,SAAS,OAAO,MAAM,MAAM,GAC5B,SAAS,OAAO,MAAM,MAAM,MAAM,MAAM,CAC1C;EAEJ;CACF,QAAQ,CAER;CAEA,OAAO,MAAM,OAAO,SAAS,OAAO,GAAG,CAAC,GAAG,SAAS,OAAO,GAAG,CAAC,CAAC;AAClE;AAEA,WAAW,cAAc,WAA+C;CACtE,gBACE,OAAO,aACN,OAAO,mBAAmB,IAAI,MAC3B,mBAAmB,IAAI,IAAI,OAAO,iBAAiB,GAAG,GAAG,EAAE,QAAQ,IACnE;CACN,eAAe;CAEf,OAAO,EACL,cAAc;EACZ,kBAAkB,qBAAqB;EAEvC,oBAAoB;CACtB,EACF;AACF,CAAC;AAED,WAAW,cAAc,WAAW;CAClC,MAAM,WAAW,UAAU,IAAI,OAAO,aAAa,GAAG;CACtD,IAAI,CAAC,UAAU,OAAO;CAKtB,MAAM,MAAM,gBAHC,SAAS,QAGS,GAFhB,SAAS,SAAS,OAAO,QAED,CAAC;CACxC,IAAI,KAAK;EACP,MAAM,YAAY,+BAA+B,GAAG;EACpD,OAAO,UAAU,SAAS,YAAY;CACxC;CAEA,OAAO;AACT,CAAC;AAID,UAAU,OAAO,UAAU;AAG3B,WAAW,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { buildComponentFilesList } from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type CompletionItem,\n CompletionItemKind,\n type CompletionParams,\n createConnection,\n type Diagnostic,\n DiagnosticSeverity,\n type Hover,\n type HoverParams,\n type InitializeParams,\n type InitializeResult,\n Location,\n MarkupKind,\n Position,\n ProposedFeatures,\n Range,\n type ReferenceParams,\n TextDocumentSyncKind,\n TextDocuments,\n} from 'vscode-languageserver/node';\nimport { TextDocument } from 'vscode-languageserver-textdocument';\nimport {\n buildCallerWithKeyPattern,\n buildKeyUsagePatterns,\n getCallerNamesAlternation,\n} from './callers/patterns';\nimport {\n formatDictionaryHover,\n formatFieldHover,\n formatFieldValue,\n getFieldByPath,\n getFieldsAtPath,\n} from './dictionaryUtils';\nimport {\n escapeRegularExpression,\n findFieldRangesInFile,\n offsetToRange,\n} from './findFieldInFile';\nimport { findKeyAtOffset } from './findKeyAtOffset';\nimport {\n findContentFieldAtOffset,\n findKeyInContentFile,\n} from './findKeyInContentFile';\nimport { type OxcNode, parseText, walkAst } from './oxcUtils';\nimport {\n collectNamespaceReferences,\n findMessageUsageAtOffset,\n matchCallNamespace,\n} from './usageAnalyzer';\n\n// Create a connection for the server, using Node's IPC as a transport.\n// Also include all preview / proposed LSP features.\nconst connection = createConnection(ProposedFeatures.all);\n\n// Create a simple text document manager.\nconst documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\n/**\n * Send a log line to the client's Output panel (View → Output → \"Intlayer LSP\").\n * Uses connection.console.log so it travels over the JSON-RPC channel and never\n * touches stdout (which is reserved for the LSP protocol).\n */\nconst log = (message: string): void =>\n connection.console.log(`[Intlayer LSP] ${message}`);\n\nlet workspaceRoot: string | null | undefined;\n\ntype WorkspaceConfig = Pick<\n IntlayerConfig,\n 'system' | 'build' | 'content' | 'compiler'\n>;\n\n/**\n * Resolve (and cache) the Intlayer configuration for the current workspace.\n * The LSP process cwd is not the project root, so we must resolve the config\n * from `workspaceRoot` to get the right `system`/`build`/`content` paths.\n */\nconst projectConfigs = new Map<string, WorkspaceConfig>();\n\ntype DictionariesCache = {\n dictionaries: ReturnType<typeof getUnmergedDictionaries>;\n cachedAt: number;\n};\nconst projectDictionaries = new Map<string, DictionariesCache>();\nconst DICTIONARY_CACHE_TTL_MS = 5_000;\n\ntype SourceFilesCache = {\n files: string[];\n cachedAt: number;\n};\nconst projectSourceFiles = new Map<string, SourceFilesCache>();\nconst SOURCE_FILES_CACHE_TTL_MS = 30_000;\n\nconst invalidateConfigCaches = () => {\n projectConfigs.clear();\n projectDictionaries.clear();\n\n projectSourceFiles.clear();\n};\n\nconst getProjectConfig = (absolutePath: string): WorkspaceConfig | null => {\n try {\n const baseDir = dirname(absolutePath);\n // Find the closest intlayer config relative to the file.\n const { system, build, content, compiler } = getConfiguration({ baseDir });\n const cacheKey = system.baseDir;\n\n if (!projectConfigs.has(cacheKey)) {\n projectConfigs.set(cacheKey, { system, build, content, compiler });\n log(\n `getProjectConfig — OK baseDir=${system.baseDir} unmergedDictionariesDir=${system.unmergedDictionariesDir}`\n );\n }\n return projectConfigs.get(cacheKey)!;\n } catch (error) {\n log(`getProjectConfig — FAILED: ${error}`);\n return null;\n }\n};\n\nconst getUnmergedDictionariesCached = (\n config: WorkspaceConfig\n): ReturnType<typeof getUnmergedDictionaries> => {\n const cacheKey = config.system.baseDir;\n const cached = projectDictionaries.get(cacheKey);\n const now = Date.now();\n\n if (cached && now - cached.cachedAt < DICTIONARY_CACHE_TTL_MS) {\n return cached.dictionaries;\n }\n\n const dictionaries = getUnmergedDictionaries(config);\n projectDictionaries.set(cacheKey, { dictionaries, cachedAt: now });\n return dictionaries;\n};\n\n// ---------------------------------------------------------------------------\n// Pattern helpers — derived lazily from the live config.\n// ---------------------------------------------------------------------------\n\nconst isContentFile = (uri: string, config: WorkspaceConfig): boolean => {\n const fileExtensions = config.content.fileExtensions ?? [];\n return fileExtensions.some((extension) => uri.endsWith(extension));\n};\n\n// ---------------------------------------------------------------------------\n// Async I/O helpers\n// ---------------------------------------------------------------------------\n\n/** Read a file as UTF-8, returning null on any error. */\nconst tryReadFile = async (filePath: string): Promise<string | null> => {\n try {\n return await readFile(filePath, 'utf-8');\n } catch {\n return null;\n }\n};\n\n/**\n * Run `callback` over every item with at most `limit` tasks in-flight at once.\n * JS is single-threaded so `results.push` inside callback is race-free.\n */\nconst runConcurrent = async <T>(\n items: T[],\n callback: (item: T) => Promise<void>,\n limit = 50\n): Promise<void> => {\n if (items.length === 0) return;\n let index = 0;\n const worker = async () => {\n while (index < items.length) {\n await callback(items[index++]!);\n }\n };\n await Promise.all(\n Array.from({ length: Math.min(limit, items.length) }, worker)\n );\n};\n\n/** Find the `key: \"<key>\"` line inside a content file so the cursor lands on it. */\nconst getKeyRange = async (\n absolutePath: string,\n key: string\n): Promise<Range> => {\n try {\n const content = await readFile(absolutePath, 'utf-8');\n const lines = content.split(/\\r?\\n/);\n const keyRegularExpression = new RegExp(\n `key\\\\s*:\\\\s*['\"\\`]${key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}['\"\\`]`\n );\n\n for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {\n const column = lines[lineIndex]?.search(keyRegularExpression);\n\n if (column !== undefined && column !== -1) {\n return Range.create(\n Position.create(lineIndex, column),\n Position.create(lineIndex, lines[lineIndex]!.length)\n );\n }\n }\n } catch {\n // fall through to the top of the file\n }\n\n return Range.create(Position.create(0, 0), Position.create(0, 0));\n};\n\n/**\n * Return every `.content` file location that declares the given key.\n * A key can be split across several content files (merged dictionaries), so we\n * return one `Location` per source file, pointing at the `key:` declaration.\n */\nconst getContentDeclarationLocations = async (\n key: string,\n absolutePath: string\n): Promise<Location[]> => {\n const config = getProjectConfig(absolutePath);\n\n if (!config) return [];\n\n const unmergedDictionaries = getUnmergedDictionariesCached(config);\n const dictionaries = Object.values(unmergedDictionaries)\n .flat()\n .filter((dictionary) => dictionary?.key === key && dictionary.filePath);\n\n const locations: Location[] = [];\n\n await runConcurrent(dictionaries, async (dictionary) => {\n const filePath = dictionary.filePath!;\n const absolutePath = isAbsolute(filePath)\n ? filePath\n : join(config.system.baseDir, filePath);\n\n if (!existsSync(absolutePath)) return;\n\n locations.push(\n Location.create(\n pathToFileURL(absolutePath).href,\n await getKeyRange(absolutePath, key)\n )\n );\n });\n\n return locations;\n};\n\n/**\n * Return the cached source-file list, re-scanning only when the cache has\n * expired or been explicitly invalidated (config change, watched-file event).\n */\nconst getSourceFiles = async (\n directory: string,\n config: WorkspaceConfig\n): Promise<string[]> => {\n const now = Date.now();\n const cached = projectSourceFiles.get(directory);\n\n if (cached && now - cached.cachedAt < SOURCE_FILES_CACHE_TTL_MS) {\n return cached.files;\n }\n const startTime = Date.now();\n const files = buildComponentFilesList(config as unknown as IntlayerConfig, [\n '**/.output/**',\n '**/.svelte-kit/**',\n '**/src-tauri/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/.expo/**',\n '**/.vercel/**',\n '**/.turbo/**',\n '**/.tanstack/**',\n '**/dist/**',\n '**/build/**',\n '**/node_modules/**',\n ]);\n projectSourceFiles.set(directory, { files, cachedAt: Date.now() });\n log(\n `source files scanned: ${files.length} file(s) in ${Date.now() - startTime}ms`\n );\n return files;\n};\n\n/**\n * Return every source-file location that calls useIntlayer / getIntlayer with\n * the given key.\n */\nconst getKeyUsageLocations = async (\n key: string,\n absolutePath: string\n): Promise<Location[]> => {\n const config = getProjectConfig(absolutePath);\n\n if (!config) return [];\n\n const usagePatterns = buildKeyUsagePatterns(key);\n\n const filePaths = await getSourceFiles(config.system.baseDir, config);\n const locations: Location[] = [];\n const startTime = Date.now();\n\n await runConcurrent(filePaths, async (filePath) => {\n const text = await tryReadFile(filePath);\n // Quick string check before running the regexes — skips the vast majority of files\n\n if (!text?.includes(key)) return;\n\n const seenStarts = new Set<number>();\n\n for (const usagePattern of usagePatterns) {\n for (const match of text.matchAll(usagePattern)) {\n const matchStart = match.index!;\n\n if (seenStarts.has(matchStart)) continue;\n\n seenStarts.add(matchStart);\n const matchEnd = matchStart + match[0].length;\n locations.push(\n Location.create(\n pathToFileURL(filePath).href,\n offsetToRange(text, matchStart, matchEnd)\n )\n );\n }\n }\n });\n\n log(\n `getKeyUsageLocations(\"${key}\") — ${filePaths.length} file(s) searched in ${Date.now() - startTime}ms → ${locations.length} hit(s)`\n );\n return locations;\n};\n\n/**\n * Return every source-file location that accesses the field at `fieldPath` on\n * the result of `useIntlayer(dictionaryKey)` / `getIntlayer(dictionaryKey)`.\n *\n * `fieldPath` is an array of property names from the content root to the\n * target field (e.g. `['searchInput', 'text']` for a nested field).\n * Single-element paths (e.g. `['greet']`) behave like the previous\n * single-`fieldName` API.\n */\nconst getFieldUsageLocations = async (\n dictionaryKey: string,\n fieldPath: string[],\n absolutePath: string\n): Promise<Location[]> => {\n const config = getProjectConfig(absolutePath);\n\n if (!config || fieldPath.length === 0) return [];\n\n const leafFieldName = fieldPath[fieldPath.length - 1]!;\n const escapedKey = escapeRegularExpression(dictionaryKey);\n const escapedLeaf = escapeRegularExpression(leafFieldName);\n const useCallRegularExpression = buildCallerWithKeyPattern(dictionaryKey);\n\n const filePaths = await getSourceFiles(config.system.baseDir, config);\n const locations: Location[] = [];\n const startTime = Date.now();\n\n await runConcurrent(filePaths, async (filePath) => {\n const text = await tryReadFile(filePath);\n\n if (!text) return;\n // Pre-filter: dictionaryKey and every segment of the path must appear in the file\n\n if (!text.includes(dictionaryKey)) return;\n\n if (fieldPath.some((segment) => !text.includes(segment))) return;\n\n if (!useCallRegularExpression.test(text)) return;\n\n for (const range of findFieldRangesInFile(\n text,\n escapedKey,\n leafFieldName,\n escapedLeaf,\n fieldPath\n )) {\n locations.push(Location.create(pathToFileURL(filePath).href, range));\n }\n });\n\n log(\n `getFieldUsageLocations(\"${dictionaryKey}.${fieldPath.join('.')}\") — ${filePaths.length} file(s) searched in ${Date.now() - startTime}ms → ${locations.length} hit(s)`\n );\n return locations;\n};\n\n/**\n * Find the line/column of the field's leaf name as a property key inside a\n * content file. Looks for `fieldName:` or `'field.name':` (flat keys with\n * dots, as used by lingui catalogs), not just any occurrence. Falls back to\n * the top of the file if the field cannot be located.\n */\nconst getFieldRangeInContentFile = async (\n absolutePath: string,\n fieldPath: string[]\n): Promise<Range> => {\n const content = await tryReadFile(absolutePath);\n const fieldName = fieldPath[fieldPath.length - 1];\n\n if (!content || !fieldName)\n return Range.create(Position.create(0, 0), Position.create(0, 0));\n\n // Match `fieldName:` at an object property key position (not a value),\n // allowing an optional quoted form for keys containing dots or dashes.\n const fieldRegularExpression = new RegExp(\n `(?<![.\\\\w])(['\"\\`]?)${escapeRegularExpression(fieldName)}\\\\1\\\\s*:`\n );\n const lines = content.split(/\\r?\\n/);\n\n for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {\n const line = lines[lineIndex]!;\n const matchPosition = line.search(fieldRegularExpression);\n\n if (matchPosition === -1) continue;\n const column = line.indexOf(fieldName, matchPosition);\n\n if (column === -1) continue;\n return Range.create(\n Position.create(lineIndex, column),\n Position.create(lineIndex, column + fieldName.length)\n );\n }\n\n return Range.create(Position.create(0, 0), Position.create(0, 0));\n};\n\n/**\n * Return every content-file location where the field at `fieldPath` is\n * defined as a property of the dictionary with the given `dictionaryKey`.\n */\nconst getContentFieldLocations = async (\n dictionaryKey: string,\n fieldPath: string[],\n absolutePath: string\n): Promise<Location[]> => {\n const config = getProjectConfig(absolutePath);\n\n if (!config) return [];\n\n const unmergedDictionaries = getUnmergedDictionariesCached(config);\n const dictionaries = Object.values(unmergedDictionaries)\n .flat()\n .filter(\n (dictionary) => dictionary?.key === dictionaryKey && dictionary.filePath\n );\n\n const locations: Location[] = [];\n\n await runConcurrent(dictionaries, async (dictionary) => {\n const filePath = dictionary.filePath!;\n const absolutePath = isAbsolute(filePath)\n ? filePath\n : join(config.system.baseDir, filePath);\n\n if (!existsSync(absolutePath)) return;\n\n locations.push(\n Location.create(\n pathToFileURL(absolutePath).href,\n await getFieldRangeInContentFile(absolutePath, fieldPath)\n )\n );\n });\n\n return locations;\n};\n\n// ---------------------------------------------------------------------------\n// Diagnostics — push-based (no capability needed)\n// ---------------------------------------------------------------------------\n\nconst DIAGNOSTIC_DEBOUNCE_MS = 300;\nconst diagnosticTimers = new Map<string, ReturnType<typeof setTimeout>>();\n\nconst computeDiagnostics = (\n text: string,\n config: WorkspaceConfig\n): Diagnostic[] => {\n const namespaceReferences = collectNamespaceReferences(text);\n\n if (namespaceReferences.length === 0) return [];\n\n const unmergedDictionaries = getUnmergedDictionariesCached(config);\n const knownKeys = new Set(\n Object.values(unmergedDictionaries)\n .flat()\n .map((dictionary) => dictionary?.key)\n .filter((key): key is string => typeof key === 'string')\n );\n\n const diagnostics: Diagnostic[] = [];\n\n for (const reference of namespaceReferences) {\n if (knownKeys.has(reference.dictionaryKey)) continue;\n\n diagnostics.push({\n range: offsetToRange(\n text,\n reference.namespaceStart,\n reference.namespaceEnd\n ),\n severity: DiagnosticSeverity.Warning,\n source: 'intlayer',\n message: `Dictionary key \"${reference.dictionaryKey}\" is not declared in any content file`,\n });\n }\n\n return diagnostics;\n};\n\nconst sendDiagnosticsForDocument = (\n uri: string,\n text: string,\n version: number | null\n): void => {\n const absolutePath = decodeURIComponent(new URL(uri).pathname);\n const config = getProjectConfig(absolutePath);\n\n const diagnostics =\n config && !isContentFile(uri, config)\n ? computeDiagnostics(text, config)\n : [];\n\n connection.sendDiagnostics({\n uri,\n version: version ?? undefined,\n diagnostics,\n });\n};\n\nconst scheduleDiagnostics = (\n uri: string,\n text: string,\n version: number | null\n): void => {\n const existing = diagnosticTimers.get(uri);\n\n if (existing !== undefined) clearTimeout(existing);\n\n diagnosticTimers.set(\n uri,\n setTimeout(() => {\n diagnosticTimers.delete(uri);\n sendDiagnosticsForDocument(uri, text, version);\n }, DIAGNOSTIC_DEBOUNCE_MS)\n );\n};\n\n// ---------------------------------------------------------------------------\n// Completion context detection\n// ---------------------------------------------------------------------------\n\ntype CompletionCtx =\n | { kind: 'key' }\n | { kind: 'field'; dictionaryKey: string; fieldPath: string[] }\n | null;\n\n/** Find the dictionary key for a simple variable assigned from any registered caller. */\nconst resolveVariableToDictionaryKey = (\n program: OxcNode,\n varName: string\n): string | null => {\n let result: string | null = null;\n\n walkAst(program, (node) => {\n if (result) return true;\n\n if (node['type'] !== 'VariableDeclarator') return;\n const id = node['id'] as OxcNode | undefined;\n\n if (id?.['type'] !== 'Identifier' || (id['name'] as string) !== varName)\n return;\n const init = node['init'] as OxcNode | undefined;\n\n if (!init) return;\n result = matchCallNamespace(init);\n return true;\n });\n return result;\n};\n\n/**\n * Detect what kind of completion is appropriate at the given offset.\n *\n * Handles:\n * - key completion: cursor inside first string arg of useIntlayer/getIntlayer\n * - field (member): cursor after `variable.` where variable came from useIntlayer\n * - field (destructure): cursor inside `const { | } = useIntlayer(\"key\")`\n */\nconst getCompletionContext = (\n textBefore: string,\n textAfter: string,\n program: OxcNode | null\n): CompletionCtx => {\n // Key completion\n\n if (\n new RegExp(\n `\\\\b(?:${getCallerNamesAlternation()})\\\\b(?:<[^<>]*>)?\\\\s*\\\\(\\\\s*['\"\\`][^'\"\\`\\\\n]*$`\n ).test(textBefore)\n ) {\n return { kind: 'key' };\n }\n\n // Field completion via member access: rootVar.path.to.\n const memberMatch = /\\b(\\w+)((?:\\.\\w+)*)\\.$/.exec(textBefore);\n\n if (memberMatch && program) {\n const rootVar = memberMatch[1]!;\n const chainStr = memberMatch[2]!;\n const dictKey = resolveVariableToDictionaryKey(program, rootVar);\n\n if (dictKey) {\n const fieldPath = chainStr ? chainStr.slice(1).split('.') : [];\n return { kind: 'field', dictionaryKey: dictKey, fieldPath };\n }\n }\n\n // Field completion inside destructuring: const { | } = useIntlayer(\"key\")\n\n if (/(?:const|let|var)\\s*\\{[^}]*$/.test(textBefore)) {\n const destructMatch = new RegExp(\n `^[^}]*\\\\}\\\\s*=\\\\s*(?:${getCallerNamesAlternation()})(?:<[^<>]*>)?\\\\s*\\\\(\\\\s*['\"\\`]([^'\"\\`\\\\n]+)['\"\\`]`\n ).exec(textAfter);\n\n if (destructMatch) {\n return { kind: 'field', dictionaryKey: destructMatch[1]!, fieldPath: [] };\n }\n }\n\n return null;\n};\n\nconnection.onInitialize((parameters: InitializeParams): InitializeResult => {\n workspaceRoot =\n parameters.rootPath ||\n (parameters.workspaceFolders?.[0]?.uri\n ? decodeURIComponent(new URL(parameters.workspaceFolders[0].uri).pathname)\n : undefined);\n invalidateConfigCaches();\n\n log(`initialized — workspaceRoot: ${workspaceRoot ?? '(none)'}`);\n\n if (parameters.workspaceFolders?.length) {\n log(\n `workspaceFolders: ${parameters.workspaceFolders.map((folder) => folder.name).join(', ')}`\n );\n }\n\n return {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n definitionProvider: true,\n referencesProvider: true,\n hoverProvider: true,\n completionProvider: {\n triggerCharacters: ['\"', \"'\", '`', '.'],\n resolveProvider: false,\n },\n },\n };\n});\n\nconnection.onDefinition(async (parameters) => {\n const uri = parameters.textDocument.uri;\n const absolutePath = decodeURIComponent(new URL(uri).pathname);\n const position = parameters.position;\n const document = documents.get(uri);\n\n if (!document) {\n log(`onDefinition — document not found in cache: ${uri}`);\n return null;\n }\n\n const text = document.getText();\n const offset = document.offsetAt(position);\n const shortenedUri = uri\n .replace(/^file:\\/\\//, '')\n .split('/')\n .slice(-2)\n .join('/');\n\n log(`onDefinition — ${shortenedUri} ${position.line}:${position.character}`);\n const config = getProjectConfig(absolutePath);\n\n if (config && isContentFile(uri, config)) {\n // Content-file → component navigation is handled exclusively by the VS Code\n // extension's intlayerContentDefinitionProvider (which returns DefinitionLink[]\n // with a proper originSelectionRange). Returning null here prevents the LSP\n // from emitting a duplicate set of Location[] results for the same request.\n log('onDefinition — content file: delegating to extension provider');\n return null;\n }\n\n // Cursor on the key string / function name → navigate to content declaration.\n const key = findKeyAtOffset(text, offset);\n\n if (key) {\n log(\n `onDefinition — useIntlayer key: \"${key}\" → searching content declarations`\n );\n const locations = await getContentDeclarationLocations(key, absolutePath);\n log(\n `onDefinition — found ${locations.length} content declaration(s) for key \"${key}\"`\n );\n return locations.length ? locations : null;\n }\n\n // Cursor on any message usage: destructured property, member access,\n // t('path.to.field') call, formatMessage({ id }), <Trans>, lingui t`…`, …\n const usage = findMessageUsageAtOffset(text, offset);\n\n if (usage && usage.fieldPath.length > 0) {\n log(\n `onDefinition — usage field: \"${usage.dictionaryKey}.${usage.fieldPath.join('.')}\" (${usage.callerName}) → searching content field`\n );\n const locations = await getContentFieldLocations(\n usage.dictionaryKey,\n usage.fieldPath,\n absolutePath\n );\n log(\n `onDefinition — found ${locations.length} content file(s) with field \"${usage.fieldPath.join('.')}\"`\n );\n return locations.length ? locations : null;\n }\n\n if (usage) {\n // Dictionary-level usage (e.g. bare content variable) → content files.\n const locations = await getContentDeclarationLocations(\n usage.dictionaryKey,\n absolutePath\n );\n return locations.length ? locations : null;\n }\n\n log('onDefinition — no Intlayer key at cursor, no result');\n return null;\n});\n\n/**\n * \"Find All References\" handler (Shift+F12).\n *\n * From a content file, returns every source-file location that uses the key or\n * field at the cursor — the reverse direction of Go-to-Definition.\n *\n * From a source file, returns all content-file declarations for the key or\n * field at the cursor — complementing what Go-to-Definition already handles.\n */\nconnection.onReferences(async (parameters: ReferenceParams) => {\n const uri = parameters.textDocument.uri;\n const absolutePath = decodeURIComponent(new URL(uri).pathname);\n const position = parameters.position;\n const document = documents.get(uri);\n\n if (!document) return null;\n\n const text = document.getText();\n const offset = document.offsetAt(position);\n const shortenedUri = uri\n .replace(/^file:\\/\\//, '')\n .split('/')\n .slice(-2)\n .join('/');\n\n log(`onReferences — ${shortenedUri} ${position.line}:${position.character}`);\n const config = getProjectConfig(absolutePath);\n\n if (config && isContentFile(uri, config)) {\n // Cursor on `key: \"…\"` → all useIntlayer(key) call sites\n const key = findKeyInContentFile(text, offset);\n\n if (key) {\n const locations = await getKeyUsageLocations(key, absolutePath);\n log(`onReferences — key \"${key}\" → ${locations.length} call site(s)`);\n return locations.length ? locations : null;\n }\n\n // Cursor on a content field → all field usage sites\n const extMatch = uri.match(/\\.[^.]+$/);\n const ext = extMatch ? extMatch[0] : '';\n const fieldInfo = findContentFieldAtOffset(text, offset, ext);\n\n if (fieldInfo) {\n const locations = await getFieldUsageLocations(\n fieldInfo.dictionaryKey,\n fieldInfo.fieldPath,\n absolutePath\n );\n log(\n `onReferences — field \"${fieldInfo.fieldPath.join('.')}\" → ${locations.length} usage(s)`\n );\n return locations.length ? locations : null;\n }\n\n return null;\n }\n\n // Source file: key string → content-file declarations\n const key = findKeyAtOffset(text, offset);\n\n if (key) {\n const locations = await getContentDeclarationLocations(key, absolutePath);\n log(`onReferences — key \"${key}\" → ${locations.length} declaration(s)`);\n return locations.length ? locations : null;\n }\n\n // Source file: field property, t('field') call, JSX message component, …\n // → content-file field definitions\n const usage = findMessageUsageAtOffset(text, offset);\n\n if (usage && usage.fieldPath.length > 0) {\n const locations = await getContentFieldLocations(\n usage.dictionaryKey,\n usage.fieldPath,\n absolutePath\n );\n log(\n `onReferences — field \"${usage.fieldPath.join('.')}\" → ${locations.length} content definition(s)`\n );\n return locations.length ? locations : null;\n }\n\n return null;\n});\n\n// ---------------------------------------------------------------------------\n// Hover\n// ---------------------------------------------------------------------------\n\nconnection.onHover(async (parameters: HoverParams): Promise<Hover | null> => {\n const uri = parameters.textDocument.uri;\n const absolutePath = decodeURIComponent(new URL(uri).pathname);\n const document = documents.get(uri);\n\n if (!document) return null;\n\n const text = document.getText();\n const offset = document.offsetAt(parameters.position);\n const config = getProjectConfig(absolutePath);\n\n if (!config) return null;\n\n const unmergedDictionaries = getUnmergedDictionariesCached(config);\n const getDicts = (key: string) =>\n Object.values(unmergedDictionaries)\n .flat()\n .filter((d) => d?.key === key);\n\n if (isContentFile(uri, config)) {\n // Cursor on `key: \"...\"` declaration\n const key = findKeyInContentFile(text, offset);\n\n if (key) {\n const dicts = getDicts(key);\n\n if (dicts.length > 0) {\n return {\n contents: {\n kind: MarkupKind.Markdown,\n value: formatDictionaryHover(dicts, key),\n },\n };\n }\n }\n\n // Cursor on a content field\n const ext = uri.match(/\\.[^.]+$/)?.[0] ?? '';\n const fieldInfo = findContentFieldAtOffset(text, offset, ext);\n\n if (fieldInfo) {\n const dicts = getDicts(fieldInfo.dictionaryKey);\n\n if (dicts.length > 0) {\n const hoverText = formatFieldHover(\n dicts,\n fieldInfo.dictionaryKey,\n fieldInfo.fieldPath\n );\n\n if (hoverText) {\n return {\n contents: { kind: MarkupKind.Markdown, value: hoverText },\n };\n }\n }\n }\n\n return null;\n }\n\n // Source file: cursor on key string inside useIntlayer(\"key\")\n const key = findKeyAtOffset(text, offset);\n\n if (key) {\n const dicts = getDicts(key);\n\n if (dicts.length > 0) {\n return {\n contents: {\n kind: MarkupKind.Markdown,\n value: formatDictionaryHover(dicts, key),\n },\n };\n }\n return null;\n }\n\n // Source file: cursor on any message usage (field property, t('field'),\n // formatMessage({ id }), <Trans>, lingui t`…`, …)\n const usage = findMessageUsageAtOffset(text, offset);\n\n if (usage) {\n const dicts = getDicts(usage.dictionaryKey);\n\n if (dicts.length > 0) {\n if (usage.fieldPath.length === 0) {\n return {\n contents: {\n kind: MarkupKind.Markdown,\n value: formatDictionaryHover(dicts, usage.dictionaryKey),\n },\n };\n }\n\n const hoverText = formatFieldHover(\n dicts,\n usage.dictionaryKey,\n usage.fieldPath\n );\n\n if (hoverText) {\n return {\n contents: { kind: MarkupKind.Markdown, value: hoverText },\n };\n }\n }\n }\n\n return null;\n});\n\n// ---------------------------------------------------------------------------\n// Completion\n// ---------------------------------------------------------------------------\n\nconnection.onCompletion(\n async (parameters: CompletionParams): Promise<CompletionItem[] | null> => {\n const uri = parameters.textDocument.uri;\n const absolutePath = decodeURIComponent(new URL(uri).pathname);\n const document = documents.get(uri);\n\n if (!document) return null;\n\n const text = document.getText();\n const offset = document.offsetAt(parameters.position);\n const config = getProjectConfig(absolutePath);\n\n if (!config) return null;\n\n const program = parseText(text);\n const context = getCompletionContext(\n text.slice(0, offset),\n text.slice(offset),\n program\n );\n\n if (!context) return null;\n\n const unmergedDictionaries = getUnmergedDictionariesCached(config);\n\n if (context.kind === 'key') {\n const seen = new Set<string>();\n const items: CompletionItem[] = [];\n for (const dictionary of Object.values(unmergedDictionaries).flat()) {\n if (!dictionary?.key || seen.has(dictionary.key)) continue;\n\n seen.add(dictionary.key);\n items.push({\n label: dictionary.key,\n kind: CompletionItemKind.Value,\n detail: dictionary.title ?? undefined,\n documentation: dictionary.description\n ? { kind: MarkupKind.Markdown, value: dictionary.description }\n : undefined,\n });\n }\n log(`onCompletion — key: ${items.length} dictionary keys`);\n return items.length > 0 ? items : null;\n }\n\n if (context.kind === 'field') {\n const dictionaries = Object.values(unmergedDictionaries)\n .flat()\n .filter((dictionary) => dictionary?.key === context.dictionaryKey);\n\n if (dictionaries.length === 0) return null;\n\n const primary = dictionaries[0]!;\n const fields = getFieldsAtPath(primary.content, context.fieldPath);\n const items: CompletionItem[] = fields.map((fieldName) => {\n const value = getFieldByPath(primary.content, [\n ...context.fieldPath,\n fieldName,\n ]);\n return {\n label: fieldName,\n kind: CompletionItemKind.Field,\n detail: formatFieldValue(value),\n };\n });\n log(\n `onCompletion — field \"${context.dictionaryKey}.${context.fieldPath.join('.')}\": ${items.length} field(s)`\n );\n return items.length > 0 ? items : null;\n }\n\n return null;\n }\n);\n\n// ---------------------------------------------------------------------------\n// Push diagnostics\n// ---------------------------------------------------------------------------\n\ndocuments.onDidOpen((event) => {\n sendDiagnosticsForDocument(\n event.document.uri,\n event.document.getText(),\n event.document.version\n );\n});\n\ndocuments.onDidChangeContent((event) => {\n scheduleDiagnostics(\n event.document.uri,\n event.document.getText(),\n event.document.version\n );\n});\n\ndocuments.onDidClose((event) => {\n const uri = event.document.uri;\n const timer = diagnosticTimers.get(uri);\n\n if (timer !== undefined) {\n clearTimeout(timer);\n diagnosticTimers.delete(uri);\n }\n connection.sendDiagnostics({ uri, diagnostics: [] });\n});\n\n// Invalidate the source-file list whenever the client reports a file change.\n// The client registers a watcher for *.content.* files; any creation or\n// deletion means the project layout may have changed.\nconnection.onDidChangeWatchedFiles(() => {\n invalidateConfigCaches();\n log(\n 'watched files changed — source file list and dictionary cache invalidated'\n );\n});\n\n// Make the text document manager listen on the connection\n// for open, change and close text document events\ndocuments.listen(connection);\n\n// Listen on the connection\nconnection.listen();\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6DA,MAAM,aAAa,iBAAiB,iBAAiB,IAAI;AAGzD,MAAM,YAAyC,IAAI,cAAc,aAAa;;;;;;AAO9E,MAAM,OAAO,YACX,WAAW,QAAQ,IAAI,kBAAkB,UAAU;AAErD,IAAI;;;;;;AAYJ,MAAM,iCAAiB,IAAI,KAA8B;AAMzD,MAAM,sCAAsB,IAAI,KAAgC;AAChE,MAAM,0BAA0B;AAMhC,MAAM,qCAAqB,IAAI,KAA+B;AAC9D,MAAM,4BAA4B;AAElC,MAAM,+BAA+B;AACnC,gBAAe,OAAO;AACtB,qBAAoB,OAAO;AAE3B,oBAAmB,OAAO;;AAG5B,MAAM,oBAAoB,iBAAiD;AACzE,KAAI;EAGF,MAAM,EAAE,QAAQ,OAAO,SAAS,aAAa,iBAAiB,EAAE,SAFhD,QAAQ,aAE+C,EAAE,CAAC;EAC1E,MAAM,WAAW,OAAO;AAExB,MAAI,CAAC,eAAe,IAAI,SAAS,EAAE;AACjC,kBAAe,IAAI,UAAU;IAAE;IAAQ;IAAO;IAAS;IAAU,CAAC;AAClE,OACE,iCAAiC,OAAO,QAAQ,2BAA2B,OAAO,0BACnF;;AAEH,SAAO,eAAe,IAAI,SAAS;UAC5B,OAAO;AACd,MAAI,8BAA8B,QAAQ;AAC1C,SAAO;;;AAIX,MAAM,iCACJ,WAC+C;CAC/C,MAAM,WAAW,OAAO,OAAO;CAC/B,MAAM,SAAS,oBAAoB,IAAI,SAAS;CAChD,MAAM,MAAM,KAAK,KAAK;AAEtB,KAAI,UAAU,MAAM,OAAO,WAAW,wBACpC,QAAO,OAAO;CAGhB,MA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AC7B,4BACE,MAAM,SAAS,KACf,MAAM,SAAS,SAAS,EACxB,MAAM,SAAS,QAChB;EACD;AAEF,UAAU,oBAAoB,UAAU;AACtC,qBACE,MAAM,SAAS,KACf,MAAM,SAAS,SAAS,EACxB,MAAM,SAAS,QAChB;EACD;AAEF,UAAU,YAAY,UAAU;CAC9B,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,QAAQ,iBAAiB,IAAI,IAAI;AAEvC,KAAI,UAAU,QAAW;AACvB,eAAa,MAAM;AACnB,mBAAiB,OAAO,IAAI;;AAE9B,YAAW,gBAAgB;EAAE;EAAK,aAAa,EAAE;EAAE,CAAC;EACpD;AAKF,WAAW,8BAA8B;AACvC,yBAAwB;AACxB,KACE,4EACD;EACD;AAIF,UAAU,OAAO,WAAW;AAG5B,WAAW,QAAQ"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
|
|
3
|
+
//#region src/oxcUtils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse `text` into an Oxc program AST.
|
|
6
|
+
* Returns null when the parse completely fails (e.g. unsupported syntax).
|
|
7
|
+
* Oxc is generally resilient to partial/in-progress edits and still returns a
|
|
8
|
+
* usable AST alongside error diagnostics, so this is rare.
|
|
9
|
+
*/
|
|
10
|
+
const parseText = (text) => {
|
|
11
|
+
try {
|
|
12
|
+
const { program } = parseSync("file.tsx", text);
|
|
13
|
+
return program;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Depth-first walk of an Oxc AST. Visitor is called for every node that has
|
|
20
|
+
* a `type` property; returning `true` prunes that subtree.
|
|
21
|
+
*/
|
|
22
|
+
const walkAst = (node, visitor) => {
|
|
23
|
+
if (!node || typeof node !== "object") return;
|
|
24
|
+
if (Array.isArray(node)) {
|
|
25
|
+
for (const child of node) walkAst(child, visitor);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const oxcNode = node;
|
|
29
|
+
if (typeof oxcNode["type"] !== "string") return;
|
|
30
|
+
if (visitor(oxcNode)) return;
|
|
31
|
+
for (const key of Object.keys(oxcNode)) {
|
|
32
|
+
if (key === "start" || key === "end" || key === "type") continue;
|
|
33
|
+
walkAst(oxcNode[key], visitor);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Build a child → parent reference map for upward traversal.
|
|
38
|
+
* Only AST-node-valued properties are followed; primitives are ignored.
|
|
39
|
+
*/
|
|
40
|
+
const buildParentMap = (root) => {
|
|
41
|
+
const parentMap = /* @__PURE__ */ new Map();
|
|
42
|
+
const walk = (node, parent) => {
|
|
43
|
+
if (!node || typeof node !== "object") return;
|
|
44
|
+
if (Array.isArray(node)) {
|
|
45
|
+
for (const child of node) walk(child, parent);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const oxcNode = node;
|
|
49
|
+
if (typeof oxcNode["type"] !== "string") return;
|
|
50
|
+
if (parent) parentMap.set(oxcNode, parent);
|
|
51
|
+
for (const key of Object.keys(oxcNode)) {
|
|
52
|
+
if (key === "start" || key === "end" || key === "type") continue;
|
|
53
|
+
walk(oxcNode[key], oxcNode);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
walk(root, null);
|
|
57
|
+
return parentMap;
|
|
58
|
+
};
|
|
59
|
+
/** Byte offset of the node's start. */
|
|
60
|
+
const nodeStart = (node) => node["start"] ?? node["range"]?.[0] ?? 0;
|
|
61
|
+
/** Byte offset of the node's end. */
|
|
62
|
+
const nodeEnd = (node) => node["end"] ?? node["range"]?.[1] ?? 0;
|
|
63
|
+
/** Returns `true` when `offset` falls inside the node's span (inclusive). */
|
|
64
|
+
const nodeContainsOffset = (node, offset) => offset >= nodeStart(node) && offset <= nodeEnd(node);
|
|
65
|
+
/**
|
|
66
|
+
* Returns `true` for nodes that carry a static string value:
|
|
67
|
+
* Literal / StringLiteral, and no-substitution TemplateLiteral.
|
|
68
|
+
*/
|
|
69
|
+
const isStringLiteralNode = (node) => {
|
|
70
|
+
const nodeType = node["type"];
|
|
71
|
+
if (nodeType === "Literal" || nodeType === "StringLiteral") return typeof node["value"] === "string";
|
|
72
|
+
if (nodeType === "TemplateLiteral") return (node["expressions"]?.length ?? 0) === 0;
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Extract the static string value from a literal node, or null when the node
|
|
77
|
+
* is not a static string.
|
|
78
|
+
*/
|
|
79
|
+
const getStaticStringValue = (node) => {
|
|
80
|
+
if (!node) return null;
|
|
81
|
+
const nodeType = node["type"];
|
|
82
|
+
if ((nodeType === "Literal" || nodeType === "StringLiteral") && typeof node["value"] === "string") return node["value"];
|
|
83
|
+
if (nodeType === "TemplateLiteral" && (node["expressions"]?.length ?? 0) === 0) {
|
|
84
|
+
const valueNode = node["quasis"]?.[0]?.["value"];
|
|
85
|
+
return valueNode?.["cooked"] ?? valueNode?.["raw"] ?? null;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
};
|
|
89
|
+
/** Extract the string value from the Nth argument of a call expression. */
|
|
90
|
+
const getStringArgAt = (callNode, index) => {
|
|
91
|
+
const argumentsList = callNode["arguments"];
|
|
92
|
+
if (!argumentsList || argumentsList.length <= index) return null;
|
|
93
|
+
return getStaticStringValue(argumentsList[index]);
|
|
94
|
+
};
|
|
95
|
+
/** Extract the string value from the first argument of a call expression. */
|
|
96
|
+
const getFirstStringArg = (callExpressionNode) => getStringArgAt(callExpressionNode, 0);
|
|
97
|
+
/**
|
|
98
|
+
* Find the property node named `propertyName` inside an ObjectExpression.
|
|
99
|
+
*/
|
|
100
|
+
const getObjectPropertyNode = (objectExpression, propertyName) => {
|
|
101
|
+
if (objectExpression?.["type"] !== "ObjectExpression") return null;
|
|
102
|
+
for (const property of objectExpression["properties"] ?? []) {
|
|
103
|
+
const propertyType = property["type"];
|
|
104
|
+
if (propertyType !== "Property" && propertyType !== "ObjectProperty") continue;
|
|
105
|
+
const keyNode = property["key"];
|
|
106
|
+
if ((keyNode?.["type"] === "Identifier" ? keyNode["name"] : typeof keyNode?.["value"] === "string" ? keyNode["value"] : null) === propertyName) return property;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Read a static string property from an ObjectExpression argument,
|
|
112
|
+
* e.g. the `namespace` of `useI18n({ namespace: 'about' })`.
|
|
113
|
+
*/
|
|
114
|
+
const getObjectPropertyString = (objectExpression, propertyName) => {
|
|
115
|
+
const property = getObjectPropertyNode(objectExpression, propertyName);
|
|
116
|
+
if (!property) return null;
|
|
117
|
+
return getStaticStringValue(property["value"]);
|
|
118
|
+
};
|
|
119
|
+
/** Get the identifier or string name of an object-property key node. */
|
|
120
|
+
const getPropertyKeyName = (keyNode) => {
|
|
121
|
+
if (!keyNode) return null;
|
|
122
|
+
const nodeType = keyNode["type"];
|
|
123
|
+
if (nodeType === "Identifier") return keyNode["name"];
|
|
124
|
+
if ((nodeType === "Literal" || nodeType === "StringLiteral") && typeof keyNode["value"] === "string") return keyNode["value"];
|
|
125
|
+
return null;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
export { buildParentMap, getFirstStringArg, getObjectPropertyNode, getObjectPropertyString, getPropertyKeyName, getStaticStringValue, getStringArgAt, isStringLiteralNode, nodeContainsOffset, nodeEnd, nodeStart, parseText, walkAst };
|
|
130
|
+
//# sourceMappingURL=oxcUtils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oxcUtils.mjs","names":[],"sources":["../../src/oxcUtils.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\n\nexport type OxcNode = Record<string, unknown>;\n\n/**\n * Parse `text` into an Oxc program AST.\n * Returns null when the parse completely fails (e.g. unsupported syntax).\n * Oxc is generally resilient to partial/in-progress edits and still returns a\n * usable AST alongside error diagnostics, so this is rare.\n */\nexport const parseText = (text: string): OxcNode | null => {\n try {\n const { program } = parseSync('file.tsx', text);\n\n return program as unknown as OxcNode;\n } catch {\n return null;\n }\n};\n\n/**\n * Depth-first walk of an Oxc AST. Visitor is called for every node that has\n * a `type` property; returning `true` prunes that subtree.\n */\nexport const walkAst = (\n node: unknown,\n // biome-ignore lint/suspicious/noConfusingVoidType: visitors without a return value must stay assignable\n visitor: (node: OxcNode) => boolean | void\n): void => {\n if (!node || typeof node !== 'object') return;\n\n if (Array.isArray(node)) {\n for (const child of node) walkAst(child, visitor);\n\n return;\n }\n const oxcNode = node as OxcNode;\n\n if (typeof oxcNode['type'] !== 'string') return;\n\n if (visitor(oxcNode)) return; // pruned\n\n for (const key of Object.keys(oxcNode)) {\n if (key === 'start' || key === 'end' || key === 'type') continue;\n walkAst(oxcNode[key], visitor);\n }\n};\n\n/**\n * Build a child → parent reference map for upward traversal.\n * Only AST-node-valued properties are followed; primitives are ignored.\n */\nexport const buildParentMap = (root: OxcNode): Map<OxcNode, OxcNode> => {\n const parentMap = new Map<OxcNode, OxcNode>();\n\n const walk = (node: unknown, parent: OxcNode | null): void => {\n if (!node || typeof node !== 'object') return;\n\n if (Array.isArray(node)) {\n for (const child of node) walk(child, parent);\n\n return;\n }\n const oxcNode = node as OxcNode;\n\n if (typeof oxcNode['type'] !== 'string') return;\n\n if (parent) parentMap.set(oxcNode, parent);\n\n for (const key of Object.keys(oxcNode)) {\n if (key === 'start' || key === 'end' || key === 'type') continue;\n walk(oxcNode[key], oxcNode);\n }\n };\n\n walk(root, null);\n return parentMap;\n};\n\n/** Byte offset of the node's start. */\nexport const nodeStart = (node: OxcNode): number =>\n (node['start'] as number | undefined) ??\n (node['range'] as number[] | undefined)?.[0] ??\n 0;\n\n/** Byte offset of the node's end. */\nexport const nodeEnd = (node: OxcNode): number =>\n (node['end'] as number | undefined) ??\n (node['range'] as number[] | undefined)?.[1] ??\n 0;\n\n/** Returns `true` when `offset` falls inside the node's span (inclusive). */\nexport const nodeContainsOffset = (node: OxcNode, offset: number): boolean =>\n offset >= nodeStart(node) && offset <= nodeEnd(node);\n\n/**\n * Returns `true` for nodes that carry a static string value:\n * Literal / StringLiteral, and no-substitution TemplateLiteral.\n */\nexport const isStringLiteralNode = (node: OxcNode): boolean => {\n const nodeType = node['type'] as string;\n\n if (nodeType === 'Literal' || nodeType === 'StringLiteral') {\n return typeof node['value'] === 'string';\n }\n\n if (nodeType === 'TemplateLiteral') {\n return ((node['expressions'] as unknown[])?.length ?? 0) === 0;\n }\n\n return false;\n};\n\n/**\n * Extract the static string value from a literal node, or null when the node\n * is not a static string.\n */\nexport const getStaticStringValue = (\n node: OxcNode | undefined\n): string | null => {\n if (!node) return null;\n const nodeType = node['type'] as string;\n\n if (\n (nodeType === 'Literal' || nodeType === 'StringLiteral') &&\n typeof node['value'] === 'string'\n ) {\n return node['value'];\n }\n\n if (\n nodeType === 'TemplateLiteral' &&\n ((node['expressions'] as unknown[])?.length ?? 0) === 0\n ) {\n const templateElements = node['quasis'] as OxcNode[] | undefined;\n const valueNode = templateElements?.[0]?.['value'] as OxcNode | undefined;\n\n return (\n (valueNode?.['cooked'] as string) ??\n (valueNode?.['raw'] as string) ??\n null\n );\n }\n\n return null;\n};\n\n/** Extract the string value from the Nth argument of a call expression. */\nexport const getStringArgAt = (\n callNode: OxcNode,\n index: number\n): string | null => {\n const argumentsList = callNode['arguments'] as OxcNode[] | undefined;\n\n if (!argumentsList || argumentsList.length <= index) return null;\n\n return getStaticStringValue(argumentsList[index]);\n};\n\n/** Extract the string value from the first argument of a call expression. */\nexport const getFirstStringArg = (callExpressionNode: OxcNode): string | null =>\n getStringArgAt(callExpressionNode, 0);\n\n/**\n * Find the property node named `propertyName` inside an ObjectExpression.\n */\nexport const getObjectPropertyNode = (\n objectExpression: OxcNode | undefined,\n propertyName: string\n): OxcNode | null => {\n if (objectExpression?.['type'] !== 'ObjectExpression') return null;\n\n for (const property of (objectExpression['properties'] as OxcNode[]) ?? []) {\n const propertyType = property['type'] as string;\n\n if (propertyType !== 'Property' && propertyType !== 'ObjectProperty') {\n continue;\n }\n\n const keyNode = property['key'] as OxcNode | undefined;\n const keyName =\n keyNode?.['type'] === 'Identifier'\n ? (keyNode['name'] as string)\n : typeof keyNode?.['value'] === 'string'\n ? (keyNode['value'] as string)\n : null;\n\n if (keyName === propertyName) return property;\n }\n\n return null;\n};\n\n/**\n * Read a static string property from an ObjectExpression argument,\n * e.g. the `namespace` of `useI18n({ namespace: 'about' })`.\n */\nexport const getObjectPropertyString = (\n objectExpression: OxcNode | undefined,\n propertyName: string\n): string | null => {\n const property = getObjectPropertyNode(objectExpression, propertyName);\n\n if (!property) return null;\n\n return getStaticStringValue(property['value'] as OxcNode | undefined);\n};\n\n/** Get the identifier or string name of an object-property key node. */\nexport const getPropertyKeyName = (\n keyNode: OxcNode | undefined\n): string | null => {\n if (!keyNode) return null;\n const nodeType = keyNode['type'] as string;\n\n if (nodeType === 'Identifier') return keyNode['name'] as string;\n\n if (\n (nodeType === 'Literal' || nodeType === 'StringLiteral') &&\n typeof keyNode['value'] === 'string'\n ) {\n return keyNode['value'];\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,aAAa,SAAiC;AACzD,KAAI;EACF,MAAM,EAAE,YAAY,UAAU,YAAY,KAAK;AAE/C,SAAO;SACD;AACN,SAAO;;;;;;;AAQX,MAAa,WACX,MAEA,YACS;AACT,KAAI,CAAC,QAAQ,OAAO,SAAS,SAAU;AAEvC,KAAI,MAAM,QAAQ,KAAK,EAAE;AACvB,OAAK,MAAM,SAAS,KAAM,SAAQ,OAAO,QAAQ;AAEjD;;CAEF,MAAM,UAAU;AAEhB,KAAI,OAAO,QAAQ,YAAY,SAAU;AAEzC,KAAI,QAAQ,QAAQ,CAAE;AAEtB,MAAK,MAAM,OAAO,OAAO,KAAK,QAAQ,EAAE;AACtC,MAAI,QAAQ,WAAW,QAAQ,SAAS,QAAQ,OAAQ;AACxD,UAAQ,QAAQ,MAAM,QAAQ;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