Skip to main content

LSP WebSocket Protocol

The Constellation Engine provides an LSP (Language Server Protocol) endpoint via WebSocket for IDE integration.

IDE Setup Checklist

  1. Install the extension — Search "Constellation" in Extensions marketplace
  2. Start the server — Run make server or sbt "exampleApp/run"
  3. Open a .cst file — Syntax highlighting activates automatically
  4. Verify connection — Status bar shows "Constellation: Connected"

Other Editors (Generic LSP)

For Neovim, Emacs, Sublime Text, or other LSP-capable editors:

  1. Configure LSP client to connect to ws://localhost:8080/lsp
  2. Set file type — Associate .cst files with the Constellation language
  3. Start server first — The LSP endpoint requires a running server

Troubleshooting Connection

SymptomCauseFix
"Connection refused"Server not runningStart with make server
No autocompleteWrong portCheck CONSTELLATION_PORT env var
Diagnostics staleWebSocket disconnectedRestart editor LSP client

Verify It's Working

Type this in a .cst file and check for autocomplete:

in x: Int
result = Upp # Should show Uppercase suggestion

If autocomplete appears, LSP is connected and working.

Connection

Endpoint: ws://localhost:8080/lsp

Connect using any WebSocket client. Messages follow the LSP specification with JSON-RPC 2.0 framing.

Message Format

All messages use the LSP Content-Length header format:

Content-Length: <length>\r\n\r\n<json-payload>

Where <length> is the byte length of the JSON payload in UTF-8.

Supported Methods

Lifecycle

MethodTypeDescription
initializeRequestInitialize the language server
initializedNotificationClient finished initialization
shutdownRequestPrepare server for exit
exitNotificationExit the server

Text Document Synchronization

MethodTypeDescription
textDocument/didOpenNotificationDocument opened
textDocument/didChangeNotificationDocument content changed
textDocument/didCloseNotificationDocument closed

Language Features

MethodTypeDescription
textDocument/completionRequestGet completion items
textDocument/hoverRequestGet hover information

Custom Methods (Constellation-specific)

MethodTypeDescription
constellation/executePipelineRequestExecute the current script
constellation/getInputSchemaRequestGet input schema for script
constellation/getDagStructureRequestGet DAG visualization data
constellation/stepStartRequestStart step-through execution
constellation/stepNextRequestExecute next batch
constellation/stepContinueRequestRun to completion
constellation/stepStopRequestStop debug session

Example Messages

Initialize Request

{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"processId": 1234,
"capabilities": {}
}
}

Initialize Response

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capabilities": {
"textDocumentSync": 1,
"completionProvider": {
"triggerCharacters": ["(", ",", " ", "."]
},
"hoverProvider": true
}
}
}

Document Open Notification

{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "file:///path/to/script.cst",
"languageId": "constellation",
"version": 1,
"text": "in text: String\nresult = Uppercase(text)\nout result"
}
}
}

Completion Request

{
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/completion",
"params": {
"textDocument": {
"uri": "file:///path/to/script.cst"
},
"position": {
"line": 1,
"character": 10
}
}
}

Completion Response

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"isIncomplete": false,
"items": [
{
"label": "Uppercase",
"kind": 3,
"detail": "Uppercase(text: String) -> String",
"documentation": "Converts text to uppercase",
"insertText": "Uppercase()"
}
]
}
}

Execute Pipeline Request

{
"jsonrpc": "2.0",
"id": 3,
"method": "constellation/executePipeline",
"params": {
"uri": "file:///path/to/script.cst",
"inputs": {
"text": "hello world"
}
}
}

Execute Pipeline Response

{
"jsonrpc": "2.0",
"id": 3,
"result": {
"success": true,
"outputs": {
"result": "HELLO WORLD"
},
"executionTimeMs": 15
}
}

Get DAG Structure Request

{
"jsonrpc": "2.0",
"id": 4,
"method": "constellation/getDagStructure",
"params": {
"uri": "file:///path/to/script.cst"
}
}

Get DAG Structure Response

{
"jsonrpc": "2.0",
"id": 4,
"result": {
"success": true,
"dag": {
"modules": {
"uuid-1": {
"name": "Uppercase",
"consumes": {"text": "String"},
"produces": {"result": "String"}
}
},
"data": {
"uuid-2": {"name": "text", "cType": "String"},
"uuid-3": {"name": "result", "cType": "String"}
},
"inEdges": [["uuid-2", "uuid-1"]],
"outEdges": [["uuid-1", "uuid-3"]],
"declaredOutputs": ["result"]
}
}
}

Step-Through Execution

Start a debug session:

{
"jsonrpc": "2.0",
"id": 5,
"method": "constellation/stepStart",
"params": {
"uri": "file:///path/to/script.cst",
"inputs": {"text": "hello"}
}
}

Response includes session ID:

{
"jsonrpc": "2.0",
"id": 5,
"result": {
"success": true,
"sessionId": "session-abc123",
"totalBatches": 3,
"initialState": {
"currentBatch": 0,
"totalBatches": 3,
"batchNodes": ["uuid-1"],
"completedNodes": [],
"pendingNodes": ["uuid-2", "uuid-3"]
}
}
}

Step to next batch:

{
"jsonrpc": "2.0",
"id": 6,
"method": "constellation/stepNext",
"params": {
"sessionId": "session-abc123"
}
}

Server-Sent Notifications

The server sends diagnostics when documents are validated:

{
"jsonrpc": "2.0",
"method": "textDocument/publishDiagnostics",
"params": {
"uri": "file:///path/to/script.cst",
"diagnostics": [
{
"range": {
"start": {"line": 1, "character": 9},
"end": {"line": 1, "character": 18}
},
"severity": 1,
"source": "constellation-lang",
"message": "Undefined function: Upppercase"
}
]
}
}

Error Responses

Errors follow JSON-RPC 2.0 format:

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32601,
"message": "Method not found: unknownMethod"
}
}

Standard error codes:

  • -32700 - Parse error
  • -32600 - Invalid request
  • -32601 - Method not found
  • -32602 - Invalid params
  • -32603 - Internal error

Client Implementation Notes

  1. Keep-alive: Empty messages are silently ignored (can be used for keep-alive pings)
  2. Text sync: Use textDocumentSync: 1 (full document sync)
  3. Diagnostics: Published automatically after didOpen and didChange
  4. Completion triggers: (, ,, , . trigger completion suggestions