Skip to content
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

Fix #715: fix eglot-extend-to-xref under Windows #933

Closed
wants to merge 3 commits into from

Conversation

wsw0108
Copy link

@wsw0108 wsw0108 commented Apr 26, 2022

By downcase 'buffer-file-name' as hash key

@joaotavora
Copy link
Owner

Thanks, but can you explain how you reached the conclusion that there is a casing problem here? When exactly is one filename with a given casing inserted into the hash table only to be retrieved with a different casing? Give a simple example.

@wsw0108
Copy link
Author

wsw0108 commented Apr 26, 2022

For feature eglot-extend-to-xref, it use var eglot--servers-by-xrefed-file.

From the log attached to this issue, we can see that it's the casing mismatch problem(between lsp server and emacs). So just normalize the key for set/get to/from hash table eglot--servers-by-xrefed-file.

@joaotavora
Copy link
Owner

From the log attached to this issue, we can see that it's the casing mismatch problem(between lsp server and emacs). So just normalize the key for set/get to/from hash table eglot--servers-by-xrefed-file.

Where can I see this? Can you point it out specifically?

You wrote in that issue:

cangd return "file:///C:/Program%20Files%20%28x86%29/Windows%20Kits/10/Include/10.0.19041.0/ucrt/stdio.h"
buffer-file-name is "c:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/stdio.h"

But the difference between the two representations of the same file (presumably) is much more than just casing.

So I must be missing something.

@wsw0108
Copy link
Author

wsw0108 commented Apr 27, 2022

(eglot--uri-to-path "file:///C:/Program%20Files%20%28x86%29/Windows%20Kits/10/Include/10.0.19041.0/ucrt/stdio.h")
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/stdio.h"

When Emacs visit the stdio.h, the buffer-file-name will be "c:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/stdio.h".

And in eglot--xref-make-match, it use eglot--uri-to-path to extract file from uri, then use (expand-file-name file) as key to check eglot--servers-by-xrefed-file.

eglot/eglot.el

Lines 2347 to 2351 in 777a716

(defun eglot--xref-make-match (name uri range)
"Like `xref-make-match' but with LSP's NAME, URI and RANGE.
Try to visit the target file for a richer summary line."
(pcase-let*
((file (eglot--uri-to-path uri))

eglot/eglot.el

Lines 2379 to 2380 in 777a716

(setf (gethash (expand-file-name file) eglot--servers-by-xrefed-file)
(eglot--current-server-or-lose))

@joaotavora
Copy link
Owner

Ah, thanks, so it's only the drive letter?

@wsw0108
Copy link
Author

wsw0108 commented Apr 27, 2022

Ah, thanks, so it's only the drive letter?

Yes, Emacs just downcase the driver letter under Windows.

@joaotavora
Copy link
Owner

joaotavora commented Apr 27, 2022 via email

@wsw0108
Copy link
Author

wsw0108 commented Apr 27, 2022

(expand-file-name (eglot--uri-to-path "file:///C:/Program%20Files%20%28x86%29/Windows%20Kits/10/Include/10.0.19041.0/ucrt/stdio.h"))
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/stdio.h"

(expand-file-name "/abc.txt")
"c:/abc.txt"

It seems expand-file-name handle absolute path specially.

@wsw0108
Copy link
Author

wsw0108 commented May 23, 2022

this pr can not fix #715, as gopls does not follow the fs displayed case(ex gopls return C:/go/src, and fs explorer display C:/Go/src.

So I close it.

@wsw0108 wsw0108 closed this May 23, 2022
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