@@ -2,7 +2,6 @@ package controllers
22
33import (
44 "encoding/json"
5- "fmt"
65
76 "github.com/delta/codecharacter-lsp-2023/models"
87 "github.com/gorilla/websocket"
@@ -15,7 +14,6 @@ func HandleMessage(ws *models.WebsocketConnection, messageBytes []byte) error {
1514 return err
1615 }
1716 _ , isPresent := message ["jsonrpc" ]
18- fmt .Println ("Is JSONRPC? : " , isPresent )
1917 if isPresent {
2018 return handleJSONRPCRequest (ws , messageBytes )
2119 }
@@ -27,22 +25,26 @@ func SendMessage(ws *models.WebsocketConnection, message map[string]interface{})
2725 if err != nil {
2826 return err
2927 }
30- err = ws .Connection .WriteMessage (websocket .TextMessage , messageBytes )
31- if err != nil {
32- return err
33- }
34- return nil
28+ return ws .Connection .WriteMessage (websocket .TextMessage , messageBytes )
29+ }
30+
31+ func SendErrorMessage (ws * models.WebsocketConnection , message error ) error {
32+ responseBody := make (map [string ]interface {})
33+ responseBody ["status" ] = "error"
34+ responseBody ["message" ] = message .Error ()
35+ return SendMessage (ws , responseBody )
3536}
3637
3738func handleJSONRPCRequest (ws * models.WebsocketConnection , messageBytes []byte ) error {
38- fmt .Println ("JSONRPC Request : " , string (messageBytes ), " with ID : " , ws .ID )
39- return nil
39+ return handleJSONRPC (ws , messageBytes )
4040}
4141
4242func handleWebSocketRequest (ws * models.WebsocketConnection , message map [string ]interface {}) error {
43- fmt . Println ( "Websocket Request : " , message , " with ID : " , ws . ID )
44- if message [ "operation" ] == " fileUpdate" {
43+ switch message [ "operation" ] {
44+ case " fileUpdate":
4545 return handleFileUpdate (message , ws )
46+ case "getAbsPath" :
47+ return getAbsPath (ws )
4648 }
4749 return nil
4850}
0 commit comments