Skip to content

Commit

Permalink
Return null instead of empty structs (#721)
Browse files Browse the repository at this point in the history
Where the specification says we should. Did not change this for the
notification type events, as they don't render responses. Perhaps we
should change the signature of those functions to not return a result?

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert authored May 20, 2024
1 parent d54f730 commit f9065f6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:nilnil
package lsp

import (
Expand Down Expand Up @@ -517,7 +518,8 @@ func (l *LanguageServer) handleTextDocumentHover(
if !ok {
l.logError(fmt.Errorf("could not get builtins for uri %q", params.TextDocument.URI))

return struct{}{}, nil
// return "null" as per the spec
return nil, nil
}

for _, bp := range builtinsOnLine[params.Position.Line+1] {
Expand All @@ -537,7 +539,8 @@ func (l *LanguageServer) handleTextDocumentHover(
}
}

return struct{}{}, nil
// return "null" as per the spec
return nil, nil
}

func (l *LanguageServer) handleTextDocumentCodeAction(
Expand Down Expand Up @@ -780,8 +783,8 @@ func (l *LanguageServer) handleTextDocumentDefinition(

definition, err := orc.FindDefinition(query)
if err != nil {
// fail silently — the user could have clicked anywhere
return struct{}{}, nil //nolint:nilerr
// fail silently — the user could have clicked anywhere. return "null" as per the spec
return nil, nil //nolint:nilerr
}

loc := types.Location{
Expand Down Expand Up @@ -967,7 +970,8 @@ func (l *LanguageServer) handleTextDocumentFormatting(
if err != nil {
l.logError(fmt.Errorf("failed to format file: %w", err))

return struct{}{}, nil
// return "null" as per the spec
return nil, nil
}

if len(fixResults) == 0 {
Expand Down

0 comments on commit f9065f6

Please sign in to comment.