mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
7927dbab1b
This moves the fileset down to the base cache, the overlays down to the session and stores the environment on the view. packages.Config is no longer part of any public API, and the config is build on demand by combining all the layers of cache. Also added some documentation to the main source pacakge interfaces. Change-Id: I058092ad2275d433864d1f58576fc55e194607a6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/178017 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Copyright 2018 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 lsp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLinkParams) ([]protocol.DocumentLink, error) {
|
|
uri := span.NewURI(params.TextDocument.URI)
|
|
view := s.session.ViewOf(uri)
|
|
f, m, err := getGoFile(ctx, view, uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
file := f.GetAST(ctx)
|
|
if file == nil {
|
|
return nil, fmt.Errorf("no AST for %v", uri)
|
|
}
|
|
// Add a Godoc link for each imported package.
|
|
var result []protocol.DocumentLink
|
|
for _, imp := range file.Imports {
|
|
spn, err := span.NewRange(f.FileSet(), imp.Pos(), imp.End()).Span()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rng, err := m.Range(spn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
target, err := strconv.Unquote(imp.Path.Value)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
target = "https://godoc.org/" + target
|
|
result = append(result, protocol.DocumentLink{
|
|
Range: rng,
|
|
Target: target,
|
|
})
|
|
}
|
|
return result, nil
|
|
}
|