-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat(spxls): add support for retrieving package documentation in hover #1373
base: dev
Are you sure you want to change the base?
Changes from all commits
8f32549
64354ff
8a3e440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 哦对了,可能需要补个单测,往 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package server | ||
|
||
import "strings" | ||
import ( | ||
"go/doc" | ||
"strings" | ||
) | ||
|
||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification#textDocument_hover | ||
func (s *Server) textDocumentHover(params *HoverParams) (*Hover, error) { | ||
|
@@ -22,6 +25,19 @@ func (s *Server) textDocumentHover(params *HoverParams) (*Hover, error) { | |
}, nil | ||
} | ||
|
||
// Check if the position is within an import declaration. | ||
// If so, return the package documentation. | ||
rpkg := result.spxImportsAtASTFilePosition(astFile, params.Position) | ||
if rpkg != nil { | ||
return &Hover{ | ||
Contents: MarkupContent{ | ||
Kind: Markdown, | ||
Value: doc.Synopsis(rpkg.Pkg.Doc), | ||
}, | ||
Range: result.rangeForNode(rpkg.Node), | ||
}, nil | ||
} | ||
|
||
ident := result.identAtASTFilePosition(astFile, params.Position) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其实我倾向于认为这种对于在 当然不排除 go 那边的处理方式也是类似的,如果是那样就不算 go+ 的 bug 了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我最早也是考虑在 typesutil 里面处理,typestuil 里有一个 Implicits,ast.ImportSpec 在这个字段中,不过 ImportSpec 具体的pkg 是一个BasicLit 不是 ident,所以就没在这里处理, 看了 gopls 也是单独分支处理,所以就单独放出来 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的。不过感觉这个逻辑是不是可以放进 |
||
if ident == nil { | ||
return nil, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/goplus/builder/tools/spxls/internal/pkgdoc" | ||
gopast "github.com/goplus/gop/ast" | ||
) | ||
|
||
// SpxReferencePkg is a reference to an imported package. | ||
type SpxReferencePkg struct { | ||
PkgPath string | ||
Pkg *pkgdoc.PkgDoc | ||
Node *gopast.ImportSpec | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
话说这里是不是就该
return
了?感觉没必要再继续遍历下去了