-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use relative paths when previewing file locations #2238
Use relative paths when previewing file locations #2238
Conversation
Linter is failing with:
But we (probably) don't want the results relative to specific buffer; we want it relative to the current working directory, which is precisely what @w0rp is there a better way around this? |
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.
Use a " no-custom-checks
comment at the end of line to ignore the warning about getcwd()
.
These changes completely replace absolute paths with relative paths. Instead of doing that, add options to the commands for showing relative paths, like :ALEExampleCommand -relative
, and show absolute paths by default.
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 added an optional use_relative_paths flag to the ale#preview#ShowSelection()
function to enable the display of relative paths, defaulting to absolute paths.
" Absolute paths
ale#preview#ShowSelection([])
ale#preview#ShowSelection([], { 'use_relative_paths': 0 })
" Relative paths
ale#preview#ShowSelection([], { 'use_relative_paths': 1 })
But I'm not familiar with how to parse a -relative
option from an ex-command, and then, the best way to pass that through multiple function calls to reach ale#preview#ShowSelection()
- ale#references#Find()
- s:FindReferences()
- s:OnReady
- ale#references#HandleTSServerResponse
- ale#references#HandleLSPResponse
- ale#preview#ShowSelection
Example: ALEFindReferences -relative
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.
See :help command
. You can pass <args>
or similar to a function and parse the string for options. You can access the raw string for the options and parse it.
autoload/ale/references.vim
Outdated
endif | ||
endfor | ||
endif | ||
|
||
for l:linter in ale#linter#Get(&filetype) | ||
if !empty(l:linter.lsp) | ||
call s:FindReferences(l:linter) |
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.
Instead of modifying a script variable, pass the options in here. Forward that on to the OnReady
function. You can then save the options in s:references_map
. You can write let l:options = remove(s:references_map, a:response.id)
above to get the options out at the 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.
Thanks for pointing me in the right direction. I applied your solution and added tests.
Lemme know if there's anything else I can do to clean up (or correct) the code.
Cheers! 🍻 |
Absolute paths can be long and repetitive, and cause the more interesting details (in a file location preview) to be truncated. Instead, display file locations relative to the current working directory.