-
Notifications
You must be signed in to change notification settings - Fork 122
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
Migrate DocumentLink request to YARP #982
Conversation
3933178
to
8090d76
Compare
sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue).void } | ||
def initialize(uri, emitter, message_queue) | ||
sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue, document: Document).void } | ||
def initialize(uri, emitter, message_queue, document) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
d7a6fdb
to
9702676
Compare
3c49936
to
d7cf5a3
Compare
dc4c184
to
ed9bde7
Compare
lib/ruby_lsp/document.rb
Outdated
@@ -30,6 +30,7 @@ def initialize(source:, version:, uri:, encoding: Constant::PositionEncodingKind | |||
@uri = T.let(uri, URI::Generic) | |||
@unparsed_edits = T.let([], T::Array[EditShape]) | |||
@parse_result = T.let(YARP.parse(@source), YARP::ParseResult) | |||
@parse_result.attach_comments! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vinistock do you think we should always attach the comments, or make it conditional for requests that need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know what performance cost it could bring to large files? If it's not too significant, having comments always available could enable more extensions (e.g. go-to-definition for yard comments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could indeed have a performance cost because it basically analyzes the entire AST to attach the comments.
Given that the only request that needs comments is document link, which we plan on removing in the future anyway, I'm not sure we want to do it.
Tapioca always adds the magic source comment immediately above the class/module/constant/method, so we always know where to find it without paying this cost.
What do you think about avoiding it for now to get the most performance we can out of YARP?
In that case, we can pass the comments array to document link's initializer, turn the array into a hash of line_number => comment
and then just access it directly when finding nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll push a commit to show how that would look, then we can decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed.
ed9bde7
to
d0e4379
Compare
49b835e
to
dab68c0
Compare
d0e4379
to
75178a4
Compare
c01556e
to
e4912b0
Compare
1cd1a00
to
933b7a1
Compare
933b7a1
to
2002a4d
Compare
2002a4d
to
7307e49
Compare
@@ -85,6 +92,12 @@ def initialize(uri, emitter, message_queue) | |||
version_match = path ? /(?<=%40)[\d.]+(?=\.rbi$)/.match(path) : nil | |||
@gem_version = T.let(version_match && version_match[0], T.nilable(String)) | |||
@_response = T.let([], T::Array[Interface::DocumentLink]) | |||
@comments = T.let( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to name the instance variable, @lines_to_comments
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good name 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just some minor adjustments
lib/ruby_lsp/executor.rb
Outdated
@@ -97,7 +97,7 @@ def run(request) | |||
# Run listeners for the document | |||
emitter = EventEmitter.new | |||
document_symbol = Requests::DocumentSymbol.new(emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, @message_queue, document.comments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been putting extra arguments other than emitter
and message_queue
first. Can we put this after uri
please?
@@ -85,6 +92,12 @@ def initialize(uri, emitter, message_queue) | |||
version_match = path ? /(?<=%40)[\d.]+(?=\.rbi$)/.match(path) : nil | |||
@gem_version = T.let(version_match && version_match[0], T.nilable(String)) | |||
@_response = T.let([], T::Array[Interface::DocumentLink]) | |||
@comments = T.let( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good name 👍
comments.map do |comment| | ||
[comment.location.end_line, comment] | ||
end.to_h, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need the intermediate array.
comments.map do |comment| | |
[comment.location.end_line, comment] | |
end.to_h, | |
comments.to_h do |comment| | |
[comment.location.end_line, comment] | |
end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice, I forgot to_h
can accept a block.
lib/ruby_lsp/executor.rb
Outdated
@@ -97,7 +97,7 @@ def run(request) | |||
# Run listeners for the document | |||
emitter = EventEmitter.new | |||
document_symbol = Requests::DocumentSymbol.new(emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, document.comments, @message_queue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order doesn't look right here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. And this highlighted that the integration test was being skipped, which I've re-enabled.
lib/ruby_lsp/executor.rb
Outdated
@@ -97,7 +97,7 @@ def run(request) | |||
# Run listeners for the document | |||
emitter = EventEmitter.new | |||
document_symbol = Requests::DocumentSymbol.new(emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, @message_queue) | |||
document_link = Requests::DocumentLink.new(uri, emitter, document.comments, @message_queue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the order of arguments is not right?
* Temporarily disable .github/workflows/lsp_check.yml * Temporarily disable some tests * Preparation for YARP migration * Migrate DocumentSymbol request to YARP * Migrate Hover request to YARP * Migrate PathCompletion request to YARP * Migrate Sorbet request to YARP * Migrate InlayHints request to YARP * Migrate ShowSyntaxTree request to YARP * Migrate SelectionRange request to YARP * Migrate Definition request to YARP * Migrate Diagnostics request to YARP * Migrate CodeActionResolve request to YARP * Update selection ranges expectations * Fix rebase discrepancies * Add YARP RBI annotations (#978) * Migrate code lens to yarp (#979) Migrate CodeLens to YARP * Update `SERVER_EXTENSIONS.md` for YARP (#984) Co-authored-by: Andy Waite <andyw8@users.noreply.github.com> * Update text references from Syntax Tree to YARP (#986) Co-authored-by: Andy Waite <andyw8@users.noreply.github.com> * Fix rebase discrepancies * Migrate folding range to YARP (#980) * Fix rebase discrepancies 3 * Migrate semantic highlighting to YARP (#1000) Co-authored-by: Alexandre Terrasa <Morriar@users.noreply.github.com> * Migrate document highlight to YARP (#1005) * Simplify block locals handling in semantic highlighting (#1011) * Fix latest breaking changes * Make folding range a listener (#1013) * Migrate DocumentLink request to YARP (#982) * Migrate DocumentLink to YARP * Only parse comments where needed * Fix type * PR feedback * Fix argument order * Re-enable DocumentLink integration test --------- Co-authored-by: Andy Waite <andyw8@users.noreply.github.com> * Re-enable CI (#1022) * Re-generate YARP RBIs * Re-enable tests * Fix typechecking errors * Use locations for creating document symbol entries --------- Co-authored-by: Andy Waite <andyw8@users.noreply.github.com> Co-authored-by: Andy Waite <13400+andyw8@users.noreply.github.com> Co-authored-by: Alexandre Terrasa <Morriar@users.noreply.github.com>
Motivation
Partially addresses #449
Implementation
The previous approach was based on parsing the document for comments, but with YARP we don't have a Comment node, so instead we visit the critical nodes and then check for attached comments.
Automated Tests
I added extra examples to the existing fixtures.
Manual Tests