1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:04:41 -07:00
go/internal/lsp/source/call_hierarchy.go
Rebecca Stambler fd80f4dbb3 internal/lsp: fix a few small staticcheck warnings
Address unused context / unused error warnings.

Change-Id: Ibd302d58a3d6db5aa274ed95fb6d5a337978779a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Danish Dua <danishdua@google.com>
2020-08-11 03:20:01 +00:00

75 lines
2.5 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package source
import (
"context"
"go/ast"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/lsp/debug/tag"
"golang.org/x/tools/internal/lsp/protocol"
errors "golang.org/x/xerrors"
)
// PrepareCallHierarchy returns an array of CallHierarchyItem for a file and the position within the file
func PrepareCallHierarchy(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protocol.Position) ([]protocol.CallHierarchyItem, error) {
ctx, done := event.Start(ctx, "source.prepareCallHierarchy")
defer done()
identifier, err := Identifier(ctx, snapshot, fh, pos)
if err != nil {
if errors.Is(err, ErrNoIdentFound) {
event.Log(ctx, err.Error(), tag.Position.Of(pos))
} else {
event.Error(ctx, "error getting identifier", err, tag.Position.Of(pos))
}
return nil, nil
}
// if identifier is not of type function
_, ok := identifier.Declaration.node.(*ast.FuncDecl)
if !ok {
event.Log(ctx, "invalid identifier type, expected funtion declaration", tag.Position.Of(pos))
return nil, nil
}
rng, err := identifier.Range()
if err != nil {
return nil, err
}
callHierarchyItem := protocol.CallHierarchyItem{
Name: identifier.Name,
Kind: protocol.Function,
Tags: []protocol.SymbolTag{},
Detail: "func()",
URI: protocol.DocumentURI(fh.URI()),
Range: rng,
SelectionRange: rng,
}
return []protocol.CallHierarchyItem{callHierarchyItem}, nil
}
// IncomingCalls returns an array of CallHierarchyIncomingCall for a file and the position within the file
func IncomingCalls(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protocol.Position) ([]protocol.CallHierarchyIncomingCall, error) {
ctx, done := event.Start(ctx, "source.incomingCalls")
defer done()
// TODO: Remove this once the context is used.
_ = ctx // avoid staticcheck SA4006 warning
return []protocol.CallHierarchyIncomingCall{}, nil
}
// OutgoingCalls returns an array of CallHierarchyOutgoingCall for a file and the position within the file
func OutgoingCalls(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protocol.Position) ([]protocol.CallHierarchyOutgoingCall, error) {
ctx, done := event.Start(ctx, "source.outgoingCalls")
defer done()
// TODO: Remove this once the context is used.
_ = ctx // avoid staticcheck SA4006 warning
return []protocol.CallHierarchyOutgoingCall{}, nil
}