-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add GotoRelevantFile functionality #2985
base: main
Are you sure you want to change the base?
Conversation
ce2a926
to
fb30abd
Compare
super() | ||
|
||
@workspace_path = T.let(Dir.pwd, String) | ||
@path = T.let(path.delete_prefix(@workspace_path), String) |
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 I think it may be convenient to have a URI#to_workspace_relative_path
that matches VS Code's Copy Relative Path
value. WDYT?
Sorry for the delay in reviewing. Can you rebase this against the |
fb30abd
to
9b39633
Compare
Define and implement the experimental/gotoRelevantFile lsp method. This request takes in a textDcoument param, and retusn an array of locations that are related to the input file path. Currently, the related file paths are - test files, if the input file is a source file - source files, if the input file is a test file Basically it goes between source file <> test file. This is implemented as a experimental method until something more official comes along.
9b39633
to
02e94b1
Compare
02e94b1
to
e23d525
Compare
|
||
class GotoRelevantFileTest < Minitest::Test | ||
def setup | ||
Dir.stubs(:pwd).returns("/workspace") |
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'm a little wary of stubbing pwd
since if some test helper, or minitest itself, uses it then it may break.
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.
Can you expand on that?
I tried tophatting on |
For the CI spelling failures, you can add those terms to |
@andyw8 can you share your tophatting steps? I tried it on both vscode and nvim and both work as expected. For what's worth I've also been using it on shopify/shopify for a while now and have not encountered issues. |
Just tried again and it's working, I must have missed something before. |
|
||
test_prefix_pattern = /^(#{TEST_KEYWORDS.join("_|")}_)/ | ||
test_suffix_pattern = /(_#{TEST_KEYWORDS.join("|_")})$/ | ||
test_pattern = /#{test_prefix_pattern}|#{test_suffix_pattern}/ |
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.
Maybe we can store these patterns in constants too? Do we need to recompute them for each request?
input_basename.gsub(test_pattern, "") | ||
else | ||
test_prefix_glob = "#{TEST_KEYWORDS.join("_,")}_" | ||
test_suffix_glob = "_#{TEST_KEYWORDS.join(",_")}" |
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.
Same as the above.
end | ||
|
||
sig { params(path: String, candidates: T::Array[String]).returns(T::Array[String]) } | ||
def find_most_similar_with_jacaard(path, candidates) |
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'd appreciate a comment explaining what jacaard
means 😂
|
||
sig { returns(T::Array[String]) } | ||
def find_relevant_paths | ||
workspace_path = Dir.pwd |
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.
Let's take in GlobalState
and use its workspace_path
method to get this value. I think Requests::Rename
is a good reference.
def initialize(path) | ||
super() | ||
|
||
@workspace_path = T.let(Dir.pwd, String) |
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.
Let's use GlobalState#workspace_path
instead.
sig { returns(T::Array[String]) } | ||
def find_relevant_paths | ||
workspace_path = Dir.pwd | ||
relative_path = @path.delete_prefix(workspace_path) |
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.
Isn't @path
already the value without workspace path prefix?
Motivation
A stab at #2966. We can now click the "Goto Test" and "Goto Source" from the commands menu and from the explorer view.
Instruction here for those that want to use in in neovim
In the LspAttach event callback, add the following
and then you can bind goto_relevant_file() to a keymap
Implementation
Implementing it as a custom request for now until vscode starts supporting it officially.
I've studied a few different implementations and after some internet browsing decided to use the Jacaard similarity here to find the most likely path to the desired filename.
Some future opportunities–
Automated Tests
Included
Manual Tests
goto-relevant-file-demo.mp4