YouCompleteMe icon indicating copy to clipboard operation
YouCompleteMe copied to clipboard

Filepath issues with YCM and subst on Windows

Open iainmacpherson opened this issue 5 years ago • 2 comments

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

  • [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
  • [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
  • [x] I have read and understood YCM's [README][readme], especially the [Frequently Asked Questions][faq] section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm about to report and couldn't find an answer to my problem.
  • [x] If filing a bug report, I have included the output of vim --version.
  • [x] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [x] If filing a bug report, I have attached the contents of the logfiles using the :YcmToggleLogs command.
  • [x] If filing a bug report, I have included which OS (including specific OS version) I am using.
  • [X] I understand this is an open-source project staffed by volunteers and that any help I receive is a selfless, heartfelt gift of their free time. I know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

Background: I installed YouCompleteMe according to the instructions in the readme with support for clangd. Everything works as expected with errors in the source code showing up in the open vim buffer. However when using the windows command subst to map the drive letter W: to my working directory C:\work the error highlighting stopped working.

Steps to reproduce:

  1. On a windows machine create a work directory C:\work, change into that directory.
  2. vim -Nu /path/to/YCM/ycm_vimrc_minimal
  3. :edit test.cpp
  4. Enter insert mode and add a single misspelled line: #include <stio.h>
  5. Leave insert mode and you should see the error highlighted.
  6. Exit to your command prompt and type subst W: C:\work
  7. Type W: into the command prompt to change to that drive.
  8. Repeat steps 2 and 3
  9. The error should no longer be highlighted.

Changes to vimrc_ycm_minimal: On windows you will probably need to add set encoding=utf-8.

Expected behaviour: YCM should still highlight the error regardless of the drive the file is on.

Actual behaviour: YCM finds the error, (shown in YcmDiags), but the file path to the error that is displayed is the C:\work file path instead of the W:\ path and as such the error is not displayed in the open buffer.

Solution

The issue appears to be due to the behaviour of the python function os.path.realpath(filepath) on windows, which returns the "un-substed" file path C:\work when given W:\.

In YouCompleteMe\python\ycm\youcompleteme.py the UpdateWithNewDiagnosticsForFile( self, filepath, diagnostics ) function checks to see if the error found is present in an open buffer using the vimsupport.GetBufferNumberForFilename( filepath ) function. However this function uses the realpath function on the filepath passed, and causes the check to fail even when the buffer is open and the filepath is 'W:\test.cpp'.

The filepath for the Location class in third_party\ycmd\ycmd\responses.py has a member variable called filename_ which is also set using the same realpath function, and as such it will get the incorrect filepath if 'W:\test.cpp' is passed.

If both of these instances are changed from using os.path.realpath to os.path.abspath instead then YCM can locate the errors and highlight them fixing the issue.

Diagnostic data

For:

  • Output of vim --version
  • Output of YcmDebugInfo
  • Output of YcmDiags
  • Contents of YCM, ycmd and completion engine logfiles

See this gist

Output of git rev-parse HEAD in YouCompleteMe installation directory

8965a46b274c5ea36a98eaede574c8e9e7c5cf3b

OS version, distribution, etc.

OS: Microsoft Windows 10 Home Version: 10.0.18363 Build 18363

iainmacpherson avatar Apr 29 '20 12:04 iainmacpherson

Thanks for the detailed report!

I was able to repro this. I checked the history and it's been this way since year dot, so I don't think there's a specific reason we use realpath rather than abspath, and therefore the client change should be enough to resolve it.

Interestingly I didn't need to change the server's use of realpath, which surprised me.

puremourning avatar May 09 '20 10:05 puremourning

The thing mentioned in this issue is supposedly fixed. However we still have a realpath() in one place. Should we change that one to abspath() as well?

bstaletic avatar Jul 22 '20 07:07 bstaletic

it's extremely unlikely that we'll change this without a community contribution. No contribution in nearly 3 years, so closing.

puremourning avatar Dec 06 '22 13:12 puremourning