Skip to content

returned an error each time something bad occurred. #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion langserver/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func (s *server) Completion(ctx context.Context, params *protocol.CompletionParams) (ret *protocol.CompletionList, err error) {
location, err := s.cache.Find(&params.TextDocumentPositionParams)
if err != nil {
return nil, nil
return nil, err
}

ret = &protocol.CompletionList{}
Expand Down
6 changes: 3 additions & 3 deletions langserver/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
)

// Definition is required by the protocol.Server interface.
func (s *server) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
func (s *server) Definition(_ context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
location, err := s.cache.Find(&params.TextDocumentPositionParams)
if err != nil {
return nil, nil
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's incorrect.

See #185 for why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get why we couldn't return an error saying the document is not there. In the point of view of the cache that's an error.

It should be on the side of the caller to decide what to do with it using a sort of switch case on the error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't suppress errors about documents being not there. In fact this error shouldn't have happened in the first place.

The only type of error that should be suppressed is, if the document context has expired, since in that case the request is silently cancelled to avoid returning outdated results to the client.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For explanation: An expired document context means, the document content has changed while processing the request. While that's rare, it shouldn't result in an error. However in that case, an error is raised internally, since the request can't be handled in a sane way. These special errors have to be filtered out, before responding to the client.

}

defs := []protocol.Location{}
var defs []protocol.Location

switch n := location.Node.(type) { // nolint: gocritic
case *promql.VectorSelector:
Expand Down
4 changes: 2 additions & 2 deletions langserver/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func initializeFunctionDocumentation() http.FileSystem {
func (s *server) Hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) {
location, err := s.cache.Find(&params.TextDocumentPositionParams)
if err != nil || location.Node == nil {
return nil, nil
return nil, err
}

markdown := s.nodeToDocMarkdown(ctx, location)
hoverRange, err := getEditRange(location, "")
if err != nil {
return nil, nil
return nil, err
}

return &protocol.Hover{
Expand Down
8 changes: 4 additions & 4 deletions langserver/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ import (
)

// SignatureHelp is required by the protocol.Server interface.
func (s *server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
func (s *server) SignatureHelp(_ context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
location, err := s.cache.Find(&params.TextDocumentPositionParams)
if err != nil {
return nil, nil
return nil, err
}

call, ok := location.Node.(*promql.Call)
if !ok {
return nil, nil
return nil, errors.New("no node find for the given query")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code branch is not an error condition. In case we reach this, the cursor is not over a function call and we simply return an empty result.

Also note, that returning nil pointers isn't a problem with this endpoint, since no member accesses take place.

}

signature, err := getSignature(call.Func.Name)
if err != nil {
return nil, nil
return nil, err
}

activeParameter := 0.
Expand Down