-
Notifications
You must be signed in to change notification settings - Fork 245
ocamlmerlin.c: chdir to root also on Windows to continue working if cwd is deleted #1569
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
Conversation
|
@let-def was there a reason why we didn't |
What is |
|
@nojb why not chdir to the root like in the unix cases ? |
Sorry, I was too lazy to write |
Yes, I also considered doing that by using |
I meant that |
|
No strong opinion. Switching to the temporary path seems fine. |
Oh right, each drive has its own root. I would have expected that cd'ing to |
Correct me if I am wrong, I remember trying that on windows at some point, and I remember the effect was to move to the root of the current drive (so However I don't know why we were not doing this on Windows before. |
Oops, you are both right; I misspoke.
If it works, using |
Tried it, seems to work fine, and it is simpler. Updated the PR. @MisterDA do you mind taking a second look, since you already did a first pass over the PR? Thanks! |
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.
I'm not sure I knew you could chdir to root, like this, that's good to know.
This version seems actually better than the last one, chdir is a CRT function and will set errno and failwith_perror uses perror and errno. The previous version was using Win32 functions, I don't think they set errno since the error code has to be retrieved with GetLastError (in that sense failwith_perror, a wrapper over CRT functions, is wrong for all Win32 functions…).
Reported the problem at #1570.
|
Thanks for the review @MisterDA! I updated CHANGES. This is ready to go as far as I am concerned. |
|
The windows CI failure is a bit surprising. |
It may have been a missing include. I pushed a possible fix.
Thanks! |
|
So, one of the failing test is calling: And it looks like with that PR the argument Not sure what is causing that, there nothing obvious in the diff. |
|
Right, maybe there is something wrong with how Merlin treat the relative path given as an argument now that the server is not spawned at the same place. @let-def does that ring a 🔔 ? |
I think I now what is going on. In the Unix code, we only change the working directory for the child process, but in the present verseion of this PR we are changing the working directory also for the parent process. I am working on a fix. |
|
FWIW (sorry for late entry), |
|
Oo, except |
|
Thanks @dra27 for the suggestion! Switched to |
|
(By the way, this PR fixes #1474.) |
|
Friendly ping. |
| try Sys.chdir wd; Printf.sprintf "changed directory to %S" wd | ||
| with _ -> Printf.sprintf "cannot change working directory to %S" wd | ||
| let oldwd = Sys.getcwd () in | ||
| try Sys.chdir wd; Printf.sprintf "changed directory to %S" wd, restore_cwd oldwd run |
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.
So, do I understand well that without these changes we update the server cwd before running a command without restoring it after that. Which means that the first cd to / is useless ?
Could you add a test illustrating this change's effect ?
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.
So, do I understand well that without these changes we update the server cwd before running a command without restoring it after that.
Yes.
Which means that the first cd to / is useless ?
No, it is still necessary: otherwise after handling a request the server is left on the directory where it was first launched, and this can cause problems.
Could you add a test illustrating this change's effect ?
I'm not sure how I would go about it, since we are talking about correctly (re)setting the "current directory" of the server process, but there should be no observable difference for the user. But if you have any suggestions, I'm happy to give it a try.
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.
Arf, I just realized I edited your comment instead of replying to it... My answer:
Which means that the first cd to
/is useless ?No, it is still necessary: otherwise after handling a request the server is left on the directory where it was first > launched, and this can cause problems.
Sorry, my formulation was unclear, I meant "so the current (without these changes) cd to / done in the Unix case is useless because of this issue".
Could you add a test illustrating this change's effect ?
I'm not sure how I would go about it, since we are talking about correctly (re)setting the "current directory" of the server process, but there should be no observable difference for the user. But if you have any suggestions, I'm happy to give it a try.
Maybe by triggering the original issue: start the server, move the dir, perform a query, observe a crash ?
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.
Sorry, my formulation was unclear, I meant "so the current (without these changes) cd to
/done in the Unix case is useless because of this issue".
Yes, exactly.
Maybe by triggering the original issue: start the server, move the dir, perform a query, observe a crash ?
I'll give it a try and report back.
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.
I pushed a test that shows that the current working directory was not being restored correctly before. I didn't try to exhibit a server misbehaviour because this was harder, it depends on the operating system, etc.
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.
Great, thank you !
Update src/frontend/ocamlmerlin/new/new_merlin.ml Co-authored-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
|
Thanks a lot @nojb ! |
from nojb/win32_chdir ocamlmerlin.c: chdir to root also on Windows to continue working if cwd is deleted
CHANGES:
Fri Feb 24 16:55:42 CEST 2023
+ merlin binary
- Recognize OCaml 5.0 cmi magic number in compiler version mismatch message
(ocaml/merlin#1554, fixes ocaml/merlin#1553)
- Upgrade Merlin from the RC2 to the stable 5.0.0 compiler release (ocaml/merlin#1559,
fixes ocaml/merlin#1558)
- Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
fixes ocaml/merlin#1564)
- Restore compatibility with the compiler's command line by accepting the
`-safe-string` flag as a no-op instead of rejecting it (ocaml/merlin#1544, fixes
ocaml/merlin#1518)
- Traverse aliases when jumping to declaration. This matches
jump-to-definition's behavior (ocaml/merlin#1563)
- Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
ocaml/merlin#1567 and partially ocaml/merlin#1543)
- Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
- Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
fixes ocaml/merlin#1540)
- On Windows, change to a harmless directory when launching server to avoid
locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
+ editor modes
- emacs: Fix misuse of `eq` comparison (ocaml/merlin#1549, @mattiase)
- emacs: xref works from context menus; better highlighting of xref matches;
xref recognises operators and binding operators at the cursor position;
bad locations are filtered out (ocaml/merlin#1385, fixes ocaml/merlin#1410, @mattiase)
+ test suite
- Add a test for incorrect alert defaults (ocaml/merlin#1559)
- Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
- Add non-regression tests for other fixes in this release
CHANGES:
Fri Feb 24 16:55:42 CEST 2023
+ merlin binary
- Update internal typer to match OCaml 4.14.1 release (ocaml/merlin#1557)
- Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
fixes ocaml/merlin#1564)
- Restore compatibility with some OCaml compiler's debug flags that were
incorrectly rejected by Merlin (ocaml/merlin#1556)
- Traverse aliases when jumping to declaration. This matches
jump-to-definition's behavior (ocaml/merlin#1563)
- Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
ocaml/merlin#1567 and partially ocaml/merlin#1543)
- Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
- Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
fixes ocaml/merlin#1540)
- On Windows, change to a harmless directory when launching server to avoid
locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
+ test suite
- Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
- Add non-regression tests for other fixes in this release
CHANGES:
Fri Feb 24 16:55:42 CEST 2023
+ merlin binary
- Recognize OCaml 5.0 cmi magic number in compiler version mismatch message
(ocaml/merlin#1554, fixes ocaml/merlin#1553)
- Upgrade Merlin from the RC2 to the stable 5.0.0 compiler release (ocaml/merlin#1559,
fixes ocaml/merlin#1558)
- Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
fixes ocaml/merlin#1564)
- Restore compatibility with the compiler's command line by accepting the
`-safe-string` flag as a no-op instead of rejecting it (ocaml/merlin#1544, fixes
ocaml/merlin#1518)
- Traverse aliases when jumping to declaration. This matches
jump-to-definition's behavior (ocaml/merlin#1563)
- Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
ocaml/merlin#1567 and partially ocaml/merlin#1543)
- Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
- Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
fixes ocaml/merlin#1540)
- On Windows, change to a harmless directory when launching server to avoid
locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
+ editor modes
- emacs: Fix misuse of `eq` comparison (ocaml/merlin#1549, @mattiase)
- emacs: xref works from context menus; better highlighting of xref matches;
xref recognises operators and binding operators at the cursor position;
bad locations are filtered out (ocaml/merlin#1385, fixes ocaml/merlin#1410, @mattiase)
+ test suite
- Add a test for incorrect alert defaults (ocaml/merlin#1559)
- Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
- Add non-regression tests for other fixes in this release
CHANGES:
Fri Feb 24 16:55:42 CEST 2023
+ merlin binary
- Update internal typer to match OCaml 4.14.1 release (ocaml/merlin#1557)
- Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
fixes ocaml/merlin#1564)
- Restore compatibility with some OCaml compiler's debug flags that were
incorrectly rejected by Merlin (ocaml/merlin#1556)
- Traverse aliases when jumping to declaration. This matches
jump-to-definition's behavior (ocaml/merlin#1563)
- Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
ocaml/merlin#1567 and partially ocaml/merlin#1543)
- Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
- Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
fixes ocaml/merlin#1540)
- On Windows, change to a harmless directory when launching server to avoid
locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
+ test suite
- Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
- Add non-regression tests for other fixes in this release

On Windows, the process
ocamlmerlin-server.exeis launched with the directory of the current source file as current working directory. This causes problems if one tries to move or delete that directory.To avoid this problem, this PR makes sure to
chdirto a different directory (TMPDIR) before launchingocamlmerlin-server.exe. Note that the same logic already exists for Unix:merlin/src/frontend/ocamlmerlin/ocamlmerlin.c
Lines 314 to 317 in f1b877c
cc @dra27 @MisterDA
Fixes #1474