Skip to content

Commit 2a0e5ed

Browse files
committed
server: implements Declaration and PrepareRename
1 parent e27d88e commit 2a0e5ed

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

server.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ServerInterface interface {
2727
ColorPresentation(ctx context.Context, params *ColorPresentationParams) (result []ColorPresentation, err error)
2828
Completion(ctx context.Context, params *CompletionParams) (result *CompletionList, err error)
2929
CompletionResolve(ctx context.Context, params *CompletionItem) (result *CompletionItem, err error)
30-
// Declaration() // TODO(zchee): implements
30+
Declaration(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error)
3131
Definition(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error)
3232
DidChange(ctx context.Context, params *DidChangeTextDocumentParams) (err error)
3333
DidChangeConfiguration(ctx context.Context, params *DidChangeConfigurationParams) (err error)
@@ -47,7 +47,7 @@ type ServerInterface interface {
4747
Hover(ctx context.Context, params *TextDocumentPositionParams) (result *Hover, err error)
4848
Implementation(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error)
4949
OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFormattingParams) (result []TextEdit, err error)
50-
// PrepareRename(ctx context.Context) // TODO(zchee): implements
50+
PrepareRename(ctx context.Context, params *TextDocumentPositionParams) (result *Range, err error)
5151
RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) (result []TextEdit, err error)
5252
References(ctx context.Context, params *ReferenceParams) (result []Location, err error)
5353
Rename(ctx context.Context, params *RenameParams) (result []WorkspaceEdit, err error)
@@ -333,9 +333,11 @@ func (s *Server) CompletionResolve(ctx context.Context, params *CompletionItem)
333333
// The result type LocationLink[] got introduce with version 3.14.0 and depends in the corresponding client capability `clientCapabilities.textDocument.declaration.linkSupport`.
334334
//
335335
// Since version 3.14.0.
336-
//
337-
// TODO(zchee): implements
338-
// func (s *Server) Declaration(ctx context.Context) {}
336+
func (s *Server) Declaration(ctx context.Context, params *TextDocumentPositionParams) (result []Location, err error) {
337+
err = s.Conn.Call(ctx, MethodTextDocumentDeclaration, params, &result)
338+
339+
return result, err
340+
}
339341

340342
// Definition sends the request from the client to the server to resolve the definition location of a symbol at a given text document position.
341343
//
@@ -528,9 +530,11 @@ func (s *Server) OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFor
528530
// PrepareRename sends the request from the client to the server to setup and test the validity of a rename operation at a given location.
529531
//
530532
// Since version 3.12.0.
531-
//
532-
// TODO(zchee): implements
533-
// func (s *Server) PrepareRename(ctx context.Context) {}
533+
func (s *Server) PrepareRename(ctx context.Context, params *TextDocumentPositionParams) (result *Range, err error) {
534+
err = s.Conn.Call(ctx, MethodTextDocumentPrepareRename, params, &result)
535+
536+
return result, err
537+
}
534538

535539
// RangeFormatting sends the request from the client to the server to format a given range in a document.
536540
func (s *Server) RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) (result []TextEdit, err error) {
@@ -716,6 +720,17 @@ func ServerHandler(ctx context.Context, server ServerInterface, logger *zap.Logg
716720
logger.Error(MethodCompletionItemResolve, zap.Error(err))
717721
}
718722

723+
case MethodTextDocumentDeclaration:
724+
var params TextDocumentPositionParams
725+
if err := dec.DecodeObject(&params); err != nil {
726+
ReplyError(ctx, err, conn, r, logger)
727+
return
728+
}
729+
resp, err := server.Declaration(ctx, &params)
730+
if err := conn.Reply(ctx, r, resp, err); err != nil {
731+
logger.Error(MethodTextDocumentDeclaration, zap.Error(err))
732+
}
733+
719734
case MethodTextDocumentDefinition:
720735
var params TextDocumentPositionParams
721736
if err := dec.DecodeObject(&params); err != nil {
@@ -918,6 +933,17 @@ func ServerHandler(ctx context.Context, server ServerInterface, logger *zap.Logg
918933
logger.Error(MethodTextDocumentOnTypeFormatting, zap.Error(err))
919934
}
920935

936+
case MethodTextDocumentPrepareRename:
937+
var params TextDocumentPositionParams
938+
if err := dec.DecodeObject(&params); err != nil {
939+
ReplyError(ctx, err, conn, r, logger)
940+
return
941+
}
942+
resp, err := server.PrepareRename(ctx, &params)
943+
if err := conn.Reply(ctx, r, resp, err); err != nil {
944+
logger.Error(MethodTextDocumentPrepareRename, zap.Error(err))
945+
}
946+
921947
case MethodTextDocumentRangeFormatting:
922948
var params DocumentRangeFormattingParams
923949
if err := dec.DecodeObject(&params); err != nil {

0 commit comments

Comments
 (0)