From e65741d47122ca44df514cb2cf25e07c6b3d9ff1 Mon Sep 17 00:00:00 2001 From: David Clausen Date: Fri, 15 May 2026 09:29:10 -0400 Subject: [PATCH 01/17] feat(elixir): add tree-sitter language support --- gitnexus-shared/src/language-detection.ts | 2 + gitnexus-shared/src/languages.ts | 1 + .../language-classification.ts | 1 + gitnexus/package-lock.json | 30 ++ gitnexus/package.json | 1 + .../class-extractors/configs/elixir.ts | 47 +++ .../src/core/ingestion/export-detection.ts | 22 +- .../import-resolvers/configs/elixir.ts | 73 +++++ .../src/core/ingestion/languages/elixir.ts | 272 ++++++++++++++++++ .../src/core/ingestion/languages/index.ts | 2 + .../method-extractors/configs/elixir.ts | 152 ++++++++++ .../src/core/ingestion/tree-sitter-queries.ts | 91 ++++++ .../core/ingestion/type-extractors/elixir.ts | 19 ++ .../src/core/tree-sitter/parser-loader.ts | 8 + gitnexus/test/fixtures/sample-code/simple.ex | 35 +++ .../integration/tree-sitter-languages.test.ts | 85 ++++++ 16 files changed, 840 insertions(+), 1 deletion(-) create mode 100644 gitnexus/src/core/ingestion/class-extractors/configs/elixir.ts create mode 100644 gitnexus/src/core/ingestion/import-resolvers/configs/elixir.ts create mode 100644 gitnexus/src/core/ingestion/languages/elixir.ts create mode 100644 gitnexus/src/core/ingestion/method-extractors/configs/elixir.ts create mode 100644 gitnexus/src/core/ingestion/type-extractors/elixir.ts create mode 100644 gitnexus/test/fixtures/sample-code/simple.ex diff --git a/gitnexus-shared/src/language-detection.ts b/gitnexus-shared/src/language-detection.ts index 3fe27f7b7..cede46956 100644 --- a/gitnexus-shared/src/language-detection.ts +++ b/gitnexus-shared/src/language-detection.ts @@ -55,6 +55,7 @@ const EXTENSION_MAP: Record = { [SupportedLanguages.Vue]: ['.vue'], [SupportedLanguages.Cobol]: ['.cbl', '.cob', '.cpy', '.cobol'], [SupportedLanguages.Zig]: ['.zig'], + [SupportedLanguages.Elixir]: ['.ex', '.exs'], } satisfies Record; // Ensure exhaustiveness /** Pre-built reverse lookup: extension → language (built once at module load). */ @@ -125,6 +126,7 @@ const SYNTAX_MAP: Record = { [SupportedLanguages.Vue]: 'typescript', [SupportedLanguages.Cobol]: 'cobol', [SupportedLanguages.Zig]: 'zig', + [SupportedLanguages.Elixir]: 'elixir', } satisfies Record; // Ensure exhaustiveness /** Non-code file extensions → Prism-compatible syntax identifiers */ diff --git a/gitnexus-shared/src/languages.ts b/gitnexus-shared/src/languages.ts index eec45e612..376478bb5 100644 --- a/gitnexus-shared/src/languages.ts +++ b/gitnexus-shared/src/languages.ts @@ -24,4 +24,5 @@ export enum SupportedLanguages { /** Standalone regex processor — no tree-sitter, no LanguageProvider. */ Cobol = 'cobol', Zig = 'zig', + Elixir = 'elixir', } diff --git a/gitnexus-shared/src/scope-resolution/language-classification.ts b/gitnexus-shared/src/scope-resolution/language-classification.ts index 2e635c8e2..262ec768d 100644 --- a/gitnexus-shared/src/scope-resolution/language-classification.ts +++ b/gitnexus-shared/src/scope-resolution/language-classification.ts @@ -47,6 +47,7 @@ export const LanguageClassifications: Readonly true; /** Dart: public if no leading underscore (convention, same as Python). */ export const dartExportChecker: ExportChecker = (_node, name) => !name.startsWith('_'); - /** Zig declaration node types whose `pub` / `export` keyword child marks the symbol public. */ const ZIG_DECL_TYPES = new Set(['function_declaration', 'variable_declaration']); @@ -303,3 +302,24 @@ export function hasZigPubKeyword(declNode: SyntaxNode): boolean { } return false; } +const ELIXIR_PRIVATE_KEYWORDS = new Set(['defp', 'defmacrop', 'defguardp']); +const ELIXIR_PUBLIC_KEYWORDS = new Set(['def', 'defmacro', 'defguard', 'defdelegate']); + +/** + * Elixir: def = public, defp = private. Walk up to the enclosing def/defp call + * to determine visibility. defmodule/defprotocol/defimpl are always public. + */ +export const elixirExportChecker: ExportChecker = (node, _name) => { + let current: SyntaxNode | null = node; + while (current) { + if (current.type === 'call') { + const target = current.childForFieldName?.('target'); + if (target?.type === 'identifier') { + if (ELIXIR_PRIVATE_KEYWORDS.has(target.text)) return false; + if (ELIXIR_PUBLIC_KEYWORDS.has(target.text)) return true; + } + } + current = current.parent; + } + return true; +}; diff --git a/gitnexus/src/core/ingestion/import-resolvers/configs/elixir.ts b/gitnexus/src/core/ingestion/import-resolvers/configs/elixir.ts new file mode 100644 index 000000000..27ba1d451 --- /dev/null +++ b/gitnexus/src/core/ingestion/import-resolvers/configs/elixir.ts @@ -0,0 +1,73 @@ +/** + * Elixir import resolution config. + * + * Elixir modules are identified by atoms (capitalized names, e.g. MyApp.User). + * By convention, `MyApp.User` maps to `lib/my_app/user.ex` (or `.exs`). + * Each dotted segment is snake_cased independently. + * + * Handles: import, alias, use, require directives. + * External/hex dependencies (no slash in module path context) return empty. + */ + +import { SupportedLanguages } from 'gitnexus-shared'; +import type { ImportResolutionConfig, ImportResolverStrategy } from '../types.js'; + +/** + * Convert a PascalCase module name segment to snake_case. + * HTTPClient → http_client, MyApp → my_app, XmlParser → xml_parser + */ +function toSnakeCase(segment: string): string { + return segment + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') + .replace(/([a-z\d])([A-Z])/g, '$1_$2') + .toLowerCase(); +} + +/** + * Convert a dotted Elixir module alias to a relative file path. + * MyApp.User → my_app/user + * Elixir.MyApp.User → elixir/my_app/user (Erlang-namespaced modules) + */ +function moduleToRelPath(moduleName: string): string { + return moduleName + .split('.') + .map(toSnakeCase) + .join('/'); +} + +const ELIXIR_EXTS = ['.ex', '.exs']; + +/** Elixir module alias → file path strategy. */ +const elixirModuleStrategy: ImportResolverStrategy = (rawImportPath, _filePath, ctx) => { + const moduleName = rawImportPath.trim(); + + // Must start with a capital letter (Elixir module alias convention) + if (!moduleName || !/^[A-Z]/.test(moduleName)) return null; + + const relPath = moduleToRelPath(moduleName); + + // Try common Elixir project roots: lib/, test/, apps/*/lib/, apps/*/test/ + const prefixes = ['lib/', 'test/', '']; + const files: string[] = []; + + for (const prefix of prefixes) { + for (const ext of ELIXIR_EXTS) { + const candidate = `${prefix}${relPath}${ext}`; + for (const fp of ctx.allFileList) { + if (fp === candidate || fp.endsWith(`/${candidate}`)) { + files.push(fp); + break; + } + } + if (files.length > 0) return { kind: 'files', files }; + } + } + + // No local file found — likely an external hex dependency + return { kind: 'files', files: [] }; +}; + +export const elixirImportConfig: ImportResolutionConfig = { + language: SupportedLanguages.Elixir, + strategies: [elixirModuleStrategy], +}; diff --git a/gitnexus/src/core/ingestion/languages/elixir.ts b/gitnexus/src/core/ingestion/languages/elixir.ts new file mode 100644 index 000000000..ea92ad30e --- /dev/null +++ b/gitnexus/src/core/ingestion/languages/elixir.ts @@ -0,0 +1,272 @@ +/** + * Elixir Language Provider + * + * Key Elixir traits: + * - importSemantics: 'wildcard-leaf' (import/use bring all public functions into scope) + * - mroStrategy: 'none' (functional language — no class inheritance) + * - heritageDefaultEdge: 'IMPLEMENTS' (protocol/behaviour relationships) + * - Modules defined with defmodule, functions with def/defp + * - Module names are atoms: MyApp.User → lib/my_app/user.ex by convention + */ + +import { SupportedLanguages, type NodeLabel } from 'gitnexus-shared'; +import type { AstFrameworkPatternConfig } from '../language-provider.js'; +import { defineLanguage } from '../language-provider.js'; +import { typeConfig as elixirTypeConfig } from '../type-extractors/elixir.js'; +import { elixirExportChecker } from '../export-detection.js'; +import { createImportResolver } from '../import-resolvers/resolver-factory.js'; +import { elixirImportConfig } from '../import-resolvers/configs/elixir.js'; +import { ELIXIR_QUERIES } from '../tree-sitter-queries.js'; +import { createMethodExtractor } from '../method-extractors/generic.js'; +import { elixirMethodConfig } from '../method-extractors/configs/elixir.js'; +import { createClassExtractor } from '../class-extractors/generic.js'; +import { elixirClassConfig } from '../class-extractors/configs/elixir.js'; +import { createHeritageExtractor } from '../heritage-extractors/generic.js'; +import type { CallExtractor, ExtractedCallSite } from '../call-types.js'; +import type { SyntaxNode } from '../utils/ast-helpers.js'; +import { countCallArguments } from '../utils/call-analysis.js'; +import { generateId } from '../../../lib/utils.js'; + +const ELIXIR_DEF_KEYWORDS = new Set([ + 'def', + 'defp', + 'defmacro', + 'defmacrop', + 'defguard', + 'defguardp', + 'defdelegate', +]); + +const ELIXIR_MODULE_KEYWORDS = new Set(['defmodule', 'defprotocol']); + +const ELIXIR_NON_CALL_KEYWORDS = new Set([ + ...ELIXIR_DEF_KEYWORDS, + ...ELIXIR_MODULE_KEYWORDS, + 'defimpl', + 'defstruct', + 'defoverridable', + 'defexception', + 'import', + 'alias', + 'use', + 'require', + 'case', + 'cond', + 'if', + 'unless', + 'for', + 'with', + 'receive', + 'try', + 'quote', + 'fn', +]); + +function callKeyword(node: SyntaxNode): string | undefined { + const target = node.childForFieldName?.('target'); + return target?.type === 'identifier' ? target.text : undefined; +} + +function findArguments(node: SyntaxNode): SyntaxNode | null { + for (let i = 0; i < node.namedChildCount; i++) { + const child = node.namedChild(i); + if (child?.type === 'arguments') return child; + } + return null; +} + +function firstAliasArgument(node: SyntaxNode): string | undefined { + const args = findArguments(node); + if (!args) return undefined; + for (let i = 0; i < args.namedChildCount; i++) { + const child = args.namedChild(i); + if (child?.type === 'alias') return child.text; + } + return undefined; +} + +function extractFunctionNameFromDef(node: SyntaxNode): string | undefined { + if (!ELIXIR_DEF_KEYWORDS.has(callKeyword(node) ?? '')) return undefined; + const args = findArguments(node); + if (!args) return undefined; + for (let i = 0; i < args.namedChildCount; i++) { + const arg = args.namedChild(i); + if (!arg) continue; + if (arg.type === 'identifier') return arg.text; + if (arg.type === 'call') { + const target = arg.childForFieldName?.('target'); + if (target?.type === 'identifier') return target.text; + } + if (arg.type === 'binary_operator') { + const left = arg.childForFieldName?.('left'); + if (left?.type === 'call') { + const target = left.childForFieldName?.('target'); + if (target?.type === 'identifier') return target.text; + } + } + } + return undefined; +} + +function isInsideDefinitionHead(node: SyntaxNode): boolean { + let current = node.parent; + while (current) { + if (current.type === 'do_block') return false; + if (current.type === 'call' && ELIXIR_DEF_KEYWORDS.has(callKeyword(current) ?? '')) { + return true; + } + current = current.parent; + } + return false; +} + +function isModuleAttributeCall(node: SyntaxNode): boolean { + return node.parent?.type === 'unary_operator' && node.parent.text.startsWith('@'); +} + +function remoteReceiver(callNode: SyntaxNode): string | undefined { + const target = callNode.childForFieldName?.('target'); + if (target?.type !== 'dot') return undefined; + const left = target.childForFieldName?.('left'); + return left?.type === 'alias' ? left.text : undefined; +} + +const elixirCallExtractor: CallExtractor = { + language: SupportedLanguages.Elixir, + + extract(callNode, callNameNode): ExtractedCallSite | null { + if (!callNameNode) return null; + if (isModuleAttributeCall(callNode) || isInsideDefinitionHead(callNode)) return null; + + const calledName = callNameNode.text; + if (ELIXIR_NON_CALL_KEYWORDS.has(calledName)) return null; + + const receiverName = remoteReceiver(callNode); + return { + calledName, + callForm: receiverName ? 'member' : 'free', + ...(receiverName ? { receiverName } : {}), + argCount: countCallArguments(callNode), + }; + }, +}; + +const elixirIsClassContainerNode = (node: SyntaxNode): boolean => + node.type === 'call' && ELIXIR_MODULE_KEYWORDS.has(callKeyword(node) ?? ''); + +const elixirExtractEnclosingClassInfo = (node: SyntaxNode, filePath: string) => { + if (!elixirIsClassContainerNode(node)) return null; + const className = firstAliasArgument(node); + if (!className) return null; + const label = callKeyword(node) === 'defprotocol' ? 'Interface' : 'Class'; + return { classId: generateId(label, `${filePath}:${className}`), className }; +}; + +const elixirEnclosingFunctionFinder = ( + node: SyntaxNode, +): { funcName: string; label: NodeLabel; definitionNode: SyntaxNode } | null => { + if (node.type !== 'call') return null; + const funcName = extractFunctionNameFromDef(node); + return funcName ? { funcName, label: 'Function', definitionNode: node } : null; +}; + +const elixirImportPathPreprocessor = (cleaned: string, importNode: SyntaxNode): string | null => { + const keyword = callKeyword(importNode); + return keyword === 'import' || keyword === 'use' || keyword === 'require' || keyword === 'alias' + ? cleaned + : null; +}; + +const BUILT_INS: ReadonlySet = new Set([ + // Kernel built-ins + 'send', 'spawn', 'spawn_link', 'spawn_monitor', 'exit', 'throw', 'raise', + 'reraise', 'apply', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean', + 'is_float', 'is_function', 'is_integer', 'is_list', 'is_map', 'is_nil', + 'is_number', 'is_pid', 'is_port', 'is_reference', 'is_struct', 'is_tuple', + 'length', 'hd', 'tl', 'abs', 'ceil', 'floor', 'round', 'trunc', 'rem', + 'div', 'max', 'min', 'elem', 'put_elem', 'tuple_size', 'map_size', + 'byte_size', 'bit_size', 'binary_part', 'get_in', 'put_in', 'update_in', + 'pop_in', 'get_and_update_in', 'struct', 'struct!', + // IO + 'IO.puts', 'IO.inspect', 'IO.gets', 'IO.write', 'IO.read', + // Common pipeline functions + 'then', 'tap', 'dbg', +]); + +export const elixirProvider = defineLanguage({ + id: SupportedLanguages.Elixir, + extensions: ['.ex', '.exs'], + + entryPointPatterns: [ + /^mount$/, + /^handle_event$/, + /^handle_info$/, + /^handle_call$/, + /^handle_cast$/, + /^handle_continue$/, + /^perform$/, + /^process$/, + /^call$/, + /^init$/, + /^start_link$/, + /^action$/, + ], + + astFrameworkPatterns: [ + { + framework: 'phoenix-liveview', + entryPointMultiplier: 3.0, + reason: 'liveview-handler', + patterns: ['Phoenix.LiveView', 'use Phoenix.LiveView', 'mount', 'handle_event'], + }, + { + framework: 'phoenix-controller', + entryPointMultiplier: 2.5, + reason: 'phoenix-action', + patterns: ['use Phoenix.Controller', 'conn', 'params', 'Phoenix.Controller'], + }, + { + framework: 'phoenix-channel', + entryPointMultiplier: 2.5, + reason: 'phoenix-channel', + patterns: ['use Phoenix.Channel', 'Phoenix.Channel', 'socket', 'join'], + }, + { + framework: 'oban-worker', + entryPointMultiplier: 2.8, + reason: 'oban-job', + patterns: ['use Oban.Worker', 'Oban.Worker', 'perform'], + }, + { + framework: 'genserver', + entryPointMultiplier: 2.0, + reason: 'genserver', + patterns: ['use GenServer', 'GenServer', 'handle_call', 'handle_cast', 'handle_info'], + }, + { + framework: 'plug', + entryPointMultiplier: 2.0, + reason: 'plug-middleware', + patterns: ['use Plug.Router', 'Plug.Conn', 'plug'], + }, + ] satisfies AstFrameworkPatternConfig[], + + treeSitterQueries: ELIXIR_QUERIES, + typeConfig: elixirTypeConfig, + exportChecker: elixirExportChecker, + importResolver: createImportResolver(elixirImportConfig), + importPathPreprocessor: elixirImportPathPreprocessor, + importSemantics: 'wildcard-leaf', + + callExtractor: elixirCallExtractor, + isClassContainerNode: elixirIsClassContainerNode, + extractEnclosingClassInfo: elixirExtractEnclosingClassInfo, + enclosingFunctionFinder: elixirEnclosingFunctionFinder, + methodExtractor: createMethodExtractor(elixirMethodConfig), + classExtractor: createClassExtractor(elixirClassConfig), + heritageExtractor: createHeritageExtractor(SupportedLanguages.Elixir), + + heritageDefaultEdge: 'IMPLEMENTS', + + builtInNames: BUILT_INS, +}); diff --git a/gitnexus/src/core/ingestion/languages/index.ts b/gitnexus/src/core/ingestion/languages/index.ts index b10822a6f..c92f7994a 100644 --- a/gitnexus/src/core/ingestion/languages/index.ts +++ b/gitnexus/src/core/ingestion/languages/index.ts @@ -31,6 +31,7 @@ import { dartProvider } from './dart.js'; import { vueProvider } from './vue.js'; import { cobolProvider } from './cobol.js'; import { zigProvider } from './zig.js'; +import { elixirProvider } from './elixir.js'; export const providers = { [SupportedLanguages.JavaScript]: javascriptProvider, @@ -51,6 +52,7 @@ export const providers = { [SupportedLanguages.Vue]: vueProvider, [SupportedLanguages.Cobol]: cobolProvider, [SupportedLanguages.Zig]: zigProvider, + [SupportedLanguages.Elixir]: elixirProvider, } satisfies Record; /** Get provider by language enum (always succeeds for SupportedLanguages). */ diff --git a/gitnexus/src/core/ingestion/method-extractors/configs/elixir.ts b/gitnexus/src/core/ingestion/method-extractors/configs/elixir.ts new file mode 100644 index 000000000..814914fb1 --- /dev/null +++ b/gitnexus/src/core/ingestion/method-extractors/configs/elixir.ts @@ -0,0 +1,152 @@ +// gitnexus/src/core/ingestion/method-extractors/configs/elixir.ts + +import { SupportedLanguages } from 'gitnexus-shared'; +import type { MethodExtractionConfig, ParameterInfo, MethodVisibility } from '../../method-types.js'; +import type { SyntaxNode } from '../../utils/ast-helpers.js'; + +const ELIXIR_DEF_KEYWORDS = new Set([ + 'def', 'defp', 'defmacro', 'defmacrop', 'defguard', 'defguardp', 'defdelegate', +]); + +const ELIXIR_PRIVATE_KEYWORDS = new Set(['defp', 'defmacrop', 'defguardp']); + +/** Return the `target` identifier text of a call node, or undefined. */ +function callKeyword(node: SyntaxNode): string | undefined { + const t = node.childForFieldName?.('target'); + return t?.type === 'identifier' ? t.text : undefined; +} + +/** Find the arguments node among named children. */ +function findArguments(node: SyntaxNode): SyntaxNode | null { + for (let i = 0; i < node.namedChildCount; i++) { + const c = node.namedChild(i); + if (c?.type === 'arguments') return c; + } + return null; +} + +/** + * Extract the function name from a def/defp call node. + * + * AST shape: call(target: identifier("def"), arguments(call(target: identifier("name"), ...), ...)) + * No-arg zero-clause: call(target: identifier("def"), arguments(identifier("name"), ...)) + */ +function extractElixirName(node: SyntaxNode): string | undefined { + if (!ELIXIR_DEF_KEYWORDS.has(callKeyword(node) ?? '')) return undefined; + const args = findArguments(node); + if (!args) return undefined; + for (let i = 0; i < args.namedChildCount; i++) { + const arg = args.namedChild(i); + if (!arg) continue; + if (arg.type === 'call') { + const innerTarget = arg.childForFieldName?.('target'); + if (innerTarget?.type === 'identifier') return innerTarget.text; + } + if (arg.type === 'identifier') return arg.text; + // binary_operator covers guard forms: def name(x) when is_integer(x) + if (arg.type === 'binary_operator') { + const left = arg.childForFieldName?.('left'); + if (left?.type === 'call') { + const innerTarget = left.childForFieldName?.('target'); + if (innerTarget?.type === 'identifier') return innerTarget.text; + } + } + } + return undefined; +} + +/** + * Extract parameters from the inner function-signature call inside a def node. + * Captures simple identifier parameters; skips pattern-match and default-value nodes. + */ +function extractElixirParameters(node: SyntaxNode): ParameterInfo[] { + const args = findArguments(node); + if (!args) return []; + + // Find the inner call (the function signature) + let sigArgs: SyntaxNode | null = null; + for (let i = 0; i < args.namedChildCount; i++) { + const arg = args.namedChild(i); + if (arg?.type === 'call') { + sigArgs = findArguments(arg); + break; + } + // guard form: binary_operator left: call + if (arg?.type === 'binary_operator') { + const left = arg.childForFieldName?.('left'); + if (left?.type === 'call') { + sigArgs = findArguments(left); + break; + } + } + } + if (!sigArgs) return []; + + const params: ParameterInfo[] = []; + for (let i = 0; i < sigArgs.namedChildCount; i++) { + const p = sigArgs.namedChild(i); + if (!p) continue; + if (p.type === 'identifier') { + params.push({ name: p.text, type: null, isOptional: false, isVariadic: false }); + } else if (p.type === 'binary_operator') { + // default value: `param \\ default` or `param // default` + const left = p.childForFieldName?.('left'); + if (left?.type === 'identifier') { + params.push({ name: left.text, type: null, isOptional: true, isVariadic: false }); + } + } + // Skip map/struct patterns, tuples, etc. — complex destructuring + } + return params; +} + +function extractElixirVisibility(node: SyntaxNode): MethodVisibility { + return ELIXIR_PRIVATE_KEYWORDS.has(callKeyword(node) ?? '') ? 'private' : 'public'; +} + +/** + * Walk up from a def/defp call to find the enclosing defmodule's alias name. + * Returns undefined for top-level functions (no parent defmodule). + */ +function extractElixirOwnerName(node: SyntaxNode): string | undefined { + let cur = node.parent; + while (cur) { + if (cur.type === 'do_block') { + const parent = cur.parent; + if (parent?.type === 'call') { + const kw = callKeyword(parent); + if (kw === 'defmodule') { + const pArgs = findArguments(parent); + if (pArgs) { + for (let i = 0; i < pArgs.namedChildCount; i++) { + const a = pArgs.namedChild(i); + if (a?.type === 'alias') return a.text; + } + } + } + } + } + cur = cur.parent; + } + return undefined; +} + +export const elixirMethodConfig: MethodExtractionConfig = { + language: SupportedLanguages.Elixir, + + // defmodule calls are the class-like containers; def/defp calls are the methods + typeDeclarationNodes: ['call'], + methodNodeTypes: ['call'], + bodyNodeTypes: ['do_block'], + staticOwnerTypes: new Set(), // opt out — Elixir has no static concept + + extractName: extractElixirName, + extractReturnType: () => undefined, // dynamic typing — no return type annotation in AST + extractParameters: extractElixirParameters, + extractVisibility: extractElixirVisibility, + extractOwnerName: extractElixirOwnerName, + + isStatic: () => false, + isAbstract: () => false, + isFinal: () => false, +}; diff --git a/gitnexus/src/core/ingestion/tree-sitter-queries.ts b/gitnexus/src/core/ingestion/tree-sitter-queries.ts index fbde18729..60de31620 100644 --- a/gitnexus/src/core/ingestion/tree-sitter-queries.ts +++ b/gitnexus/src/core/ingestion/tree-sitter-queries.ts @@ -2978,6 +2978,96 @@ export const ZIG_QUERIES = ` member: (identifier) @call.name)) @call `; +export const ELIXIR_QUERIES = ` +; ── Modules ────────────────────────────────────────────────────────────────── +(call + target: (identifier) @_def (#eq? @_def "defmodule") + (arguments + (alias) @name)) @definition.class + +; ── Protocols ───────────────────────────────────────────────────────────────── +(call + target: (identifier) @_def (#eq? @_def "defprotocol") + (arguments + (alias) @name)) @definition.interface + +; ── Public functions & macros ───────────────────────────────────────────────── +(call + target: (identifier) @_def (#eq? @_def "def") + (arguments + (call + target: (identifier) @name))) @definition.function + +(call + target: (identifier) @_def (#eq? @_def "defmacro") + (arguments + (call + target: (identifier) @name))) @definition.function + +(call + target: (identifier) @_def (#eq? @_def "defguard") + (arguments + (call + target: (identifier) @name))) @definition.function + +(call + target: (identifier) @_def (#eq? @_def "defdelegate") + (arguments + (call + target: (identifier) @name))) @definition.function + +; ── Private functions & macros ──────────────────────────────────────────────── +(call + target: (identifier) @_def (#eq? @_def "defp") + (arguments + (call + target: (identifier) @name))) @definition.function + +(call + target: (identifier) @_def (#eq? @_def "defmacrop") + (arguments + (call + target: (identifier) @name))) @definition.function + +(call + target: (identifier) @_def (#eq? @_def "defguardp") + (arguments + (call + target: (identifier) @name))) @definition.function + +; ── Imports: import/use/require ─────────────────────────────────────────────── +(call + target: (identifier) @_kw (#eq? @_kw "import") + (arguments + (alias) @import.source)) @import + +(call + target: (identifier) @_kw (#eq? @_kw "use") + (arguments + (alias) @import.source)) @import + +(call + target: (identifier) @_kw (#eq? @_kw "require") + (arguments + (alias) @import.source)) @import + +; ── Aliases ─────────────────────────────────────────────────────────────────── +(call + target: (identifier) @_kw (#eq? @_kw "alias") + (arguments + (alias) @import.source)) @import + +; ── Remote calls: Module.function() ────────────────────────────────────────── +(call + target: (dot + left: (alias) @call.receiver + right: (identifier) @call.name)) @call + +; ── Local calls: function() — provider filters definitions/control-flow ─────── +(call + target: (identifier) @call.name) @call +`; + import { SupportedLanguages } from 'gitnexus-shared'; const OBJECTIVE_C_QUERIES = `((translation_unit) @objc.root)`; @@ -3001,4 +3091,5 @@ export const LANGUAGE_QUERIES: Record = { [SupportedLanguages.Vue]: TYPESCRIPT_QUERIES, // Vue