Switch to pkg.nimblebun.works/go-lsp for LSP types.

This commit is contained in:
Qi Xiao 2023-04-23 00:19:26 +01:00
parent 1974b30eb6
commit 6c5d24ad81
4 changed files with 25 additions and 37 deletions

3
go.mod
View File

@ -4,10 +4,11 @@ require (
github.com/creack/pty v1.1.15
github.com/google/go-cmp v0.5.9
github.com/mattn/go-isatty v0.0.17
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d
github.com/sourcegraph/jsonrpc2 v0.2.0
go.etcd.io/bbolt v1.3.7
golang.org/x/sys v0.5.0
)
require pkg.nimblebun.works/go-lsp v1.1.0
go 1.19

4
go.sum
View File

@ -8,8 +8,6 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d h1:afLbh+ltiygTOB37ymZVwKlJwWZn+86syPTbrrOAydY=
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d/go.mod h1:SULmZY7YNBsvNiQbrb/BEDdEJ84TGnfyUQxaHt8t8rY=
github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U=
github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
@ -19,3 +17,5 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
pkg.nimblebun.works/go-lsp v1.1.0 h1:TH5ro4p2vlDtELK4LoVeKs4TsKm6aW1f5WP8jHm/9m4=
pkg.nimblebun.works/go-lsp v1.1.0/go.mod h1:Suh759Ki+DjU0zwf0xkl1H6Ln1C6/+GtYyNofbtfcug=

View File

