mirror of
https://github.com/golang/go
synced 2024-11-19 03:14:42 -07:00
0bd3dbed90
In preparation for later changes to the implementation of the workspace Symbol method, we add the Symbol method to fake.Editor. This requires the definition of a number of associated fake types (editor-friendly, byte-offset-based versions of protocol UTF16-based types) for example fake.SymbolInformation and the types it references. We also implement a basic regtest for the Symbol method, exposing Symbol on regtest.Env like other LSP server methods. To aid with the writing of Symbol result assertions, we provide some helper functions to simplify the process of defining matches that are evaluated against the result set. Change-Id: If73b493e1e791c8201423a303af8041f5a15ccfc Reviewed-on: https://go-review.googlesource.com/c/tools/+/228121 Run-TryBot: Paul Jolly <paul@myitcv.org.uk> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
// 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 (
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/fake"
|
|
)
|
|
|
|
const symbolSetup = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
go 1.12
|
|
-- main.go --
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Println(Message)
|
|
}
|
|
-- const.go --
|
|
package main
|
|
|
|
const Message = "Hello World."
|
|
`
|
|
|
|
// TestSymbolPos tests that, at a basic level, we get the correct position
|
|
// information for symbols matches that are returned.
|
|
func TestSymbolPos(t *testing.T) {
|
|
matcher := "caseSensitive"
|
|
opts := []RunOption{
|
|
WithEditorConfig(fake.EditorConfig{SymbolMatcher: &matcher}),
|
|
}
|
|
|
|
runner.Run(t, symbolSetup, func(t *testing.T, env *Env) {
|
|
res := env.Symbol("main")
|
|
exp := &expSymbolInformation{
|
|
Name: pString("main"),
|
|
Location: &expLocation{
|
|
Path: pString("main.go"),
|
|
Range: &expRange{
|
|
Start: &expPos{
|
|
Line: pInt(4),
|
|
Column: pInt(5),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
if !exp.matchAgainst(res) {
|
|
t.Fatalf("failed to find match for main function")
|
|
}
|
|
}, opts...)
|
|
}
|