diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 4ad7c250..78086a1b 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -315,6 +315,7 @@ function Base.run(server::LanguageServerInstance) msg_dispatcher[textDocument_formatting_request_type] = request_wrapper(textDocument_formatting_request, server) msg_dispatcher[textDocument_references_request_type] = request_wrapper(textDocument_references_request, server) msg_dispatcher[textDocument_rename_request_type] = request_wrapper(textDocument_rename_request, server) + msg_dispatcher[textDocument_prepareRename_request_type] = request_wrapper(textDocument_prepareRename_request, server) msg_dispatcher[textDocument_documentSymbol_request_type] = request_wrapper(textDocument_documentSymbol_request, server) msg_dispatcher[textDocument_documentHighlight_request_type] = request_wrapper(textDocument_documentHighlight_request, server) msg_dispatcher[julia_getModuleAt_request_type] = request_wrapper(julia_getModuleAt_request, server) diff --git a/src/protocol/messagedefs.jl b/src/protocol/messagedefs.jl index 12dc8ab6..48e5d6d8 100644 --- a/src/protocol/messagedefs.jl +++ b/src/protocol/messagedefs.jl @@ -5,6 +5,7 @@ const textDocument_definition_request_type = JSONRPC.RequestType("textDocument/d const textDocument_formatting_request_type = JSONRPC.RequestType("textDocument/formatting", DocumentFormattingParams, Union{Vector{TextEdit}, Nothing}) const textDocument_references_request_type = JSONRPC.RequestType("textDocument/references", ReferenceParams, Union{Vector{Location}, Nothing}) const textDocument_rename_request_type = JSONRPC.RequestType("textDocument/rename", RenameParams, Union{WorkspaceEdit, Nothing}) +const textDocument_prepareRename_request_type = JSONRPC.RequestType("textDocument/prepareRename", PrepareRenameParams, Range) const textDocument_documentSymbol_request_type = JSONRPC.RequestType("textDocument/documentSymbol", DocumentSymbolParams, Union{Vector{DocumentSymbol}, Vector{SymbolInformation}, Nothing}) const textDocument_documentHighlight_request_type = JSONRPC.RequestType("textDocument/documentHighlight", DocumentHighlightParams, Union{Vector{DocumentHighlight}, Nothing}) const textDocument_hover_request_type = JSONRPC.RequestType("textDocument/hover", TextDocumentPositionParams, Union{Hover, Nothing}) diff --git a/src/requests/features.jl b/src/requests/features.jl index 4b0d7d0b..0a7bcbfb 100644 --- a/src/requests/features.jl +++ b/src/requests/features.jl @@ -168,6 +168,13 @@ function textDocument_rename_request(params::RenameParams, server::LanguageServe return WorkspaceEdit(missing, collect(values(tdes))) end +function textDocument_prepareRename_request(params::PrepareRenameParams, server::LanguageServerInstance, conn) + doc = getdocument(server, URI2(params.textDocument.uri)) + x = get_expr1(getcst(doc), get_offset(doc, params.position)) + _, x_start_offset = get_file_loc(x) + x_range = Range(doc, x_start_offset .+ (0:x.span)) + return x_range +end is_valid_binding_name(name) = false function is_valid_binding_name(name::EXPR) diff --git a/src/requests/init.jl b/src/requests/init.jl index 77b9698f..1d6b7709 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -1,4 +1,7 @@ -const serverCapabilities = ServerCapabilities( +function ServerCapabilities(client::ClientCapabilities) + prepareSupport = !ismissing(client.textDocument.rename) && client.textDocument.rename.prepareSupport === true + + ServerCapabilities( TextDocumentSyncOptions(true, TextDocumentSyncKinds.Full, false, @@ -21,7 +24,7 @@ const serverCapabilities = ServerCapabilities( true, false, missing, - true, + RenameOptions(missing, prepareSupport), false, ExecuteCommandOptions(missing, collect(keys(LSActions))), true, @@ -29,6 +32,8 @@ const serverCapabilities = ServerCapabilities( WorkspaceOptions(WorkspaceFoldersOptions(true, true)), missing) +end + hasreadperm(p::String) = (uperm(p) & 0x04) == 0x04 function isjuliabasedir(path) @@ -167,7 +172,7 @@ function initialize_request(params::InitializeParams, server::LanguageServerInst server.clientcapability_workspace_didChangeConfiguration = true end - return InitializeResult(serverCapabilities, missing) + return InitializeResult(ServerCapabilities(server.clientCapabilities), missing) end diff --git a/test/test_communication.jl b/test/test_communication.jl index c39cea27..b886dd2b 100644 --- a/test/test_communication.jl +++ b/test/test_communication.jl @@ -34,7 +34,7 @@ init_request = LanguageServer.InitializeParams( LanguageServer.DocumentFormattingClientCapabilities(true), missing, # DocumentRangeFormattingClientCapabilities(), missing, # DocumentOnTypeFormattingClientCapabilities(), - LanguageServer.RenameClientCapabilities(true, missing), + LanguageServer.RenameClientCapabilities(true, true), missing, # PublishDiagnosticsClientCapabilities(), missing, # FoldingRangeClientCapabilities(), missing, # SelectionRangeClientCapabilities() @@ -73,7 +73,9 @@ init_response = JSON.parse(""" "codeActionProvider": true, "documentFormattingProvider": true, "documentRangeFormattingProvider": false, - "renameProvider": true, + "renameProvider": { + "prepareProvider": true + }, "documentLinkProvider": { "resolveProvider": false }, @@ -128,7 +130,7 @@ try @test_broken init_response == response @test response["capabilities"]["typeDefinitionProvider"] == false - @test response["capabilities"]["renameProvider"] == true + @test response["capabilities"]["renameProvider"] == Dict("prepareProvider" => true) finally close(client) end