Skip to content

Commit

Permalink
Merge pull request #1196 from jwortmann/fix-expand-function
Browse files Browse the repository at this point in the history
Fix "ExpandFunction" code action removing comments and whitespace
  • Loading branch information
pfitzseb authored Oct 23, 2023
2 parents 98be4d8 + 39b8aa9 commit e6cb559
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/requests/actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function expand_inline_func(x, server, conn)
if headof(body) == :block && length(body) == 1
file, offset = get_file_loc(func)
tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[
TextEdit(Range(file, offset .+ (0:func.fullspan)), string("function ", get_text(file)[offset .+ (1:sig.span)], "\n ", get_text(file)[offset + sig.fullspan + op.fullspan .+ (1:body.span)], "\nend\n"))
TextEdit(Range(file, offset .+ (0:func.span)), string("function ", get_text(file)[offset .+ (1:sig.span)], "\n ", get_text(file)[offset + sig.fullspan + op.fullspan .+ (1:body.span)], "\nend"))
])
JSONRPC.send(conn, workspace_applyEdit_request_type, ApplyWorkspaceEditParams(missing, WorkspaceEdit(missing, TextDocumentEdit[tde])))
elseif (headof(body) === :begin || CSTParser.isbracketed(body)) &&
Expand All @@ -175,8 +175,8 @@ function expand_inline_func(x, server, conn)
newtext = string(newtext, "\n ", get_text(file)[blockoffset .+ (1:body.args[1].args[i].span)])
blockoffset += body.args[1].args[i].fullspan
end
newtext = string(newtext, "\nend\n")
tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[TextEdit(Range(file, offset .+ (0:func.fullspan)), newtext)])
newtext = string(newtext, "\nend")
tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[TextEdit(Range(file, offset .+ (0:func.span)), newtext)])
JSONRPC.send(conn, workspace_applyEdit_request_type, ApplyWorkspaceEditParams(missing, WorkspaceEdit(missing, TextDocumentEdit[tde])))
end
end
Expand Down

0 comments on commit e6cb559

Please sign in to comment.