1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/tools/internal/lsp/protocol"
26 func main() { // function
30 var myvar int // variable
32 type myType string // basic type
34 type myDecoder json.Decoder // to use the encoding/json import
36 func (m *myType) Blahblah() {} // method
38 type myStruct struct { // struct type
39 myStructField int // struct field
42 type myInterface interface { // interface
43 DoSomeCoolStuff() string // interface method
52 nestedStruct2 struct {
57 nestedInterface interface {
65 const Message = "Hello World." // constant
68 var caseSensitiveSymbolChecks = map[string]*expSymbolInformation{
70 Name: pString("main.main"),
71 Kind: pKind(protocol.Function),
72 Location: &expLocation{
73 Path: pString("main.go"),
83 Name: pString("p.Message"),
84 Kind: pKind(protocol.Constant),
85 Location: &expLocation{
86 Path: pString("p/p.go"),
96 Name: pString("main.myvar"),
97 Kind: pKind(protocol.Variable),
98 Location: &expLocation{
99 Path: pString("main.go"),
109 Name: pString("main.myType"),
110 Kind: pKind(protocol.String),
111 Location: &expLocation{
112 Path: pString("main.go"),
122 Name: pString("main.myType.Blahblah"),
123 Kind: pKind(protocol.Method),
124 Location: &expLocation{
125 Path: pString("main.go"),
135 Name: pString("json.NewEncoder"),
136 Kind: pKind(protocol.Function),
139 Name: pString("main.myStruct"),
140 Kind: pKind(protocol.Struct),
141 Location: &expLocation{
142 Path: pString("main.go"),
151 // TODO: not sure we should be returning struct fields
153 Name: pString("main.myStruct.myStructField"),
154 Kind: pKind(protocol.Field),
155 Location: &expLocation{
156 Path: pString("main.go"),
166 Name: pString("main.myInterface"),
167 Kind: pKind(protocol.Interface),
168 Location: &expLocation{
169 Path: pString("main.go"),
178 // TODO: not sure we should be returning interface methods
180 Name: pString("main.myInterface.DoSomeCoolStuff"),
181 Kind: pKind(protocol.Method),
182 Location: &expLocation{
183 Path: pString("main.go"),
194 Name: pString("main.embed.myStruct"),
195 Kind: pKind(protocol.Field),
196 Location: &expLocation{
197 Path: pString("main.go"),
207 "nestedStruct2.int": {
208 Name: pString("main.embed.nestedStruct.nestedStruct2.int"),
209 Kind: pKind(protocol.Field),
210 Location: &expLocation{
211 Path: pString("main.go"),
221 "nestedInterface.myInterface": {
222 Name: pString("main.embed.nestedInterface.myInterface"),
223 Kind: pKind(protocol.Interface),
224 Location: &expLocation{
225 Path: pString("main.go"),
235 "nestedInterface.nestedMethod": {
236 Name: pString("main.embed.nestedInterface.nestedMethod"),
237 Kind: pKind(protocol.Method),
238 Location: &expLocation{
239 Path: pString("main.go"),
250 var caseInsensitiveSymbolChecks = map[string]*expSymbolInformation{
251 "Main": caseSensitiveSymbolChecks["main"],
254 var fuzzySymbolChecks = map[string]*expSymbolInformation{
255 "Mn": caseSensitiveSymbolChecks["main"],
258 // TestSymbolPos tests that, at a basic level, we get the correct position
259 // information for symbols matches that are returned.
260 func TestSymbolPos(t *testing.T) {
261 checkChecks(t, "caseSensitive", caseSensitiveSymbolChecks)
262 checkChecks(t, "caseInsensitive", caseInsensitiveSymbolChecks)
263 checkChecks(t, "fuzzy", fuzzySymbolChecks)
266 func checkChecks(t *testing.T, matcher string, checks map[string]*expSymbolInformation) {
269 EditorConfig{SymbolMatcher: &matcher},
270 ).run(t, symbolSetup, func(t *testing.T, env *Env) {
271 t.Run(matcher, func(t *testing.T) {
272 for query, exp := range checks {
273 t.Run(query, func(t *testing.T) {
274 res := env.Symbol(query)
275 if !exp.matchAgainst(res) {
276 t.Fatalf("failed to find a match against query %q for %v,\ngot: %v", query, exp, res)