forked from sourcegraph/go-langserver
/
partial.go
50 lines (41 loc) · 1.53 KB
/
partial.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
package langserver
import "github.com/sourcegraph/go-langserver/pkg/lsp"
// This file contains types and functions related to $/partialResult streaming
// RewriteURIer is a type that implements RewriteURI. The typical use of
// RewriteURI is a build server which translates workspace URIs into URIs for
// other systems to consume.
type RewriteURIer interface {
// RewriteURI will update all URIs in the type using the rewrite
// function.
RewriteURI(rewrite func(lsp.DocumentURI) lsp.DocumentURI)
}
// referenceAddOp is a JSON Patch operation used by
// textDocument/references. The only other patch operation is to create the
// empty location list.
type referenceAddOp struct {
// OP should always be "add"
OP string `json:"op"`
Path string `json:"path"`
Value lsp.Location `json:"value"`
}
type referencePatch []referenceAddOp
func (p referencePatch) RewriteURI(rewrite func(lsp.DocumentURI) lsp.DocumentURI) {
for i := range p {
p[i].Value.URI = rewrite(p[i].Value.URI)
}
}
// xreferenceAddOp is a JSON Patch operation used by
// workspace/xreferences. The only other patch operation is to create the
// empty location list.
type xreferenceAddOp struct {
// OP should always be "add"
OP string `json:"op"`
Path string `json:"path"`
Value referenceInformation `json:"value"`
}
type xreferencePatch []xreferenceAddOp
func (p xreferencePatch) RewriteURI(rewrite func(lsp.DocumentURI) lsp.DocumentURI) {
for i := range p {
p[i].Value.Reference.URI = rewrite(p[i].Value.Reference.URI)
}
}