mirror of
https://github.com/golang/go
synced 2024-11-18 15:04:44 -07:00
x/tools/gopls: convert to the august, 2019 version of the LSP protocol
The latest version of the LSP protocol introduces a number of changes. It is now possible to indicate partial results and progress. request.ts had to construct some new types (at the end of tsclient.go and tsserver,go) to avoid using a struct for a formal parameter type. Also, instead of using the same type for many RPCs, most RPCs now have their own types. Change-Id: I095a3e872f42a9f851c01ca4e3c6ac6e32446042 Reviewed-on: https://go-review.googlesource.com/c/tools/+/194177 Run-TryBot: Peter Weinberger <pjw@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
4c50eace5a
commit
fef9eaa9e4
@ -194,7 +194,7 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
|
||||
}
|
||||
|
||||
func (c *connection) initialize(ctx context.Context) error {
|
||||
params := &protocol.InitializeParams{}
|
||||
params := &protocol.ParamInitia{}
|
||||
params.RootURI = string(span.FileURI(c.Client.app.wd))
|
||||
params.Capabilities.Workspace.Configuration = true
|
||||
params.Capabilities.TextDocument.Hover.ContentFormat = []protocol.MarkupKind{protocol.PlainText}
|
||||
@ -283,7 +283,7 @@ func (c *cmdClient) WorkspaceFolders(ctx context.Context) ([]protocol.WorkspaceF
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ConfigurationParams) ([]interface{}, error) {
|
||||
func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ParamConfig) ([]interface{}, error) {
|
||||
results := make([]interface{}, len(p.Items))
|
||||
for i, item := range p.Items {
|
||||
if item.Section != "gopls" {
|
||||
|
@ -74,10 +74,15 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p := protocol.TextDocumentPositionParams{
|
||||
tdpp := protocol.TextDocumentPositionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
|
||||
Position: loc.Range.Start,
|
||||
}
|
||||
p := protocol.DefinitionParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
protocol.PartialResultParams{},
|
||||
}
|
||||
locs, err := conn.Definition(ctx, &p)
|
||||
if err != nil {
|
||||
return errors.Errorf("%v: %v", from, err)
|
||||
@ -86,7 +91,11 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
|
||||
if len(locs) == 0 {
|
||||
return errors.Errorf("%v: not an identifier", from)
|
||||
}
|
||||
hover, err := conn.Hover(ctx, &p)
|
||||
q := protocol.HoverParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
}
|
||||
hover, err := conn.Hover(ctx, &q)
|
||||
if err != nil {
|
||||
return errors.Errorf("%v: %v", from, err)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
func (s *Server) definition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) {
|
||||
func (s *Server) definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
f, err := getGoFile(ctx, view, uri)
|
||||
@ -35,7 +35,7 @@ func (s *Server) definition(ctx context.Context, params *protocol.TextDocumentPo
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) typeDefinition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) {
|
||||
func (s *Server) typeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) ([]protocol.Location, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
f, err := getGoFile(ctx, view, uri)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
errors "golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func (s *Server) initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) {
|
||||
func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitia) (*protocol.InitializeResult, error) {
|
||||
s.stateMu.Lock()
|
||||
state := s.state
|
||||
s.stateMu.Unlock()
|
||||
@ -82,7 +82,8 @@ func (s *Server) initialize(ctx context.Context, params *protocol.InitializePara
|
||||
}
|
||||
|
||||
var codeActionProvider interface{}
|
||||
if len(params.Capabilities.TextDocument.CodeAction.CodeActionLiteralSupport.CodeActionKind.ValueSet) > 0 {
|
||||
if params.Capabilities.TextDocument.CodeAction.CodeActionLiteralSupport != nil &&
|
||||
len(params.Capabilities.TextDocument.CodeAction.CodeActionLiteralSupport.CodeActionKind.ValueSet) > 0 {
|
||||
// If the client has specified CodeActionLiteralSupport,
|
||||
// send the code actions we support.
|
||||
//
|
||||
@ -148,7 +149,8 @@ func (s *Server) initialize(ctx context.Context, params *protocol.InitializePara
|
||||
func (s *Server) setClientCapabilities(o *source.SessionOptions, caps protocol.ClientCapabilities) {
|
||||
// Check if the client supports snippets in completion items.
|
||||
o.InsertTextFormat = protocol.PlainTextTextFormat
|
||||
if caps.TextDocument.Completion.CompletionItem.SnippetSupport {
|
||||
if caps.TextDocument.Completion.CompletionItem != nil &&
|
||||
caps.TextDocument.Completion.CompletionItem.SnippetSupport {
|
||||
o.InsertTextFormat = protocol.SnippetTextFormat
|
||||
}
|
||||
// Check if the client supports configuration messages.
|
||||
@ -220,16 +222,19 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
|
||||
}
|
||||
|
||||
func (s *Server) fetchConfig(ctx context.Context, view source.View, options *source.SessionOptions) error {
|
||||
configs, err := s.client.Configuration(ctx, &protocol.ConfigurationParams{
|
||||
Items: []protocol.ConfigurationItem{{
|
||||
ScopeURI: protocol.NewURI(view.Folder()),
|
||||
Section: "gopls",
|
||||
}, {
|
||||
ScopeURI: protocol.NewURI(view.Folder()),
|
||||
Section: view.Name(),
|
||||
},
|
||||
},
|
||||
})
|
||||
v := protocol.ParamConfig{
|
||||
protocol.ConfigurationParams{
|
||||
Items: []protocol.ConfigurationItem{{
|
||||
ScopeURI: protocol.NewURI(view.Folder()),
|
||||
Section: "gopls",
|
||||
}, {
|
||||
ScopeURI: protocol.NewURI(view.Folder()),
|
||||
Section: view.Name(),
|
||||
},
|
||||
},
|
||||
}, protocol.PartialResultParams{},
|
||||
}
|
||||
configs, err := s.client.Configuration(ctx, &v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"golang.org/x/tools/internal/telemetry/log"
|
||||
)
|
||||
|
||||
func (s *Server) documentHighlight(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.DocumentHighlight, error) {
|
||||
func (s *Server) documentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
rngs, err := source.Highlight(ctx, view, uri, params.Position)
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
"golang.org/x/tools/internal/telemetry/log"
|
||||
)
|
||||
|
||||
func (s *Server) hover(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.Hover, error) {
|
||||
func (s *Server) hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
f, err := getGoFile(ctx, view, uri)
|
||||
|
@ -501,20 +501,34 @@ func (r *runner) Definition(t *testing.T, data tests.Definitions) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %v", d.Src, err)
|
||||
}
|
||||
params := &protocol.TextDocumentPositionParams{
|
||||
tdpp := protocol.TextDocumentPositionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
|
||||
Position: loc.Range.Start,
|
||||
}
|
||||
var locs []protocol.Location
|
||||
var hover *protocol.Hover
|
||||
if d.IsType {
|
||||
params := &protocol.TypeDefinitionParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
protocol.PartialResultParams{},
|
||||
}
|
||||
locs, err = r.server.TypeDefinition(r.ctx, params)
|
||||
} else {
|
||||
params := &protocol.DefinitionParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
protocol.PartialResultParams{},
|
||||
}
|
||||
locs, err = r.server.Definition(r.ctx, params)
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %+v", d.Src, err)
|
||||
}
|
||||
hover, err = r.server.Hover(r.ctx, params)
|
||||
v := &protocol.HoverParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
}
|
||||
hover, err = r.server.Hover(r.ctx, v)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %v", d.Src, err)
|
||||
@ -557,10 +571,15 @@ func (r *runner) Highlight(t *testing.T, data tests.Highlights) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %v", locations[0], err)
|
||||
}
|
||||
params := &protocol.TextDocumentPositionParams{
|
||||
tdpp := protocol.TextDocumentPositionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
|
||||
Position: loc.Range.Start,
|
||||
}
|
||||
params := &protocol.DocumentHighlightParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
protocol.PartialResultParams{},
|
||||
}
|
||||
highlights, err := r.server.DocumentHighlight(r.ctx, params)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -700,10 +719,14 @@ func (r *runner) PrepareRename(t *testing.T, data tests.PrepareRenames) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %v", src, err)
|
||||
}
|
||||
params := &protocol.TextDocumentPositionParams{
|
||||
tdpp := protocol.TextDocumentPositionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
|
||||
Position: loc.Range.Start,
|
||||
}
|
||||
params := &protocol.PrepareRenameParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
}
|
||||
got, err := r.server.PrepareRename(context.Background(), params)
|
||||
if err != nil {
|
||||
t.Errorf("prepare rename failed for %v: got error: %v", src, err)
|
||||
@ -811,12 +834,17 @@ func (r *runner) SignatureHelp(t *testing.T, data tests.Signatures) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed for %v: %v", loc, err)
|
||||
}
|
||||
gotSignatures, err := r.server.SignatureHelp(r.ctx, &protocol.TextDocumentPositionParams{
|
||||
tdpp := protocol.TextDocumentPositionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{
|
||||
URI: protocol.NewURI(spn.URI()),
|
||||
},
|
||||
Position: loc.Range.Start,
|
||||
})
|
||||
}
|
||||
params := &protocol.SignatureHelpParams{
|
||||
tdpp,
|
||||
protocol.WorkDoneProgressParams{},
|
||||
}
|
||||
gotSignatures, err := r.server.SignatureHelp(r.ctx, params)
|
||||
if err != nil {
|
||||
// Only fail if we got an error we did not expect.
|
||||
if expectedSignatures != nil {
|
||||
|
@ -16,7 +16,7 @@ type Client interface {
|
||||
Event(context.Context, *interface{}) error
|
||||
PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error
|
||||
WorkspaceFolders(context.Context) ([]WorkspaceFolder, error)
|
||||
Configuration(context.Context, *ConfigurationParams) ([]interface{}, error)
|
||||
Configuration(context.Context, *ParamConfig) ([]interface{}, error)
|
||||
RegisterCapability(context.Context, *RegistrationParams) error
|
||||
UnregisterCapability(context.Context, *UnregistrationParams) error
|
||||
ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem, error)
|
||||
@ -87,7 +87,7 @@ func (h clientHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "workspace/configuration": // req
|
||||
var params ConfigurationParams
|
||||
var params ParamConfig
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -174,7 +174,7 @@ func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFol
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *clientDispatcher) Configuration(ctx context.Context, params *ConfigurationParams) ([]interface{}, error) {
|
||||
func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfig) ([]interface{}, error) {
|
||||
var result []interface{}
|
||||
if err := s.Conn.Call(ctx, "workspace/configuration", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -205,3 +205,9 @@ func (s *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspace
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// Types constructed to avoid structs as formal argument types
|
||||
type ParamConfig struct {
|
||||
ConfigurationParams
|
||||
PartialResultParams
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,35 +21,36 @@ type Server interface {
|
||||
DidSave(context.Context, *DidSaveTextDocumentParams) error
|
||||
WillSave(context.Context, *WillSaveTextDocumentParams) error
|
||||
DidChangeWatchedFiles(context.Context, *DidChangeWatchedFilesParams) error
|
||||
Progress(context.Context, *ProgressParams) error
|
||||
SetTraceNotification(context.Context, *SetTraceParams) error
|
||||
LogTraceNotification(context.Context, *LogTraceParams) error
|
||||
Implementation(context.Context, *TextDocumentPositionParams) ([]Location, error)
|
||||
TypeDefinition(context.Context, *TextDocumentPositionParams) ([]Location, error)
|
||||
Implementation(context.Context, *ImplementationParams) ([]Location, error)
|
||||
TypeDefinition(context.Context, *TypeDefinitionParams) ([]Location, error)
|
||||
DocumentColor(context.Context, *DocumentColorParams) ([]ColorInformation, error)
|
||||
ColorPresentation(context.Context, *ColorPresentationParams) ([]ColorPresentation, error)
|
||||
FoldingRange(context.Context, *FoldingRangeParams) ([]FoldingRange, error)
|
||||
Declaration(context.Context, *TextDocumentPositionParams) ([]DeclarationLink, error)
|
||||
Declaration(context.Context, *DeclarationParams) ([]DeclarationLink, error)
|
||||
SelectionRange(context.Context, *SelectionRangeParams) ([]SelectionRange, error)
|
||||
Initialize(context.Context, *InitializeParams) (*InitializeResult, error)
|
||||
Initialize(context.Context, *ParamInitia) (*InitializeResult, error)
|
||||
Shutdown(context.Context) error
|
||||
WillSaveWaitUntil(context.Context, *WillSaveTextDocumentParams) ([]TextEdit, error)
|
||||
Completion(context.Context, *CompletionParams) (*CompletionList, error)
|
||||
Resolve(context.Context, *CompletionItem) (*CompletionItem, error)
|
||||
Hover(context.Context, *TextDocumentPositionParams) (*Hover, error)
|
||||
SignatureHelp(context.Context, *TextDocumentPositionParams) (*SignatureHelp, error)
|
||||
Definition(context.Context, *TextDocumentPositionParams) ([]Location, error)
|
||||
Hover(context.Context, *HoverParams) (*Hover, error)
|
||||
SignatureHelp(context.Context, *SignatureHelpParams) (*SignatureHelp, error)
|
||||
Definition(context.Context, *DefinitionParams) ([]Location, error)
|
||||
References(context.Context, *ReferenceParams) ([]Location, error)
|
||||
DocumentHighlight(context.Context, *TextDocumentPositionParams) ([]DocumentHighlight, error)
|
||||
DocumentHighlight(context.Context, *DocumentHighlightParams) ([]DocumentHighlight, error)
|
||||
DocumentSymbol(context.Context, *DocumentSymbolParams) ([]DocumentSymbol, error)
|
||||
Symbol(context.Context, *WorkspaceSymbolParams) ([]SymbolInformation, error)
|
||||
CodeAction(context.Context, *CodeActionParams) ([]CodeAction, error)
|
||||
Symbol(context.Context, *WorkspaceSymbolParams) ([]SymbolInformation, error)
|
||||
CodeLens(context.Context, *CodeLensParams) ([]CodeLens, error)
|
||||
ResolveCodeLens(context.Context, *CodeLens) (*CodeLens, error)
|
||||
Formatting(context.Context, *DocumentFormattingParams) ([]TextEdit, error)
|
||||
RangeFormatting(context.Context, *DocumentRangeFormattingParams) ([]TextEdit, error)
|
||||
OnTypeFormatting(context.Context, *DocumentOnTypeFormattingParams) ([]TextEdit, error)
|
||||
Rename(context.Context, *RenameParams) (*WorkspaceEdit, error)
|
||||
PrepareRename(context.Context, *TextDocumentPositionParams) (*Range, error)
|
||||
PrepareRename(context.Context, *PrepareRenameParams) (*Range, error)
|
||||
DocumentLink(context.Context, *DocumentLinkParams) ([]DocumentLink, error)
|
||||
ResolveDocumentLink(context.Context, *DocumentLink) (*DocumentLink, error)
|
||||
ExecuteCommand(context.Context, *ExecuteCommandParams) (interface{}, error)
|
||||
@ -163,6 +164,16 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "$/progress": // notif
|
||||
var params ProgressParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
}
|
||||
if err := h.server.Progress(ctx, ¶ms); err != nil {
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "$/setTraceNotification": // notif
|
||||
var params SetTraceParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
@ -184,7 +195,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/implementation": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params ImplementationParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -195,7 +206,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/typeDefinition": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params TypeDefinitionParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -239,7 +250,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/declaration": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params DeclarationParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -261,7 +272,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "initialize": // req
|
||||
var params InitializeParams
|
||||
var params ParamInitia
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -315,7 +326,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/hover": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params HoverParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -326,7 +337,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/signatureHelp": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params SignatureHelpParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -337,7 +348,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/definition": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params DefinitionParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -359,7 +370,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/documentHighlight": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params DocumentHighlightParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -380,17 +391,6 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "workspace/symbol": // req
|
||||
var params WorkspaceSymbolParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
}
|
||||
resp, err := h.server.Symbol(ctx, ¶ms)
|
||||
if err := r.Reply(ctx, resp, err); err != nil {
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "textDocument/codeAction": // req
|
||||
var params CodeActionParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
@ -402,6 +402,17 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "workspace/symbol": // req
|
||||
var params WorkspaceSymbolParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
}
|
||||
resp, err := h.server.Symbol(ctx, ¶ms)
|
||||
if err := r.Reply(ctx, resp, err); err != nil {
|
||||
log.Error(ctx, "", err)
|
||||
}
|
||||
return true
|
||||
case "textDocument/codeLens": // req
|
||||
var params CodeLensParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
@ -469,7 +480,7 @@ func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, deliver
|
||||
}
|
||||
return true
|
||||
case "textDocument/prepareRename": // req
|
||||
var params TextDocumentPositionParams
|
||||
var params PrepareRenameParams
|
||||
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
||||
sendParseError(ctx, r, err)
|
||||
return true
|
||||
@ -562,6 +573,10 @@ func (s *serverDispatcher) DidChangeWatchedFiles(ctx context.Context, params *Di
|
||||
return s.Conn.Notify(ctx, "workspace/didChangeWatchedFiles", params)
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Progress(ctx context.Context, params *ProgressParams) error {
|
||||
return s.Conn.Notify(ctx, "$/progress", params)
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) SetTraceNotification(ctx context.Context, params *SetTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/setTraceNotification", params)
|
||||
}
|
||||
@ -569,7 +584,7 @@ func (s *serverDispatcher) SetTraceNotification(ctx context.Context, params *Set
|
||||
func (s *serverDispatcher) LogTraceNotification(ctx context.Context, params *LogTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/logTraceNotification", params)
|
||||
}
|
||||
func (s *serverDispatcher) Implementation(ctx context.Context, params *TextDocumentPositionParams) ([]Location, error) {
|
||||
func (s *serverDispatcher) Implementation(ctx context.Context, params *ImplementationParams) ([]Location, error) {
|
||||
var result []Location
|
||||
if err := s.Conn.Call(ctx, "textDocument/implementation", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -577,7 +592,7 @@ func (s *serverDispatcher) Implementation(ctx context.Context, params *TextDocum
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) TypeDefinition(ctx context.Context, params *TextDocumentPositionParams) ([]Location, error) {
|
||||
func (s *serverDispatcher) TypeDefinition(ctx context.Context, params *TypeDefinitionParams) ([]Location, error) {
|
||||
var result []Location
|
||||
if err := s.Conn.Call(ctx, "textDocument/typeDefinition", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -609,7 +624,7 @@ func (s *serverDispatcher) FoldingRange(ctx context.Context, params *FoldingRang
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Declaration(ctx context.Context, params *TextDocumentPositionParams) ([]DeclarationLink, error) {
|
||||
func (s *serverDispatcher) Declaration(ctx context.Context, params *DeclarationParams) ([]DeclarationLink, error) {
|
||||
var result []DeclarationLink
|
||||
if err := s.Conn.Call(ctx, "textDocument/declaration", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -625,7 +640,7 @@ func (s *serverDispatcher) SelectionRange(ctx context.Context, params *Selection
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Initialize(ctx context.Context, params *InitializeParams) (*InitializeResult, error) {
|
||||
func (s *serverDispatcher) Initialize(ctx context.Context, params *ParamInitia) (*InitializeResult, error) {
|
||||
var result InitializeResult
|
||||
if err := s.Conn.Call(ctx, "initialize", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -661,7 +676,7 @@ func (s *serverDispatcher) Resolve(ctx context.Context, params *CompletionItem)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Hover(ctx context.Context, params *TextDocumentPositionParams) (*Hover, error) {
|
||||
func (s *serverDispatcher) Hover(ctx context.Context, params *HoverParams) (*Hover, error) {
|
||||
var result Hover
|
||||
if err := s.Conn.Call(ctx, "textDocument/hover", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -669,7 +684,7 @@ func (s *serverDispatcher) Hover(ctx context.Context, params *TextDocumentPositi
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *TextDocumentPositionParams) (*SignatureHelp, error) {
|
||||
func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *SignatureHelpParams) (*SignatureHelp, error) {
|
||||
var result SignatureHelp
|
||||
if err := s.Conn.Call(ctx, "textDocument/signatureHelp", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -677,7 +692,7 @@ func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *TextDocume
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Definition(ctx context.Context, params *TextDocumentPositionParams) ([]Location, error) {
|
||||
func (s *serverDispatcher) Definition(ctx context.Context, params *DefinitionParams) ([]Location, error) {
|
||||
var result []Location
|
||||
if err := s.Conn.Call(ctx, "textDocument/definition", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -693,7 +708,7 @@ func (s *serverDispatcher) References(ctx context.Context, params *ReferencePara
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) DocumentHighlight(ctx context.Context, params *TextDocumentPositionParams) ([]DocumentHighlight, error) {
|
||||
func (s *serverDispatcher) DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) ([]DocumentHighlight, error) {
|
||||
var result []DocumentHighlight
|
||||
if err := s.Conn.Call(ctx, "textDocument/documentHighlight", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -709,17 +724,17 @@ func (s *serverDispatcher) DocumentSymbol(ctx context.Context, params *DocumentS
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation, error) {
|
||||
var result []SymbolInformation
|
||||
if err := s.Conn.Call(ctx, "workspace/symbol", params, &result); err != nil {
|
||||
func (s *serverDispatcher) CodeAction(ctx context.Context, params *CodeActionParams) ([]CodeAction, error) {
|
||||
var result []CodeAction
|
||||
if err := s.Conn.Call(ctx, "textDocument/codeAction", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) CodeAction(ctx context.Context, params *CodeActionParams) ([]CodeAction, error) {
|
||||
var result []CodeAction
|
||||
if err := s.Conn.Call(ctx, "textDocument/codeAction", params, &result); err != nil {
|
||||
func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation, error) {
|
||||
var result []SymbolInformation
|
||||
if err := s.Conn.Call(ctx, "workspace/symbol", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
@ -773,7 +788,7 @@ func (s *serverDispatcher) Rename(ctx context.Context, params *RenameParams) (*W
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) PrepareRename(ctx context.Context, params *TextDocumentPositionParams) (*Range, error) {
|
||||
func (s *serverDispatcher) PrepareRename(ctx context.Context, params *PrepareRenameParams) (*Range, error) {
|
||||
var result Range
|
||||
if err := s.Conn.Call(ctx, "textDocument/prepareRename", params, &result); err != nil {
|
||||
return nil, err
|
||||
@ -811,3 +826,9 @@ type CancelParams struct {
|
||||
*/
|
||||
ID jsonrpc2.ID `json:"id"`
|
||||
}
|
||||
|
||||
// Types constructed to avoid structs as formal argument types
|
||||
type ParamInitia struct {
|
||||
InitializeParams
|
||||
WorkDoneProgressParams
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func (s *Server) rename(ctx context.Context, params *protocol.RenameParams) (*pr
|
||||
return &protocol.WorkspaceEdit{Changes: &changes}, nil
|
||||
}
|
||||
|
||||
func (s *Server) prepareRename(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.Range, error) {
|
||||
func (s *Server) prepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (*protocol.Range, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
f, err := getGoFile(ctx, view, uri)
|
||||
|
@ -86,7 +86,7 @@ type Server struct {
|
||||
|
||||
// General
|
||||
|
||||
func (s *Server) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) {
|
||||
func (s *Server) Initialize(ctx context.Context, params *protocol.ParamInitia) (*protocol.InitializeResult, error) {
|
||||
return s.initialize(ctx, params)
|
||||
}
|
||||
|
||||
@ -160,23 +160,23 @@ func (s *Server) Resolve(ctx context.Context, item *protocol.CompletionItem) (*p
|
||||
return nil, notImplemented("completionItem/resolve")
|
||||
}
|
||||
|
||||
func (s *Server) Hover(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.Hover, error) {
|
||||
func (s *Server) Hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) {
|
||||
return s.hover(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) SignatureHelp(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.SignatureHelp, error) {
|
||||
func (s *Server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||
return s.signatureHelp(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) Definition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) {
|
||||
func (s *Server) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
|
||||
return s.definition(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) TypeDefinition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) {
|
||||
func (s *Server) TypeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) ([]protocol.Location, error) {
|
||||
return s.typeDefinition(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) Implementation(context.Context, *protocol.TextDocumentPositionParams) ([]protocol.Location, error) {
|
||||
func (s *Server) Implementation(context.Context, *protocol.ImplementationParams) ([]protocol.Location, error) {
|
||||
return nil, notImplemented("Implementation")
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ func (s *Server) References(ctx context.Context, params *protocol.ReferenceParam
|
||||
return s.references(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) DocumentHighlight(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.DocumentHighlight, error) {
|
||||
func (s *Server) DocumentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
|
||||
return s.documentHighlight(ctx, params)
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ func (s *Server) Rename(ctx context.Context, params *protocol.RenameParams) (*pr
|
||||
return s.rename(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) Declaration(context.Context, *protocol.TextDocumentPositionParams) ([]protocol.DeclarationLink, error) {
|
||||
func (s *Server) Declaration(context.Context, *protocol.DeclarationParams) ([]protocol.DeclarationLink, error) {
|
||||
return nil, notImplemented("Declaration")
|
||||
}
|
||||
|
||||
@ -248,11 +248,15 @@ func (s *Server) LogTraceNotification(context.Context, *protocol.LogTraceParams)
|
||||
return notImplemented("LogtraceNotification")
|
||||
}
|
||||
|
||||
func (s *Server) PrepareRename(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.Range, error) {
|
||||
func (s *Server) PrepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (*protocol.Range, error) {
|
||||
// TODO(suzmue): support sending placeholder text.
|
||||
return s.prepareRename(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) Progress(context.Context, *protocol.ProgressParams) error {
|
||||
return notImplemented("Progress")
|
||||
}
|
||||
|
||||
func (s *Server) SetTraceNotification(context.Context, *protocol.SetTraceParams) error {
|
||||
return notImplemented("SetTraceNotification")
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"golang.org/x/tools/internal/telemetry/tag"
|
||||
)
|
||||
|
||||
func (s *Server) signatureHelp(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.SignatureHelp, error) {
|
||||
func (s *Server) signatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||
uri := span.NewURI(params.TextDocument.URI)
|
||||
view := s.session.ViewOf(uri)
|
||||
f, err := getGoFile(ctx, view, uri)
|
||||
|
Loading…
Reference in New Issue
Block a user