-
Notifications
You must be signed in to change notification settings - Fork 2.8k
jdt.ls: properly handle URI by showing contents #4302
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
base: master
Are you sure you want to change the base?
Conversation
Thanks to commit ad64e63b (jdt.ls: support jumping to `jdt://` URIs with GoTo, 2025-07-07) on the ycmd repository, it has the capability to properly handle `jdt://` URIs that are predominantly returned when a user executes the `:YcmCompleter GoTo` command or some variation of it. Introduce _GetClassNameFromJdtURI() which gets the classname from a JDT URI (e.g. Member.class) using regular expression magic so that ycm displays it on the status bar of the temporary buffer which is made to see the contents of that class file. On _HandleGotoResponse(), add a new condition which checks to see if there is a key called 'jdt_contents' in the JSON response that ycmd provides. If that condition is true, create a temporary readonly buffer, set the buffer name to the file name that is received at an earlier stage from the 'uri' key, and set the contents of the buffer to match what is received from the key 'jdt_contents'. Finally, set the syntax highlighting to 'java' and jump the cursor to the line and column specified from the JSON (specifically found in the 'range' key). Note that the temporary buffer made does _NOT_ get its contents from any file - no new temporary file is created or deleted during this process, everything is handled inside vim. Signed-off-by: Chris Sdogkos <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4302 +/- ##
===========================================
- Coverage 89.88% 74.88% -15.00%
===========================================
Files 37 30 -7
Lines 4763 2938 -1825
===========================================
- Hits 4281 2200 -2081
- Misses 482 738 +256 🚀 New features to boost your workflow:
|
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.
Reviewable status: 0 of 2 LGTMs obtained
python/ycm/client/command_request.py
line 161 at r1 (raw file):
[ vimsupport.BuildQfListItem( x ) for x in self._response ] ) vimsupport.OpenQuickFixList( focus = True, autoclose = True ) elif 'jdt_contents' in self._response:
I'm not sure this is right either; it's making too many assumptions such as there only being one response to GoTo and that GoTo is somehow special.
I think we really need to register BufReadCmd auto commands to get the file contents based on the url prefix; something like:
- server returns URI/paths in a form like
YCM://<completer>/<completer subcommand>/<the actual url>
- we register a BufReadCmd for anything matching YCM://*
- we parse the buffer path to get the completer subcommand to request from ycmd.
- request from ycmd (synchronously) and provide the buffer contents
python/ycm/vimsupport.py
line 1512 at r1 (raw file):
will be readonly and unmodifiable. """ vim.command( 'enew' )
if the current buffer can't be hidden (e.g. unsaved) this will throw an error: https://github.com/puremourning/vimspector/blob/master/python3/vimspector/utils.py#L111-L122 we have something similar in YCM https://github.com/puremourning/YouCompleteMe/blob/master/python/ycm/vimsupport.py#L1347
here's how I do this in vimspector: https://github.com/puremourning/vimspector/blob/master/python3/vimspector/stack_trace.py#L736-L748
the first thing is to use a name for the buffer and use vimvupport.BufferForFile() or whatever that's called. then set the options https://github.com/puremourning/vimspector/blob/master/python3/vimspector/utils.py#L181
python/ycm/vimsupport.py
line 1528 at r1 (raw file):
buf.options[ 'buflisted' ] = False vim.command( 'setlocal noswapfile' )
buf.options[ 'swapfile' ] = False
PR Prelude
rationale for why I haven't.
actually perform all of these steps.
Why this change is necessary and useful
This pull request introduces proper handling of
jdt://
URIs in YCM when using GoTo commands (e.g.,:YcmCompleter GoTo
) with the Java Development Tools Language Server (jdt.ls). Previously, these URIs, which are commonly returned by jdt.ls for navigation to class files or members, were not fully supported in YCM, leading to incomplete or incorrect buffer handling.Building on the recent changes that I have made in the ycmd repository (specifically commit
ad64e63b
from 2025-07-07, which added support for jumping tojdt://
URIs withGoTo
), this change ensures YCM can display the contents of these URIs directly in a temporary Vim buffer without creating or relying on temporary files.Note! This PR should be merged alongside #1788 on the ycmd repository.
Original Behavior
before.mov
after.mov
This change is