Skip to content

Commit

Permalink
cmd/govim: add Hover function to give equivalent string to balloonexpr (
Browse files Browse the repository at this point in the history
  • Loading branch information
myitcv committed Apr 15, 2019
1 parent 27f38b5 commit 602decf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/govim/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
FunctionBalloonExpr Function = "BalloonExpr"
FunctionComplete Function = "Complete"
FunctionHello Function = "Hello"
FunctionHover Function = "Hover"
)

type FormatOnSave string
Expand Down
21 changes: 21 additions & 0 deletions cmd/govim/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,24 @@ func (v *vimstate) loadLocation(loc protocol.Location) error {

return nil
}

func (v *vimstate) hover(args ...json.RawMessage) (interface{}, error) {
b, pos, err := v.cursorPos()
if err != nil {
return nil, fmt.Errorf("failed to get current position: %v", err)
}
params := &protocol.TextDocumentPositionParams{
TextDocument: protocol.TextDocumentIdentifier{
URI: string(b.URI()),
},
Position: pos.ToPosition(),
}
res, err := v.server.Hover(context.Background(), params)
if err != nil {
return nil, fmt.Errorf("failed to get hover details: %v", err)
}
md := []byte(res.Contents.Value)
plain := string(blackfriday.Run(md, blackfriday.WithRenderer(plainMarkdown{})))
plain = strings.TrimSpace(plain)
return plain, nil
}
1 change: 1 addition & 0 deletions cmd/govim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (g *govimplugin) Init(gg govim.Govim, errCh chan error) error {
g.DefineFunction(string(config.FunctionComplete), []string{"findarg", "base"}, g.complete)
g.DefineCommand(string(config.CommandGoToDef), g.gotoDef, govim.NArgsZeroOrOne)
g.DefineCommand(string(config.CommandGoToPrevDef), g.gotoPrevDef, govim.NArgsZeroOrOne, govim.CountN(1))
g.DefineFunction(string(config.FunctionHover), []string{}, g.hover)

g.isGui = g.ParseInt(g.ChannelExpr(`has("gui_running")`)) == 1

Expand Down
19 changes: 19 additions & 0 deletions cmd/govim/testdata/function_hover.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Test that basic functions work

vim ex 'e main.go'
vim ex 'call cursor(6,6)'
vim expr 'GOVIMHover()'
stdout '^\Q"func fmt.Println(a ...interface{}) (n int, err error)"\E$'
! stderr .+

-- go.mod --
module mod.com

-- main.go --
package main

import "fmt"

func main() {
fmt.Println("Hello, world")
}

0 comments on commit 602decf

Please sign in to comment.