Rand Stats

Nimala::Raku-LSP

zef:kliklamala

Nimala Logo

NAME

Nimala::Raku-LSP - Complete Raku Language Server Protocol (LSP 3.18) & Debug Adapter Protocol (DAP)

DESCRIPTION

Nimala is a full-featured Language Server Protocol (LSP 3.18) and Debug Adapter Protocol (DAP) implementation for the Raku programming language, written entirely in Raku. It provides advanced IDE intelligence, refactoring capabilities, and integrated debugging to any LSP-compatible editor (such as VS Code, Neovim, Helix, or Emacs).

Key Highlights

LSP 3.18 Implementation Matrix

Of the 95 requests and notifications in the LSP 3.18 meta model, 71 are fully implemented and 2 partially; the remaining 22 are niche or low-utility roadmap items. Each method links to its section in the LSP 3.18 specification. Full audit: docs/lsp-coverage.md.

1. Lifecycle & General

2. Document Synchronization

3. Code Intelligence, Navigation & Editing

4. Hierarchies

5. Diagnostics (Push & Pull)

6. Workspace & Server-Initiated Refreshes

7. Window & Client Interaction

Programmatic Usage

The server binary dispatches JSON-RPC through its own Nimala::Raku-LSP::Dispatcher (method whitelist, cancellation, concurrent requests). For embedding, the handler can also be driven by JSON::RPC::Server, as the test suite does, to analyze Raku code or build custom clients:

use Nimala::Raku-LSP::Handler;
use JSON::RPC::Server;

# Initialize the LSP Handler
my $handler = Nimala::Raku-LSP::Handler.new;

# Wrap it in a JSON-RPC Server
my $server = JSON::RPC::Server.new(application => $handler);

# Simulate a JSON-RPC Request (e.g., from a client)
# Handler methods use '-' for the LSP '/' (send "textDocument-hover", not "textDocument/hover")
my $request = q:to/END/;
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "processId": null,
    "rootUri": null,
    "capabilities": {}
  }
}
END

# Process the request and get the JSON-RPC response
my $response = $server.handler(json => $request);
say $response;

Debug Adapter Protocol (DAP) Architecture

Nimala includes a Debug Adapter Protocol (DAP) server (bin/nimala-raku-dap). The debugger is built directly on MoarVM's native remote debugging protocol, communicating with the debuggee over loopback TCP using MessagePack framing.

For full architectural details, see docs/DEBUG.md and docs/DEBUG-MOARVM.md.

Installation & Dependencies

Nimala requires a working Raku installation (Rakudo 2026.09 recommended) and the sqlite3 shared library for index persistence. Only Rakudo 2026.09 is tested. Rakudo 2024.07 runs with limitations: the debugger can abort with a MoarVM panic, and the RakuAST-based analysis ignores signature parameters and fails on files with BEGIN blocks, so the built-in parser fills in.

Dependencies

Install via Zef

# Install all dependencies and Nimala LSP/DAP binaries
zef install Nimala::Raku-LSP

zef puts the nimala-raku-lsp and nimala-raku-dap scripts into the bin/ directory of the repository it installs to. Without root rights that is usually ~/.raku/bin, which must be in PATH (for example export PATH="$HOME/.raku/bin:$PATH" in ~/.bashrc). Otherwise editors cannot find the server.

Security Considerations

Like standard Raku tooling, the language server executes compile-time code when inspecting documents:

License Artistic-2.0

sub run-tcp-server

sub run-tcp-server(
    Str :$host = "127.0.0.1",
    Int :$port = 5007,
    Bool :$single-session = Bool::False,
    Promise :$stop-promise = Code.new
) returns Nil

Re-export run-tcp-server from Transport::Socket

sub run-server

sub run-server(
    IO::Handle :$in = Code.new,
    IO::Handle :$out = Code.new,
    Nimala::Raku-LSP::Handler :$handler = Code.new,
    :$supply = Code.new
) returns Int

Start the LSP server loop.