Skip to content

Commit

Permalink
Merge pull request #36 from xushiwei/ref
Browse files Browse the repository at this point in the history
lsp/references
  • Loading branch information
xushiwei authored Oct 22, 2023
2 parents 2483ace + c6df25d commit 16430d6
Show file tree
Hide file tree
Showing 6 changed files with 724 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gopls/internal/lsp/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func (s *Server) references(ctx context.Context, params *protocol.ReferenceParam
if !ok {
return nil, err
}
if snapshot.View().FileKind(fh) == source.Tmpl {
// goxls: Go+
// if snapshot.View().FileKind(fh) == source.Tmpl {
if kind := snapshot.View().FileKind(fh); kind == source.Gop {
return source.GopReferences(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration)
} else if kind == source.Tmpl {
return template.References(ctx, snapshot, fh, params)
}
return source.References(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration)
Expand Down
5 changes: 5 additions & 0 deletions gopls/internal/lsp/references_gox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2023 The GoPlus Authors (goplus.org). 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
22 changes: 22 additions & 0 deletions gopls/internal/lsp/source/hover_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,28 @@ func gopHoverImport(ctx context.Context, snapshot Snapshot, pkg Package, pgf *Pa
break
}
}
if comment == nil {
for _, f := range impMetadata.CompiledGoFiles {
fh, err := snapshot.ReadFile(ctx, f)
if err != nil {
if ctx.Err() != nil {
return protocol.Range{}, nil, ctx.Err()
}
continue
}
pgf, err := snapshot.ParseGo(ctx, fh, ParseHeader)
if err != nil {
if ctx.Err() != nil {
return protocol.Range{}, nil, ctx.Err()
}
continue
}
if pgf.File.Doc != nil {
comment = pgf.File.Doc
break
}
}
}

docText := comment.Text()
return rng, &HoverJSON{
Expand Down
Loading

0 comments on commit 16430d6

Please sign in to comment.