Skip to content

add preview for ALEFindReferences#5001

Merged
w0rp merged 5 commits intodense-analysis:masterfrom
bretello:add-preview-alefindreferences
Aug 13, 2025
Merged

add preview for ALEFindReferences#5001
w0rp merged 5 commits intodense-analysis:masterfrom
bretello:add-preview-alefindreferences

Conversation

@bretello
Copy link
Contributor

@bretello bretello commented Jul 11, 2025

This PR adds support line preview in ALEFindReferences output

alefindreferences

asciinema

@bretello bretello force-pushed the add-preview-alefindreferences branch from 2d0a51c to 8f11e59 Compare July 11, 2025 13:41
@bretello bretello force-pushed the add-preview-alefindreferences branch from 8f11e59 to f13c313 Compare July 11, 2025 16:27
try
let l:line_text = readfile(l:filename)[l:line]
catch
" cannot read file, this happens in tests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a workaround to the following test failures (which use a dummy filename)

LSP reference responses should be put to quickfix and LSP reference responses should be handled

here https://github.com/dense-analysis/ale/blob/add-preview-alefindreferences/test/test_find_references.vader

I'll try and come up with a better solution for tests.

@bretello
Copy link
Contributor Author

I guess this is kind of a duplicate of #4982

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

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

This is a nice addition! Have a look at my comments here.

\ 'column': l:col + 1,
\}

if exists('l:line_text')
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using an exists() check let's default the variable to an empty string. Can we avoid the conditional value and always return the Dictionary directly with text above or match here set to an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaned this section up a bit to address this and to keep it similar to ale#references#FormatTSResponseItem

let l:filename = ale#util#ToResource(a:response_item.uri)

try
let l:line_text = readfile(l:filename)[l:line]
Copy link
Member

Choose a reason for hiding this comment

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

Let's add an option to disable showing the contents of files for references. We can enable showing the contents of files by default. Lets make it a minus option so you can write commands to explicitly enable or disable line previews. Have a look at how ale#references#Find lets you specify where to output references and then falls back on ale_default_navigation.

If we are displaying preview text do we need to consider the character start and line and character end of the range? Just something worth considering and seeing how it looks.

Copy link
Contributor Author

@bretello bretello Jul 20, 2025

Choose a reason for hiding this comment

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

Thanks for the review @w0rp .

I included the first suggestion in the last push (a012900)

Regarding the second suggestion, I initially implemented it showing the match over the range, but it ended up only showing the reference being searched, which wasn't very useful.

I also added a few tests and updated the docs.

@bretello bretello force-pushed the add-preview-alefindreferences branch 4 times, most recently from 32798f9 to 7cff51e Compare July 20, 2025 16:53
@bretello bretello force-pushed the add-preview-alefindreferences branch from 7cff51e to d90648e Compare July 25, 2025 17:54
@w0rp w0rp merged commit 7df9444 into dense-analysis:master Aug 13, 2025
7 of 8 checks passed
@w0rp
Copy link
Member

w0rp commented Aug 13, 2025

Cheers! 🍻


if get(a:options, 'show_contents') == 1
try
let l:line_text = substitute(readfile(l:filename)[l:line], '^\s*\(.\{-}\)\s*$', '\1', '')
Copy link
Member

Choose a reason for hiding this comment

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

I've merged this, and thanks for this. An improvement we could try here is passing the max argument to readfile to read only up to the line we need.

@bretello bretello deleted the add-preview-alefindreferences branch August 29, 2025 18:21
Caw3 pushed a commit to Caw3/ale that referenced this pull request Dec 10, 2025
* add preview for ALEFindReferences
* ALEFindReferences: add -contents options and g:ale_references_show_contents option to configure default behaviour
* tests: add tests for ALEFindReferences -contents feature
* tests: update tsserver references tests with show_contents args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants