codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

Feature Request: Add Hybrid LSP support for Julia

Open zhuh2664-coder opened this issue 5 months ago • 4 comments

What problem does this solve?

I'm indexing Julia projects with codebase-memory-mcp. The tree-sitter layer extracts functions/structs/modules fine, but cross-file call tracing is broken because Julia uses multiple dispatch — method resolution depends on argument types, not just function names.

Concrete example:

File A: src/models/user.jl

function process(data::DataFrame) transform(data, :name => uppercase) end

File B: src/api/handler.jl

function handle_request(req) df = load_data(req) process(df) # ← codebase-memory-mcp can't resolve this call end

Without Hybrid LSP, the graph shows NO edge between handle_request and process, because it can't infer that df is a DataFrame and therefore process(::DataFrame) is the correct dispatch target.

Impact:

  • Call graph is incomplete for any Julia project using type-based dispatch (which is ALL Julia projects)
  • Dead code detection gives false positives (thinks dispatched methods are unused)
  • trace_path returns empty for cross-module calls

Proposed solution

Add Hybrid LSP pass for Julia that resolves:

  1. using/import chains to build module dependency graph
  2. Type annotations and parametric types for method dispatch resolution
  3. Multiple dispatch: match call sites to method signatures by argument types
  4. Common patterns: @generated functions, macro expansions (basic level)

Suggested test repositories:

  • Flux.jl (https://github.com/FluxML/Flux.jl) — ML framework, heavy use of dispatch and parametric types (~15k LOC)
  • DifferentialEquations.jl (https://github.com/SciML/DifferentialEquations.jl) — scientific computing, complex module hierarchy
  • Genie.jl (https://github.com/GenieFramework/Genie.jl) — web framework, HTTP routing patterns similar to Go/TS Hybrid LSP implementations
  • Makie.jl (https://github.com/MakieOrg/Makie.jl) — visualization, large multi-package structure

Priority: Flux.jl is the best starting point — small enough to iterate fast, complex enough to exercise dispatch, parametric types, and macros.


Alternatives considered

Type-stripped fallback resolution: When Hybrid LSP can't resolve types, fall back to matching function calls by NAME ONLY (ignoring all argument types). For a call like process(df), find ALL process definitions in the project and create edges to ALL of them with a "unresolved_dispatch" flag.

 Pros: Simple to implement, no type inference needed, zero false negatives
 for call existence (though may have false positives for dispatch target).
 Cons: Creates multiple edges per call site, may need post-filtering.

Confirmations

  • [x] I searched existing issues and this is not a duplicate.

zhuh2664-coder avatar Jun 20 '26 12:06 zhuh2664-coder

Hey, we are currently trying to build LSP Hybrids for other languages. If the community demands julia, we can prioritize it up. But for now it will likely not land in the close future, ss LSP Hybrid äs tend to be tricky requiri g a high parity test coverage etc. If you like you can attempt it yourself in a light version given the existing patterns and commit it as PR :) Would support you with it

DeusData avatar Jun 20 '26 23:06 DeusData

Thank you for the Julia proposal and the multiple-dispatch example. The language-support direction still needs a maintainer decision before anyone invests in a larger implementation. I do not have a new delivery date to offer. Sorry for the delay—this is waiting on maintainer follow-up, and I’ll follow up soon.

DeusData avatar Oct 25 '26 17:10 DeusData

I'd like to take this on, sliced the same way as the Ruby resolver work in #1706/#1711, so that each PR stays reviewable and stands on its own. Proposed slices (all C, following the existing perl_lsp.c / ruby_lsp.c shape, dispatched from cbm_extract_file):

  1. Pass 1 + single-file dispatch. This slice is the minimum useful version, and it already fixes the example in this issue for same-file calls.
    • Collect modules (with nesting), struct and abstract type declarations including parametric types and supertypes, and method tables keyed by name plus arity and annotated argument types.
    • Resolve calls whose argument types are known from literals, constructors (T(...) / T{P}(...)) or annotated locals.
    • Pick the most specific matching method by subtype distance over the collected hierarchy. Ambiguous calls resolve to no edge rather than a guessed one.
  2. Local type inference.
    • Assignment and constructor propagation, ::T annotations, simple Union{...}, and where clauses.
    • Keyword arguments and Vararg, which are ignored for dispatch except arity bounds.
    • Each latch has a conflict rule: conflicting assignments yield no type, as in the Ruby ivar pass.
  3. Cross-file resolution. using / import / export / include("file.jl") resolution through the existing registry, plus a small curated Base/stdlib seed (DataFrames-style constructors stay out unless you want them).

Each slice comes with tests/test_julia_lsp.c cases. Those cases include the multiple-dispatch example from this issue, plus negative cases (ambiguous dispatch, untyped arguments) asserting that no edge is created. Each slice also passes scripts/test.sh and scripts/lint.sh --ci.

Questions before I start:

  • Is a Julia resolver something you'd merge given the earlier note that the direction needs a decision?
  • If yes, is this slicing OK? Should the stdlib seed be a generated data file like generated/ruby_stdlib_data.c?

Disclosure: I'd write this with AI assistance (Claude/Cursor). I review and test it, and sign off every commit (DCO).

Cookie0103 avatar Nov 08 '26 05:11 Cookie0103

Update: I won't be able to take this on after all, so please don't hold the slot for me — anyone else is welcome to pick up the slicing above if it's useful. Sorry for the noise.

Cookie0103 avatar Nov 08 '26 05:11 Cookie0103