Skip to content

Commit

Permalink
Merge pull request #963 from julia-vscode/preparerename
Browse files Browse the repository at this point in the history
add rd/prepareRename
  • Loading branch information
davidanthoff authored Jul 17, 2021
2 parents 2d941ac + 00a40a6 commit 287be7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/protocol/messagedefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 7 additions & 0 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/requests/init.jl
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,14 +24,16 @@ const serverCapabilities = ServerCapabilities(
true,
false,
missing,
true,
RenameOptions(missing, prepareSupport),
false,
ExecuteCommandOptions(missing, collect(keys(LSActions))),
true,
true,
WorkspaceOptions(WorkspaceFoldersOptions(true, true)),
missing)

end

hasreadperm(p::String) = (uperm(p) & 0x04) == 0x04

function isjuliabasedir(path)
Expand Down Expand Up @@ -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


Expand Down
8 changes: 5 additions & 3 deletions test/test_communication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -73,7 +73,9 @@ init_response = JSON.parse("""
"codeActionProvider": true,
"documentFormattingProvider": true,
"documentRangeFormattingProvider": false,
"renameProvider": true,
"renameProvider": {
"prepareProvider": true
},
"documentLinkProvider": {
"resolveProvider": false
},
Expand Down Expand Up @@ -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

0 comments on commit 287be7f

Please sign in to comment.