From 3e185ea318967694a7cf1da698ca947f17ff2e96 Mon Sep 17 00:00:00 2001 From: Zac Nugent Date: Wed, 14 Jul 2021 11:49:06 +0100 Subject: [PATCH 1/4] add rd/prepareRename --- src/languageserverinstance.jl | 1 + src/protocol/messagedefs.jl | 1 + src/requests/features.jl | 7 +++++++ src/requests/init.jl | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 7cb1525c..cc83090f 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -314,6 +314,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..e2d75812 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -21,7 +21,7 @@ const serverCapabilities = ServerCapabilities( true, false, missing, - true, + RenameOptions(missing, true), false, ExecuteCommandOptions(missing, collect(keys(LSActions))), true, From 50cec5fc0ae6d8dea7150241cacf5f6947159989 Mon Sep 17 00:00:00 2001 From: Zac Nugent Date: Wed, 14 Jul 2021 12:13:46 +0100 Subject: [PATCH 2/4] fix test --- test/test_communication.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_communication.jl b/test/test_communication.jl index c39cea27..a61be440 100644 --- a/test/test_communication.jl +++ b/test/test_communication.jl @@ -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 From 5380cbfc2cfe2aaa8b1a2e4c51403af81a1bbd7d Mon Sep 17 00:00:00 2001 From: Zac Nugent Date: Wed, 14 Jul 2021 12:57:35 +0100 Subject: [PATCH 3/4] check prepareRename support --- src/requests/init.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/requests/init.jl b/src/requests/init.jl index e2d75812..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, - RenameOptions(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 From b47543d97737a02f56fe35999c158084f90c7ae2 Mon Sep 17 00:00:00 2001 From: Zac Nugent Date: Wed, 14 Jul 2021 13:13:30 +0100 Subject: [PATCH 4/4] test fix --- test/test_communication.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_communication.jl b/test/test_communication.jl index a61be440..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()