fix(cmd): handle errors and improve output formatting
* update error handling in various commands to use blank identifier * enhance output formatting for better readability * add golangci-lint to Makefile for linting checks
This commit is contained in:
+7
-7
@@ -89,12 +89,12 @@ func (s *server) handle(raw []byte) bool {
|
||||
return true
|
||||
case "textDocument/didOpen":
|
||||
var p didOpenParams
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
s.docs[p.TextDocument.URI] = p.TextDocument.Text
|
||||
s.pushDiagnostics(p.TextDocument.URI, p.TextDocument.Text)
|
||||
case "textDocument/didChange":
|
||||
var p didChangeParams
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
if len(p.ContentChanges) > 0 {
|
||||
text := p.ContentChanges[len(p.ContentChanges)-1].Text
|
||||
s.docs[p.TextDocument.URI] = text
|
||||
@@ -104,7 +104,7 @@ func (s *server) handle(raw []byte) bool {
|
||||
var p struct {
|
||||
TextDocument textDocID `json:"textDocument"`
|
||||
}
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
delete(s.docs, p.TextDocument.URI)
|
||||
delete(s.fixes, p.TextDocument.URI)
|
||||
s.notify("textDocument/publishDiagnostics", publishDiagnosticsParams{
|
||||
@@ -113,7 +113,7 @@ func (s *server) handle(raw []byte) bool {
|
||||
})
|
||||
case "textDocument/formatting":
|
||||
var p formattingParams
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
text, ok := s.docs[p.TextDocument.URI]
|
||||
if !ok {
|
||||
s.reply(req.ID, []textEdit{})
|
||||
@@ -127,7 +127,7 @@ func (s *server) handle(raw []byte) bool {
|
||||
s.reply(req.ID, []textEdit{fullReplace(text, formatted)})
|
||||
case "textDocument/rangeFormatting":
|
||||
var p rangeFormattingParams
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
text, ok := s.docs[p.TextDocument.URI]
|
||||
if !ok {
|
||||
s.reply(req.ID, []textEdit{})
|
||||
@@ -136,7 +136,7 @@ func (s *server) handle(raw []byte) bool {
|
||||
s.reply(req.ID, s.rangeFormat(text, p.Range))
|
||||
case "textDocument/codeAction":
|
||||
var p codeActionParams
|
||||
json.Unmarshal(req.Params, &p)
|
||||
_ = json.Unmarshal(req.Params, &p)
|
||||
s.handleCodeAction(req.ID, p)
|
||||
case "$/cancelRequest": // ignore
|
||||
default:
|
||||
@@ -360,7 +360,7 @@ func (s *server) send(v interface{}) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(s.w, "Content-Length: %d\r\n\r\n", len(data))
|
||||
_, _ = fmt.Fprintf(s.w, "Content-Length: %d\r\n\r\n", len(data))
|
||||
s.w.Write(data) //nolint:errcheck
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ func readResp(t *testing.T, buf *bytes.Buffer) map[string]interface{} {
|
||||
}
|
||||
lenStr := string(data[idx+16 : idx+eol])
|
||||
var n int
|
||||
fmt.Sscanf(lenStr, "%d", &n)
|
||||
_, _ = fmt.Sscanf(lenStr, "%d", &n)
|
||||
sep := bytes.Index(data, []byte("\r\n\r\n"))
|
||||
if sep < 0 || len(data) < sep+4+n {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
@@ -60,7 +60,7 @@ func readResp(t *testing.T, buf *bytes.Buffer) map[string]interface{} {
|
||||
body := data[sep+4 : sep+4+n]
|
||||
buf.Next(sep + 4 + n)
|
||||
var result map[string]interface{}
|
||||
json.Unmarshal(body, &result)
|
||||
_ = json.Unmarshal(body, &result)
|
||||
return result
|
||||
}
|
||||
t.Fatal("timeout waiting for response")
|
||||
|
||||
Reference in New Issue
Block a user