Skip to content

Conversation

christolis
Copy link

@christolis christolis commented Jul 12, 2025

PR Prelude

  • I have read and understood YCM's CONTRIBUTING document.
  • I have read and understood YCM's CODE_OF_CONDUCT document.
  • I have included tests for the changes in my PR. If not, I have included a
    rationale for why I haven't.
  • I understand my PR may be closed if it becomes obvious I didn'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 to jdt:// URIs with GoTo), 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 Reviewable

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]>
@christolis christolis marked this pull request as ready for review July 14, 2025 12:40
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 45.00000% with 22 lines in your changes missing coverage. Please review.

Project coverage is 74.88%. Comparing base (05f688c) to head (3502247).
Report is 1 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (05f688c) and HEAD (3502247). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (05f688c) HEAD (3502247)
6 2
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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@puremourning puremourning left a 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

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