diff --git a/internal/lsp/general.go b/internal/lsp/general.go index 3da03e3fc3..aeb6c5b223 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -439,6 +439,7 @@ func (s *Server) handleOptionResults(ctx context.Context, results source.OptionR // it to a snapshot. // We don't want to return errors for benign conditions like wrong file type, // so callers should do if !ok { return err } rather than if err != nil. +// The returned cleanup function is non-nil even in case of false/error result. func (s *Server) beginFileRequest(ctx context.Context, pURI protocol.DocumentURI, expectKind source.FileKind) (source.Snapshot, source.VersionedFileHandle, bool, func(), error) { uri := pURI.SpanURI() if !uri.IsFile() { diff --git a/internal/lsp/source/util.go b/internal/lsp/source/util.go index e277bdab45..768ff8c636 100644 --- a/internal/lsp/source/util.go +++ b/internal/lsp/source/util.go @@ -263,13 +263,16 @@ func CompareDiagnostic(a, b *Diagnostic) int { if a.Source < b.Source { return -1 } + if a.Source > b.Source { + return +1 + } if a.Message < b.Message { return -1 } - if a.Message == b.Message { - return 0 + if a.Message > b.Message { + return +1 } - return 1 + return 0 } // FindPackageFromPos finds the first package containing pos in its diff --git a/internal/lsp/template/parse.go b/internal/lsp/template/parse.go index ee35d634d2..181a5228fd 100644 --- a/internal/lsp/template/parse.go +++ b/internal/lsp/template/parse.go @@ -493,14 +493,8 @@ func (wr wrNode) writeNode(n parse.Node, indent string) { } // short prints at most 40 bytes of node.String(), for debugging -func short(n parse.Node) (ret string) { - defer func() { - if x := recover(); x != nil { - // all because of typed nils - ret = "NIL" - } - }() - s := n.String() +func short(n parse.Node) string { + s := fmt.Sprint(n) // recovers from panic if len(s) > 40 { return s[:40] + "..." }