@@ -2,7 +2,6 @@ package controllers
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
7
6
"github.com/delta/codecharacter-lsp-2023/models"
8
7
"github.com/gorilla/websocket"
@@ -15,7 +14,6 @@ func HandleMessage(ws *models.WebsocketConnection, messageBytes []byte) error {
15
14
return err
16
15
}
17
16
_ , isPresent := message ["jsonrpc" ]
18
- fmt .Println ("Is JSONRPC? : " , isPresent )
19
17
if isPresent {
20
18
return handleJSONRPCRequest (ws , messageBytes )
21
19
}
@@ -27,22 +25,26 @@ func SendMessage(ws *models.WebsocketConnection, message map[string]interface{})
27
25
if err != nil {
28
26
return err
29
27
}
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 )
35
36
}
36
37
37
38
func 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 )
40
40
}
41
41
42
42
func 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":
45
45
return handleFileUpdate (message , ws )
46
+ case "getAbsPath" :
47
+ return getAbsPath (ws )
46
48
}
47
49
return nil
48
50
}
0 commit comments