ollie/tools/lsp/cmd/lsp_references/main.go

35 lines
805 B
Go

// lsp_references — Find all references to symbol at position.
package main
import (
"encoding/json"
"fmt"
"ollie/tools/lsp/internal/lsp"
"ollie/tools/lsp/internal/cmdutil"
)
func main() {
cmdutil.Run("references", func(result json.RawMessage) {
var locations []struct {
URI string `json:"uri"`
Range struct {
Start struct {
Line int `json:"line"`
Character int `json:"character"`
} `json:"start"`
} `json:"range"`
}
if err := json.Unmarshal(result, &locations); err != nil {
fmt.Println("(no references found)")
return
}
fmt.Printf("STATUS=ok MATCH_COUNT=%d\n", len(locations))
for _, loc := range locations {
path := lsp.URIToPath(loc.URI)
fmt.Printf("%s:%d:%d\n", path, loc.Range.Start.Line+1, loc.Range.Start.Character+1)
}
})
}