@ -10,8 +10,8 @@ import (
"time"
"github.com/google/go-cmp/cmp"
lsp "github.com/sourcegraph/go-lsp"
"github.com/sourcegraph/jsonrpc2"
lsp "pkg.nimblebun.works/go-lsp"
"src.elv.sh/pkg/mods/doc"
"src.elv.sh/pkg/must"
"src.elv.sh/pkg/prog"
@ -33,7 +33,7 @@ var diagTests = []struct {
Range: lsp.Range{
Start: lsp.Position{Line: 0, Character: 1},
End: lsp.Position{Line: 0, Character: 2}},
Severity: lsp.Error, Source: "parse", Message: "should be variable name",
Severity: lsp.DSError, Source: "parse", Message: "should be variable name",
},
}},
{"multi line with NL", "\n$!", []lsp.Diagnostic{
@ -41,7 +41,7 @@ var diagTests = []struct {
Range: lsp.Range{
Start: lsp.Position{Line: 1, Character: 1},
End: lsp.Position{Line: 1, Character: 2}},
Severity: lsp.Error, Source: "parse", Message: "should be variable name",
Severity: lsp.DSError, Source: "parse", Message: "should be variable name",
},
}},
{"multi line with CR", "\r$!", []lsp.Diagnostic{
@ -49,7 +49,7 @@ var diagTests = []struct {
Range: lsp.Range{
Start: lsp.Position{Line: 1, Character: 1},
End: lsp.Position{Line: 1, Character: 2}},
Severity: lsp.Error, Source: "parse", Message: "should be variable name",
Severity: lsp.DSError, Source: "parse", Message: "should be variable name",
},
}},
{"multi line with CRNL", "\r\n$!", []lsp.Diagnostic{
@ -57,7 +57,7 @@ var diagTests = []struct {
Range: lsp.Range{
Start: lsp.Position{Line: 1, Character: 1},
End: lsp.Position{Line: 1, Character: 2}},
Severity: lsp.Error, Source: "parse", Message: "should be variable name",
Severity: lsp.DSError, Source: "parse", Message: "should be variable name",
},
}},
{"text with code point beyond FFFF", "\U00010000 $!", []lsp.Diagnostic{
@ -65,7 +65,7 @@ var diagTests = []struct {
Range: lsp.Range{
Start: lsp.Position{Line: 0, Character: 4},
End: lsp.Position{Line: 0, Character: 5}},
Severity: lsp.Error, Source: "parse", Message: "should be variable name",
Severity: lsp.DSError, Source: "parse", Message: "should be variable name",
},
}},
}
@ -98,7 +98,7 @@ var hoverTests = []struct {
text string
pos lsp.Position
wantHover hover
wantHover lsp.Hover
}{
{
name: "command doc",
@ -120,7 +120,7 @@ var hoverTests = []struct {
text: "some-external",
pos: lsp.Position{Line: 0, Character: 0},
wantHover: hover{},
wantHover: lsp.Hover{},
},
{
name: "command at non-command position",
@ -128,12 +128,12 @@ var hoverTests = []struct {
text: "echo echo",
pos: lsp.Position{Line: 0, Character: 6},
wantHover: hover{},
wantHover: lsp.Hover{},
},
}
func hoverWith(markdown string) hover {
return hover{Contents: markupContent{Kind: "markdown", Value: markdown}}
func hoverWith(markdown string) lsp.Hover {
return lsp.Hover{Contents: lsp.MarkupContent{Kind: lsp.MKMarkdown, Value: markdown}}
}
func TestHover(t *testing.T) {
@ -146,7 +146,7 @@ func TestHover(t *testing.T) {
TextDocument: lsp.TextDocumentIdentifier{URI: testURI},
Position: test.pos,
}
var response hover
var response lsp.Hover
err := f.conn.Call(bgCtx, "textDocument/hover", request, &response)
if err != nil {
t.Errorf("got error %v", err)
@ -203,7 +203,7 @@ var jsonrpcErrorTests = []struct {
params any
wantErr error
}{
{"unkown method", "unknown/method", struct{}{}, errMethodNotFound},
{"unknown method", "unknown/method", struct{}{}, errMethodNotFound},
{"invalid request type", "textDocument/didOpen", []int{}, errInvalidParams},
{"unknown document to hover", "textDocument/hover",
lsp.TextDocumentPositionParams{

View File

@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"
lsp "github.com/sourcegraph/go-lsp"
"github.com/sourcegraph/jsonrpc2"
lsp "pkg.nimblebun.works/go-lsp"
"src.elv.sh/pkg/diag"
"src.elv.sh/pkg/edit/complete"
"src.elv.sh/pkg/eval"
@ -89,14 +89,12 @@ func conn(ctx context.Context) *jsonrpc2.Conn { return ctx.Value(connKey{}).(*js
func (s *server) initialize(_ context.Context, _ json.RawMessage) (any, error) {
return &lsp.InitializeResult{
Capabilities: lsp.ServerCapabilities{
TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{
Options: &lsp.TextDocumentSyncOptions{
OpenClose: true,
Change: lsp.TDSKFull,
},
TextDocumentSync: &lsp.TextDocumentSyncOptions{
OpenClose: true,
Change: lsp.TDSyncKindFull,
},
CompletionProvider: &lsp.CompletionOptions{},
HoverProvider: true,
HoverProvider: &lsp.HoverOptions{},
},
}, nil
}
@ -115,17 +113,6 @@ func (s *server) didChange(ctx context.Context, params lsp.DidChangeTextDocument
return nil, nil
}
// TODO: Use a more up-to-date Go package for LSP data types, and avoid defining
// these ourselves.
type hover struct {
Contents markupContent `json:"contents"`
}
type markupContent struct {
Kind string `json:"kind"`
Value string `json:"value"`
}
func (s *server) hover(_ context.Context, params lsp.TextDocumentPositionParams) (any, error) {
document, ok := s.documents[params.TextDocument.URI]
if !ok {
@ -140,7 +127,7 @@ func (s *server) hover(_ context.Context, params lsp.TextDocumentPositionParams)
// TODO: Take shadowing into consideration.
markdown, err := doc.Source("$" + primary.Value)
if err == nil {
return hover{Contents: markupContent{Kind: "markdown", Value: markdown}}, nil
return lsp.Hover{Contents: lsp.MarkupContent{Kind: lsp.MKMarkdown, Value: markdown}}, nil
}
}
// Try command doc
@ -150,7 +137,7 @@ func (s *server) hover(_ context.Context, params lsp.TextDocumentPositionParams)
// TODO: Take shadowing into consideration.
markdown, err := doc.Source(expr.Value)
if err == nil {
return hover{Contents: markupContent{Kind: "markdown", Value: markdown}}, nil
return lsp.Hover{Contents: lsp.MarkupContent{Kind: lsp.MKMarkdown, Value: markdown}}, nil
}
}
return nil, nil
@ -208,7 +195,7 @@ func (s *server) updateDocument(conn *jsonrpc2.Conn, uri lsp.DocumentURI, code s
for i, err := range entries {
diags[i] = lsp.Diagnostic{
Range: lspRangeFromRange(code, err),
Severity: lsp.Error,
Severity: lsp.DSError,
Source: "parse",
Message: err.Message,
}