Skip to content

[Self-Hosting] Phase 5: Implement LSP Server in Gradient #122

@graydeon

Description

@graydeon

Summary

Implement the LSP server in Gradient. Full Language Server Protocol support for IDE integration.

Background

With the queryable API in Gradient (Phase 4), we can now implement the LSP server itself in Gradient. Currently the LSP is in Rust (codebase/devtools/lsp/).

Target State

NEW FILE: compiler/lsp.gr (~3,000 lines)

LSP server that:

  • Listens for JSON-RPC messages
  • Responds to LSP requests
  • Uses query.gr for all data

Implementation Requirements

LSP Capabilities

  1. textDocument/diagnostic

    • Real-time error reporting
    • Use session_check()
  2. textDocument/hover

    • Type information on hover
    • Use session_type_at()
  3. textDocument/definition

    • Go to definition
    • Use symbol table
  4. textDocument/references

    • Find all references
    • Use query API
  5. textDocument/rename

    • Safe renaming
    • Use session_rename()
  6. textDocument/completion

    • Autocomplete suggestions
    • Use session_symbols()
  7. textDocument/documentSymbol

    • Outline/symbol tree
    • Use symbol table

JSON-RPC Handling

  • Parse incoming messages
  • Route to handlers
  • Serialize responses

State Management

  • Track open documents
  • Cache parsed sessions
  • Incremental sync (if supported)

Acceptance Criteria

  • LSP server starts and listens
  • Handles all basic LSP methods
  • Real-time diagnostics working
  • Hover information working
  • Go-to-definition working
  • Find references working
  • Rename refactoring working
  • Autocomplete working
  • Works with VS Code, Neovim, etc.

Testing

Test with:

  • VS Code extension
  • Neovim LSP client
  • Emacs LSP mode

Part Of

  • Epic: Full Self-Hosting with Rust Kernel
  • Phase: 5 of 7
  • Blocks: Phase 6 (IR Builder)

Effort

~7 days, ~2,500 lines of Gradient

Dependencies

  • Phase 4 complete (Query API)
  • JSON parsing/writing in Gradient (may need primitives)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions