From c99c831cc45585d30ee571520ff4f43e61b311a7 Mon Sep 17 00:00:00 2001 From: Jan Pfeifer Date: Wed, 8 Mar 2023 09:49:45 +0100 Subject: [PATCH] Fixed small Go Report Card issues. --- dispatcher/dispatcher.go | 2 +- docs/CHANGELOG.md | 4 ++++ goexec/goexec.go | 1 - goexec/goplsclient/conn.go | 22 ++++++---------------- goexec/goplsclient/goplsclient.go | 4 ++-- main.go | 2 +- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/dispatcher/dispatcher.go b/dispatcher/dispatcher.go index 9f257ce..1a9767f 100644 --- a/dispatcher/dispatcher.go +++ b/dispatcher/dispatcher.go @@ -247,7 +247,7 @@ func HandleInspectRequest(msg kernel.Message, goExec *goexec.State) error { func handleCompleteRequest(msg kernel.Message, goExec *goexec.State) (err error) { log.Printf("`complete_request`:") - // Start with emtpy reply, and makes sure reply is sent at the end. + // Start with empty reply, and makes sure reply is sent at the end. reply := &kernel.CompleteReply{ Status: "ok", Matches: []string{}, diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3fcdf93..8db5326 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # GoNB Changelog +## v0.3.9 + +* Small Go Report Card fixes (https://goreportcard.com/report/github.com/janpfeifer/gonb) + ## v0.3.8 * Fixed CSS for VSCode/Github Codespaces -- it doesn't play very well with Jupyter CSS. diff --git a/goexec/goexec.go b/goexec/goexec.go index b1fc7f9..c6c0a86 100644 --- a/goexec/goexec.go +++ b/goexec/goexec.go @@ -89,7 +89,6 @@ with: !go install golang.org/x/tools/gopls@latest ` + "```\n" log.Printf(msg) - err = nil } log.Printf("Initialized goexec.State in %s", s.TempDir) diff --git a/goexec/goplsclient/conn.go b/goexec/goplsclient/conn.go index 2ab0586..e37865d 100644 --- a/goexec/goplsclient/conn.go +++ b/goexec/goplsclient/conn.go @@ -4,15 +4,16 @@ import ( "context" "encoding/json" "fmt" + "log" + "net" + "strings" + "time" + jsonrpc2 "github.com/go-language-server/jsonrpc2" lsp "github.com/go-language-server/protocol" "github.com/go-language-server/uri" "github.com/golang/glog" "github.com/pkg/errors" - "log" - "net" - "strings" - "time" ) var _ = lsp.MethodInitialize @@ -175,7 +176,7 @@ func (c *Client) notifyDidOpenOrChangeLocked(ctx context.Context, filePath strin Version: &version, }, ContentChanges: []lsp.TextDocumentContentChangeEvent{ - lsp.TextDocumentContentChangeEvent{ + { Text: fileData.Content, }, }, @@ -341,17 +342,6 @@ func trimString(s string, maxLen int) string { return s[:maxLen-1] + `…` } -// sampleRawJson returns a sample of the raw Json message (up to 100 bytes) -// converted to string. For logging/debugging prints. -func sampleRawJson(content json.RawMessage) string { - b := []byte(content) - if len(b) > 100 { - return string(b[:100]) + "..." - - } - return string(b) -} - // Deliver implements jsonrpc2.Handler. func (h *jsonrpc2Handler) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool { _ = ctx diff --git a/goexec/goplsclient/goplsclient.go b/goexec/goplsclient/goplsclient.go index 7574bd5..214576d 100644 --- a/goexec/goplsclient/goplsclient.go +++ b/goexec/goplsclient/goplsclient.go @@ -98,7 +98,7 @@ func (c *Client) Shutdown() { } // isGoInternalOrCache returns whether if file is from Go implementation or -// cached from a versioned library, in which case it's not expected to be changed +// cached from a versioned library, in which case it's not expected to be changed, // and we don't need to open the file in gopls. // TODO: implement, for now we always open all files. func isGoInternalOrCache(filePath string) bool { @@ -230,7 +230,7 @@ func (c *Client) FileData(filePath string) (content *FileData, updated bool, err return } glog.V(2).Infof("File %q: stored date is %s, fileInfo mod time is %s", - content.ContentTime, fileInfo.ModTime()) + filePath, content.ContentTime, fileInfo.ModTime()) } content = &FileData{ diff --git a/main.go b/main.go index afd4821..1c4bc39 100644 --- a/main.go +++ b/main.go @@ -93,7 +93,7 @@ func SetUpLogging() { if *flagExtraLog != "" { f, err := os.OpenFile(*flagExtraLog, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) if err != nil { - log.Fatalf("Failed to open log file %q for writting: %+v", *flagExtraLog, err) + log.Fatalf("Failed to open log file %q for writing: %+v", *flagExtraLog, err) } f.Write([]byte("\n\n")) w := io.MultiWriter(f, os.Stderr) // Write to STDERR and the newly open f.