serena icon indicating copy to clipboard operation
serena copied to clipboard

feat: Add comprehensive OCaml language support with ocaml-lsp-server integration

Open johnhaley81 opened this issue 4 months ago • 6 comments

This PR adds full OCaml language support to Serena through integration with the ocaml-lsp-server, following the established solidlsp architecture pattern.

Changes Made:

Core Language Server Integration

  • New OCamlLspServer class (src/solidlsp/language_servers/ocaml_lsp_server/ocaml_lsp_server.py):
    • Implements solidlsp interface for ocaml-lsp-server
    • Handles OCaml-specific initialization parameters and capabilities
    • Manages Dune build system integration and workspace detection
    • Includes proper error handling and logging

Runtime Dependencies Management

  • Automatic dependency resolution for ocaml-lsp-server installation
  • Runtime dependencies configuration specifying required OCaml toolchain versions
  • Cross-platform support for different OCaml installation methods

Language Support Registration

  • Added OCaml to the Language enum in ls_config.py
  • Integrated OCaml support into the language server factory in ls.py
  • Added ocaml pytest marker to pyproject.toml for targeted testing

Comprehensive Test Infrastructure

  • Realistic test repository (test/resources/repos/ocaml/test_repo/):

    • Complete Dune project structure with dune-project, .opam files
    • Library module with interface file (.mli) demonstrating OCaml conventions
    • Executable binary and test suite following OCaml best practices
    • Proper module dependencies and build configuration
  • Test suite (test/solidlsp/ocaml/test_ocaml_basic.py):

    • Symbol discovery and navigation tests
    • Reference finding across modules and interfaces
    • Integration testing with Dune build system
    • Validation of LSP capabilities specific to OCaml

Build System Integration

  • Dune project support with proper workspace detection
  • OPAM package management integration for dependency resolution
  • Interface file (.mli) handling for OCaml's module system

Technical Implementation Details:

  • Follows established solidlsp patterns for consistency with existing language servers
  • Implements OCaml-specific LSP initialization parameters for optimal language server performance
  • Handles OCaml's unique module system with proper interface file support
  • Integrates with Dune's workspace model for accurate project boundary detection

Testing Strategy:

  • Language-specific test suite using ocaml pytest marker
  • Realistic OCaml project structure for integration testing
  • Validation of core LSP operations (symbols, references, definitions)
  • Build system integration testing with Dune

This addition brings Serena's OCaml support to the same level as other supported languages, enabling full semantic code analysis and manipulation for OCaml codebases.

johnhaley81 avatar Aug 28 '25 15:08 johnhaley81

Thx! Pls run poe format such that CI can run trough

MischaPanch avatar Aug 28 '25 16:08 MischaPanch

@MischaPanch out of draft now

johnhaley81 avatar Aug 29 '25 22:08 johnhaley81

@johnhaley81 still interested in getting this merged? :)

MischaPanch avatar Sep 12 '25 22:09 MischaPanch

Yes! Sorry I got sucked down a rabbit hole trying to figure out some things with cross file references with ocaml-lap-server. I'll have some more commits this weekend for it

johnhaley81 avatar Sep 12 '25 22:09 johnhaley81

Cool, happy to hear that!

MischaPanch avatar Sep 12 '25 22:09 MischaPanch

@johnhaley81 ping :)

MischaPanch avatar Oct 19 '25 10:10 MischaPanch