Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alter getCurrentBlockRange request #755

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/requests/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,49 @@ end
function setTraceNotification_notification(params, server::LanguageServerInstance, conn)
end

function julia_getCurrentBlockRange_request(params::TextDocumentPositionParams, server::LanguageServerInstance, conn)
tdpp = params
function julia_getCurrentBlockRange_request(tdpp::TextDocumentPositionParams, server::LanguageServerInstance, conn)
doc = getdocument(server, URI2(tdpp.textDocument.uri))
offset = get_offset(doc, tdpp.position)
x = getcst(doc)
loc = 0
p1, p2, p3 = 0, x.span, x.fullspan

if typof(x) === CSTParser.FileH
(offset > x.fullspan || x.args === nothing) && return Position(get_position_at(doc, p1)...), Position(get_position_at(doc, p2)...), Position(get_position_at(doc, p3)...)
for a in x.args
if loc <= offset < loc + a.fullspan
if typof(a) === CSTParser.ModuleH
if loc + a.args[1].fullspan + a.args[2].fullspan < offset < loc + a.args[1].fullspan + a.args[2].fullspan + a.args[3].fullspan
loc0 = loc + a.args[1].fullspan + a.args[2].fullspan
if loc <= offset <= loc + a.span
if CSTParser.defines_module(a) # Within module at the top-level, lets see if we can select on of the block arguments
if loc <= offset <= loc + a.args[1].span # Within `module` keyword, so return entire expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be really helpful, while we still want julia-vscode/julia-vscode#1330 to be solved for great module experience.

return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + a.span)...), Position(get_position_at(doc, loc + a.fullspan)...)
end
if loc + a.args[1].fullspan <= offset <= loc + a.args[1].fullspan + a.args[2].span # Within name of the module, so return entire expression
return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + a.span)...), Position(get_position_at(doc, loc + a.fullspan)...)
end

if loc + a.args[1].fullspan + a.args[2].fullspan <= offset <= loc + a.args[1].fullspan + a.args[2].fullspan + a.args[3].span # Within the body of a module
loc += a.args[1].fullspan + a.args[2].fullspan
for b in a.args[3].args
if loc <= offset < loc + b.fullspan
p1, p2, p3 = loc, loc + b.span, loc + b.fullspan
break
if loc <= offset <= loc + b.span
return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + b.span)...), Position(get_position_at(doc, loc + b.fullspan)...)
end
loc += b.fullspan
end
else
p1, p2, p3 = loc, loc + a.span, loc + a.fullspan
elseif loc + a.args[1].fullspan + a.args[2].fullspan + a.args[3].fullspan < offset < loc + a.args[1].fullspan + a.args[2].fullspan + a.args[3].fullspan + a.args[4].span # Within `end` of the module, so return entire expression
Copy link
Member

@aviatesk aviatesk Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this branch tries to return the entire module code at when we query request in end keyword, right ?
how about "extending" this condition so that this gets hit when the position is "just after" the end keyword ?
The test sample in my mind will be right

module A
a rand(Bool)
end|

where | represents the request position.
Currently this case never hits this branch and so just returns empty range.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That case works fine for me.

return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + a.span)...), Position(get_position_at(doc, loc + a.fullspan)...)
end
elseif typof(a) === CSTParser.TopLevel
p1, p2, p3 = loc, loc + a.span, loc + a.fullspan
for b in a.args
if loc <= offset < loc + b.fullspan
p1, p2, p3 = loc, loc + b.span, loc + b.fullspan
if loc <= offset <= loc + b.span
return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + b.span)...), Position(get_position_at(doc, loc + b.fullspan)...)
end
loc += b.fullspan
end
else
p1, p2, p3 = loc, loc + a.span, loc + a.fullspan
return Position(get_position_at(doc, loc)...), Position(get_position_at(doc, loc + a.span)...), Position(get_position_at(doc, loc + a.fullspan)...)
end
end
loc += a.fullspan
end
end
return Position(get_position_at(doc, p1)...), Position(get_position_at(doc, p2)...), Position(get_position_at(doc, p3)...)
return Position(0, 0), Position(0, 0), tdpp.position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try to get the next block here as well instead of returning the current cursor position?

end

function julia_activateenvironment_notification(params::String, server::LanguageServerInstance, conn)
Expand Down