Skip to content

Add ErgoScript LSP with real SigmaParser integration (Closes #1097)#1108

Open
sameezy667 wants to merge 3 commits intoergoplatform:masterfrom
sameezy667:sameezy667/lsp-ergoscript
Open

Add ErgoScript LSP with real SigmaParser integration (Closes #1097)#1108
sameezy667 wants to merge 3 commits intoergoplatform:masterfrom
sameezy667:sameezy667/lsp-ergoscript

Conversation

@sameezy667
Copy link

Closes #1097

Overview

Adds a minimal, production-ready Language Server Protocol (LSP) for ErgoScript with real parser integration. Automatically uses SigmaParser when available, falls back to regex-based validation otherwise. Provides diagnostics, hover, and document symbols for IDE/AI agent support.

What I added

  • lsp/server.js — LSP server (Node.js, stdio) with auto-detection of Scala parser
  • lsp/ParserCLI.scala — Scala CLI wrapper that invokes SigmaParser and outputs JSON diagnostics
  • lsp/package.json — Node dependencies (vscode-languageserver)
  • lsp/README.md — Setup, architecture diagram, usage instructions
  • lsp/example.es — Sample ErgoScript file for testing
  • lsp/test_parser.sh — Test script for parser CLI

How it works

Real parser mode (recommended):

  1. Run sbt "parsers/publishLocal" to build parser JAR
  2. LSP auto-detects JAR and spawns scala CLI to invoke ParserCLI.scala
  3. Gets accurate parse errors with line/column from SigmaParser

Fallback mode (no build required):

  • If JAR not found, uses regex-based validation
  • Checks for unmatched braces, TODO markers
  • Still provides hover and symbols

Architecture

LSP Client → server.js → ParserCLI.scala → SigmaParser (fastparse)
↘ regex fallback (if no JAR)

How to test

# Build parser
sbt "parsers/publishLocal"

# Run LSP server
cd lsp
npm install
npm start
Then connect any LSP client (VS Code extension, Neovim, etc.) to the stdio server at node lsp/server.js.

Test files manually:
cd lsp
./test_parser.sh

- Add ParserCLI.scala: Scala wrapper that invokes SigmaParser and outputs JSON diagnostics
- Update server.js: Auto-detect parser JAR and call Scala CLI, fallback to regex if unavailable
- Add architecture diagram showing LSP -> ParserCLI -> SigmaParser flow
- Add example.es: Sample ErgoScript file for testing
- Add test_parser.sh: Helper script to test parser CLI directly
- Document build steps: sbt parsers/publishLocal to enable real parser
- Async validation to avoid blocking on parser invocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant