Closed nickwells closed 1 year ago
Thanks for the exemplary bug report. I can reproduce the bug on a Mac at v0.11.0, but not at master, so the bug is fixed... except that the fix wasn't as deliberate as we would like, so there is more work to do.
Specifically, the CodeAction RPC used to return an "Organize Imports" action whose .Edit.DocumentChanges.TextDocumentEdit.TextDocument.URI subfield was the "realpath" of the original file name (i.e. symbolic links were expanded), so the client's simple search for the original file name failed to find it. The logic at master does not expand symbolic links, so the URI returned by the server is the same as the one requested by the user, and the client proceeds to update the file.
The reason this only shows up on the Mac, and only on temporary files, is that its /tmp dir is a symbolic link:
$ realpath /tmp
/private/tmp
This problem is related to an existing problem (whose issue I cannot now find) in which identifier renaming corrupts a file because it tries to apply identical edits to two files of different names that happen, thanks to symbolic links, to be aliases for the same file. The general solution is similar: ask the file system whether two files are equal; don't rely on lexical equivalence.
I was going to write a regression test for this but I can no longer reproduce this even with v0.11.0. I'd rather not spend any more time on it since the actual big is fixed.
This problem is related to an existing problem (whose issue I cannot now find) in which identifier renaming corrupts a file because it tries to apply identical edits to two files of different names that happen, thanks to symbolic links, to be aliases for the same file. The general solution is similar: ask the file system whether two files are equal; don't rely on lexical equivalence.
On further reflection, I think it is properly a client-side concern. The server tries as much as possible not to interpret file names, but merely to pass them down to open(1)
or go list
, or back to the client. At the risk of demanding that every LSP client implement the same solutions based on something like os.SameFile, I'm going to close this issue.
ATTENTION: Please answer these questions BEFORE submitting your issue. Thanks!
What did you do?
When I run "gopls" from within a Go program (using the exec package) against a file in a temporary directory in macOS the imports statement is not updated if I give the full pathname but is if I give a relative pathname.
Note:
The following program demonstrates the issue:
What did you expect to see?
I expected the Go program to have the imports statement filled in
What did you see instead?
The file was unchanged
Build info
the OS version as given by
uname -a
is