diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-03 15:20:15 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-03 17:23:41 +0200 |
| commit | cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0 (patch) | |
| tree | a822bfde1463a7080c0ea06dd17796d7a1617d3d /internal/lsp/protocol.go | |
| parent | afd9ad0560d76c2a6d161dad52553b10ff428905 (diff) | |
| download | opencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.tar.gz opencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.zip | |
add initial lsp support
Diffstat (limited to 'internal/lsp/protocol.go')
| -rw-r--r-- | internal/lsp/protocol.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/lsp/protocol.go b/internal/lsp/protocol.go new file mode 100644 index 000000000..e70e2824b --- /dev/null +++ b/internal/lsp/protocol.go @@ -0,0 +1,48 @@ +package lsp + +import ( + "encoding/json" +) + +// Message represents a JSON-RPC 2.0 message +type Message struct { + JSONRPC string `json:"jsonrpc"` + ID int32 `json:"id,omitempty"` + Method string `json:"method,omitempty"` + Params json.RawMessage `json:"params,omitempty"` + Result json.RawMessage `json:"result,omitempty"` + Error *ResponseError `json:"error,omitempty"` +} + +// ResponseError represents a JSON-RPC 2.0 error +type ResponseError struct { + Code int `json:"code"` + Message string `json:"message"` +} + +func NewRequest(id int32, method string, params any) (*Message, error) { + paramsJSON, err := json.Marshal(params) + if err != nil { + return nil, err + } + + return &Message{ + JSONRPC: "2.0", + ID: id, + Method: method, + Params: paramsJSON, + }, nil +} + +func NewNotification(method string, params any) (*Message, error) { + paramsJSON, err := json.Marshal(params) + if err != nil { + return nil, err + } + + return &Message{ + JSONRPC: "2.0", + Method: method, + Params: paramsJSON, + }, nil +} |
