| 1 |
package lspext |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"sort" |
| 6 |
"strings" |
| 7 |
|
| 8 |
"github.com/sourcegraph/go-lsp" |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
type WorkspaceSymbolParams struct { |
| 13 |
Query string `json:"query,omitempty"` |
| 14 |
Limit int `json:"limit"` |
| 15 |
Symbol SymbolDescriptor `json:"symbol,omitempty"` |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
type WorkspaceReferencesParams struct { |
| 23 |
|
| 24 |
Query SymbolDescriptor `json:"query"` |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
Hints map[string]interface{} `json:"hints,omitempty"` |
| 30 |
|
| 31 |
|
| 32 |
Limit int `json:"limit,omitempty"` |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
type ReferenceInformation struct { |
| 38 |
|
| 39 |
|
| 40 |
Reference lsp.Location `json:"reference"` |
| 41 |
|
| 42 |
|
| 43 |
Symbol SymbolDescriptor `json:"symbol"` |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
type SymbolDescriptor map[string]interface{} |
| 53 |
|
| 54 |
|
| 55 |
type SymbolLocationInformation struct { |
| 56 |
|
| 57 |
Location lsp.Location `json:"location,omitempty"` |
| 58 |
|
| 59 |
Symbol SymbolDescriptor `json:"symbol"` |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
func (s SymbolDescriptor) Contains(other SymbolDescriptor) bool { |
| 65 |
for k, v := range other { |
| 66 |
v2, ok := s[k] |
| 67 |
if !ok || v != v2 { |
| 68 |
return false |
| 69 |
} |
| 70 |
} |
| 71 |
return true |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
func (s SymbolDescriptor) String() string { |
| 77 |
sm := make(sortedMap, 0, len(s)) |
| 78 |
for k, v := range s { |
| 79 |
sm = append(sm, mapValue{key: k, value: v}) |
| 80 |
} |
| 81 |
sort.Sort(sm) |
| 82 |
var str string |
| 83 |
for _, v := range sm { |
| 84 |
str += fmt.Sprintf("%s:%v ", v.key, v.value) |
| 85 |
} |
| 86 |
return strings.TrimSpace(str) |
| 87 |
} |
| 88 |
|
| 89 |
type mapValue struct { |
| 90 |
key string |
| 91 |
value interface{} |
| 92 |
} |
| 93 |
|
| 94 |
type sortedMap []mapValue |
| 95 |
|
| 96 |
func (s sortedMap) Len() int { return len(s) } |
| 97 |
func (s sortedMap) Less(i, j int) bool { return s[i].key < s[j].key } |
| 98 |
func (s sortedMap) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |