Better LSP error handling
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/marte-community/marte-dev-tools/internal/logger"
|
||||
"github.com/marte-community/marte-dev-tools/internal/parser"
|
||||
)
|
||||
|
||||
@@ -456,9 +455,7 @@ type QueryResult struct {
|
||||
}
|
||||
|
||||
func (pt *ProjectTree) Query(file string, line, col int) *QueryResult {
|
||||
logger.Printf("File: %s:%d:%d", file, line, col)
|
||||
for i := range pt.References {
|
||||
logger.Printf("%s", pt.Root.Name)
|
||||
ref := &pt.References[i]
|
||||
if ref.File == file {
|
||||
if line == ref.Position.Line && col >= ref.Position.Column && col < ref.Position.Column+len(ref.Name) {
|
||||
|
||||
@@ -222,6 +222,12 @@ func readMessage(reader *bufio.Reader) (*JsonRpcMessage, error) {
|
||||
}
|
||||
|
||||
func HandleMessage(msg *JsonRpcMessage) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Printf("Panic in HandleMessage: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
switch msg.Method {
|
||||
case "initialize":
|
||||
var params InitializeParams
|
||||
@@ -1326,10 +1332,10 @@ func HandleRename(params RenameParams) *WorkspaceEdit {
|
||||
}
|
||||
|
||||
func respond(id any, result any) {
|
||||
msg := JsonRpcMessage{
|
||||
Jsonrpc: "2.0",
|
||||
ID: id,
|
||||
Result: result,
|
||||
msg := map[string]any{
|
||||
"jsonrpc": "2.0",
|
||||
"id": id,
|
||||
"result": result,
|
||||
}
|
||||
send(msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user