This repository has been archived by the owner on Aug 21, 2022. It is now read-only.
/
symbol_descriptor.go
77 lines (70 loc) · 2.21 KB
/
symbol_descriptor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package langserver
import (
"github.com/sourcegraph/go-lsp"
"github.com/sourcegraph/go-lsp/lspext"
)
// This file contains lspext but redefined to suit go-langserver
// needs. Everything in here should be wire compatible.
// symbolDescriptor is the exact fields go-langserver uses for
// lspext.SymbolDescriptor. It should have the same JSON wire format. We make
// it a struct for both type safety as well as better memory efficiency.
type symbolDescriptor struct {
Package string `json:"package"`
PackageName string `json:"packageName"`
Recv string `json:"recv"`
Name string `json:"name"`
ID string `json:"id"`
Vendor bool `json:"vendor"`
}
// Contains ensures that b is a subset of our symbolDescriptor
func (a *symbolDescriptor) Contains(b lspext.SymbolDescriptor) bool {
for k, v := range b {
switch k {
case "package":
if s, ok := v.(string); !ok || s != a.Package {
return false
}
case "packageName":
if s, ok := v.(string); !ok || s != a.PackageName {
return false
}
case "recv":
if s, ok := v.(string); !ok || s != a.Recv {
return false
}
case "name":
if s, ok := v.(string); !ok || s != a.Name {
return false
}
case "id":
if s, ok := v.(string); !ok || s != a.ID {
return false
}
case "vendor":
if s, ok := v.(bool); !ok || s != a.Vendor {
return false
}
default:
return false
}
}
return true
}
// symbolLocationInformation is lspext.SymbolLocationInformation, but using
// our custom symbolDescriptor
type symbolLocationInformation struct {
// A concrete location at which the definition is located, if any.
Location lsp.Location `json:"location,omitempty"`
// Metadata about the definition.
Symbol *symbolDescriptor `json:"symbol"`
// the location of a type declaration, if one is available
TypeLocation lsp.Location `json:"-"`
}
// referenceInformation is lspext.ReferenceInformation using our custom symbolDescriptor
type referenceInformation struct {
// Reference is the location in the workspace where the `symbol` has been
// referenced.
Reference lsp.Location `json:"reference"`
// Symbol is metadata information describing the symbol being referenced.
Symbol *symbolDescriptor `json:"symbol"`
}