mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
d88f79806b
If a package has an error that makes it completely unparseable, such as containing a .go file with no "package" statement, the error was previously unreported. Such errors would manifest as other errors. Fixes golang/go#31712 Change-Id: I11b8d0e2e4d64b03fbcb4c35e7f0b02fccc83fad GitHub-Last-Rev: 1581cbe36c269dd964f0b9226dbd63b1650c2a5b GitHub-Pull-Request: golang/tools#102 Reviewed-on: https://go-review.googlesource.com/c/tools/+/177605 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
51 lines
1.2 KiB
Go
51 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
|
|
}
|
|
// find the import block
|
|
ast := f.GetAST(ctx)
|
|
if ast == nil {
|
|
return nil, fmt.Errorf("no AST for %v", uri)
|
|
}
|
|
|
|
var result []protocol.DocumentLink
|
|
for _, imp := range ast.Imports {
|
|
spn, err := span.NewRange(f.GetFileSet(ctx), 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
|
|
}
|