2020-03-04 11:29:23 -07:00
|
|
|
// Copyright 2020 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 regtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
)
|
|
|
|
|
|
|
|
const simpleProgram = `
|
|
|
|
-- go.mod --
|
2020-04-01 15:14:17 -06:00
|
|
|
module mod.com
|
2020-03-04 11:29:23 -07:00
|
|
|
|
|
|
|
go 1.12
|
|
|
|
-- main.go --
|
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println("Hello World.")
|
|
|
|
}`
|
|
|
|
|
|
|
|
func TestHoverSerialization(t *testing.T) {
|
2020-04-14 11:40:37 -06:00
|
|
|
runner.Run(t, simpleProgram, func(t *testing.T, env *Env) {
|
2020-03-04 11:29:23 -07:00
|
|
|
// Hover on an empty line.
|
|
|
|
params := protocol.HoverParams{}
|
2020-04-28 22:00:52 -06:00
|
|
|
params.TextDocument.URI = env.Sandbox.Workdir.URI("main.go")
|
2020-03-04 11:29:23 -07:00
|
|
|
params.Position.Line = 3
|
|
|
|
params.Position.Character = 0
|
|
|
|
var resp json.RawMessage
|
2020-04-07 19:35:47 -06:00
|
|
|
if err := protocol.Call(env.Ctx, env.Conn, "textDocument/hover", ¶ms, &resp); err != nil {
|
2020-03-04 11:29:23 -07:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(string(resp)) > 0 {
|
|
|
|
t.Errorf("got non-empty response for empty hover: %v", string(resp))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|