rescript-lang / rescript-vscode

Official VSCode plugin for ReScript
MIT License
324 stars 55 forks source link

Compiler is killed when switching between previewed files #541

Open Minnozz opened 2 years ago

Minnozz commented 2 years ago

vscode v1.69.2 rescript-vscode v1.5.11

Reproduce:

After starting a build via the popup:

❯ ps aux | grep rescript
bart.sc+  389111  2.5  0.5 21417852 78388 ?      Sl   10:10   0:00 /nix/store/5i1zfmhk46dwl94jfp82lacyi5fk06f5-vscode-1.69.2/lib/vscode/code --ms-enable-electron-run-as-node /home/bart.schuurmans/.vscode/extensions/chenglou92.rescript-vscode/server/out/server.js --node-ipc --clientProcessId=389080
bart.sc+  389337  0.6  0.2 321984 36596 ?        Sl   10:10   0:00 node /home/bart.schuurmans/engineering/lumi/frontend/provisioner/node_modules/.bin/rescript build -w

After switching to a different file in the same project, the compiler is no longer running:

❯ ps aux | grep rescript
bart.sc+  389111  0.5  0.5 21417852 79356 ?      Sl   10:10   0:00 /nix/store/5i1zfmhk46dwl94jfp82lacyi5fk06f5-vscode-1.69.2/lib/vscode/code --ms-enable-electron-run-as-node /home/bart.schuurmans/.vscode/extensions/chenglou92.rescript-vscode/server/out/server.js --node-ipc --clientProcessId=389080

The popup to start a new build is also shown now.

strace of the rescript build -w process during switching:

[pid 389337] --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=389111, si_uid=1000} ---
+++ exited with 0 +++
Minnozz commented 2 years ago

The compiler is started here: https://github.com/rescript-lang/rescript-vscode/blob/b16d87a8c2f33a65001d753ff3e457baf1d77f79/server/src/server.ts#L1191-L1196 And it is killed here when there are no more open files: https://github.com/rescript-lang/rescript-vscode/blob/b16d87a8c2f33a65001d753ff3e457baf1d77f79/server/src/server.ts#L341-L364 Maybe the order in which the old file is closed and the new file is opened has changed in vscode?

Minnozz commented 2 years ago

I found the issue: when you open a file in vscode but don't edit it (by single clicking in the sidebar), it is shown in italics in the tab bar and wil auto-close when you open a different file. Auto-closing happens before the new file is opened, so there is a brief moment when there are 0 files open in the project.

cristianoc commented 2 years ago

Would you say that this behaviour is to be expected? Seems kind of borderline.

Minnozz commented 2 years ago

It is certainly defendable, knowing what the cause is, but also annoying. When you don't start a build and are just browsing files in this way, each new file also triggers the "Do you want to start a build"-popup again.

I think it would be fixable by destructing the state on a small timeout after the last file has been closed, that is cancelled when a new file is opened within the timeout window. This would make the logic more complex though.

cristianoc commented 2 years ago

I think longer term we are probably heading towards a model where that pop up does not show.

@zth what do you think?

zth commented 2 years ago

Yeah I think we need to figure out if we really want to continue supporting running the compiler from the extension, and if we do we probably need to overhaul the experience around it.

I'd like to know if it's common to use that pop-up at all today. Maybe something to ask on the forums.

Minnozz commented 2 years ago

FWIW, I was under the impression that running a compiler separately from the extension would interfere with the functioning of the language server (see this question on the forum). In debugging this issue, I discovered that using the popup does nothing special compared to running the compiler manually. We might want to clarify in the docs how those two things interact and what your options are as a developer.

jmagaram commented 1 year ago

I think I've been running into this problem. Each time I single click on a .res file I get a "Do you want to start a build to get the freshest data?" message. As soon as I double-click on a file and have at least one open, this message stops popping up. But as soon as I close every .res file, which I do when I'm done editing some files, then the next time I open a .res I get that annoying popup again. What is the recommended workflow here? Do I need to have a build always going in watch mode? Or can I count on the extension to do my builds when necessary?

jmagaram commented 1 year ago

Even if I run a build -w the extension still asks "Do you want to start a build to get the freshest data?" when I open my first .res file. Super annoying and a very poor user experience for people just getting started with ReScript. I don't know what the solution is here but think the Getting Started docs need to explain the recommended workflow.

fhammerschmidt commented 1 year ago

@zth I think the logic that relies on the existence of a .bsb.lock is flawed, since this lockfile is very short-lived. After a successful build cycle, even in watch mode, it gets deleted which results in a build prompt despite the build being "fresh".