Debian Codegraph @

lspext/lspext.go

raw symbols SCIP
1 package lspext
2
3 import (
4 "fmt"
5 "sort"
6 "strings"
7
8 "github.com/sourcegraph/go-lsp"
9 )
10
11 // WorkspaceSymbolParams is the extension workspace/symbol parameter type.
12 type WorkspaceSymbolParams struct {
13 Query string `json:"query,omitempty"`
14 Limit int `json:"limit"`
15 Symbol SymbolDescriptor `json:"symbol,omitempty"`
16 }
17
18 // WorkspaceReferencesParams is parameters for the `workspace/xreferences` extension
19 //
20 // See: https://github.com/sourcegraph/language-server-protocol/blob/master/extension-workspace-reference.md
21 //
22 type WorkspaceReferencesParams struct {
23 // Query represents metadata about the symbol that is being searched for.
24 Query SymbolDescriptor `json:"query"`
25
26 // Hints provides optional hints about where the language server should
27 // look in order to find the symbol (this is an optimization). It is up to
28 // the language server to define the schema of this object.
29 Hints map[string]interface{} `json:"hints,omitempty"`
30
31 // Limit if positive will limit the number of results returned.
32 Limit int `json:"limit,omitempty"`
33 }
34
35 // ReferenceInformation represents information about a reference to programming
36 // constructs like variables, classes, interfaces etc.
37 type ReferenceInformation struct {
38 // Reference is the location in the workspace where the `symbol` has been
39 // referenced.
40 Reference lsp.Location `json:"reference"`
41
42 // Symbol is metadata information describing the symbol being referenced.
43 Symbol SymbolDescriptor `json:"symbol"`
44 }
45
46 // SymbolDescriptor represents information about a programming construct like a
47 // variable, class, interface, etc that has a reference to it. It is up to the
48 // language server to define the schema of this object.
49 //
50 // SymbolDescriptor usually uniquely identifies a symbol, but it is not
51 // guaranteed to do so.
52 type SymbolDescriptor map[string]interface{}
53
54 // SymbolLocationInformation is the response type for the `textDocument/xdefinition` extension.
55 type SymbolLocationInformation struct {
56 // A concrete location at which the definition is located, if any.
57 Location lsp.Location `json:"location,omitempty"`
58 // Metadata about the definition.
59 Symbol SymbolDescriptor `json:"symbol"`
60 }
61
62 // Contains tells if this SymbolDescriptor fully contains all of the keys and
63 // values in the other symbol descriptor.
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 // String returns a consistently ordered string representation of the
75 // SymbolDescriptor. It is useful for testing.
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] }