Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

vscode-rust extension does not start #143

Closed
pftbest opened this issue Mar 7, 2017 · 32 comments · Fixed by #148
Closed

vscode-rust extension does not start #143

pftbest opened this issue Mar 7, 2017 · 32 comments · Fixed by #148

Comments

@pftbest
Copy link

pftbest commented Mar 7, 2017

Version of VSCode: 1.10.1
Version of the extension: 0.3.10
OS: Linux 4.9.11-1-ARCH x86_64

Description:
vscode-rust extension does not start

Debug console:

[Extension Host] Uncaught Exception:  TypeError: Cannot read property 'toString' of null
[Extension Host] TypeError: Cannot read property 'toString' of null
    at ChildProcess.spawnedProcess.on.code (/home/user/.vscode/extensions/kalitaalexey.vscode-rust-0.3.10/out/src/components/configuration/configuration_manager.js:145:69)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
Cannot read property 'toString' of null: TypeError: Cannot read property 'toString' of null
    at ChildProcess.spawnedProcess.on.code (/home/user/.vscode/extensions/kalitaalexey.vscode-rust-0.3.10/out/src/components/configuration/configuration_manager.js:145:69)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Output of the "Rust logging" channel:

I don't have it.
@KalitaAlexey
Copy link
Member

@pftbest,
It is interesting.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

Yes, strage, it was working great until recently. I think I just updated rust nightly and updated racer.

@KalitaAlexey
Copy link
Member

@pftbest,
It worked before?
Until which version?

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

Yes it worked before. I don't know what versions I was using. Now with latest nightly and latest racer it doesn't work.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

I suspect that racer may be crashing, but I don't know for sure, because I don't see any logs. The only log I have is this error in developer console.

@KalitaAlexey
Copy link
Member

@pftbest,
It isn't related to any tools except my extension and Visual Studio Code.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

I tried stating code from the terminal and it works. When I start it from desktop icon it does not work.
So maybe it doesn't like my $PATH ?

@KalitaAlexey
Copy link
Member

@pftbest,
Oh yes. It does.
I don't quite remember why.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

So how do I fix it? it was working before, and I don't remember changing anything

@KalitaAlexey
Copy link
Member

It worked by starting VSCode from desktop?

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

Yes, I always started it from desktop. I just checked RustyCode and it works from desktop, but this extension doesn't work.

@KalitaAlexey
Copy link
Member

@pftbest,
I'll try to find a problem.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

Ok, I tried to debug the extension using vscode and when I start it from debugger it fails only in 50% of launches. So it is intermittent, and maybe that is why I didn't notice it for so long.
I tried older versions and I think 0.3.6 always works, but 0.3.7 is sometimes failing. So the issue is probably somewhere in between.

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

Found the commit:
e7ee78b -> works 10/10
8959ce6 -> fails 50%

@KalitaAlexey
Copy link
Member

@pftbest,
I know that, but I don't get it why.

@KalitaAlexey
Copy link
Member

@pftbest,
How do you run it from Desktop?

@pftbest
Copy link
Author

pftbest commented Mar 7, 2017

How do you run it from Desktop?

It is pinned in KDE 5 TaskBar

Strange thing that it was working yesterday the whole evening. Today in the morning I did rustup update and cargo install --force racer. And now it doesn't work. I don't think I updated the extension and I certainly did not update vscode.

@KalitaAlexey
Copy link
Member

For some reason, I am no longer able to debug the extension.
I have opened an issue:
microsoft/vscode#22201

@pftbest
Copy link
Author

pftbest commented Mar 9, 2017

I know what is happening. stdout is asynchronous, so it may not be ready when exit is called.
To test this i changed the code to look like this:

            spawnedProcess.stdout.on('data', (data) => {
                console.log(`stdout: ${data}`);
            });
            spawnedProcess.on('exit', code => {
                console.log(`exit code: ${code}`);
            });

When I run it, sometimes I see the logs in normal order:

stdout: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu
exit code: 0

But sometimes they are in reverse:

exit code: 0
stdout: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu

@KalitaAlexey
Copy link
Member

It is interesting.

@pftbest
Copy link
Author

pftbest commented Mar 9, 2017

nodejs documentation even has a warning about this:

Note that when the 'exit' event is triggered, child process stdio streams might still be open.

@KalitaAlexey
Copy link
Member

@pftbest,
I, as all we, don't read the documentation.
It is intersting note.

@pftbest
Copy link
Author

pftbest commented Mar 9, 2017

This change works for me. I am using close event instead of exit because it happens after stdio is closed.
I'm not a javascript programmer so you can probably rewrite it better.

--- a/src/components/configuration/configuration_manager.ts
+++ b/src/components/configuration/configuration_manager.ts
@@ -195,14 +195,17 @@ export class ConfigurationManager {

         const spawnedProcess = spawn('rustc', args, options);

+        var sysroot = '';
+
         return new Promise<string | undefined>(resolve => {
             spawnedProcess.on('error', () => {
                 resolve(undefined);
             });
-            spawnedProcess.on('exit', code => {
-                if (code === 0) {
-                    const sysroot = spawnedProcess.stdout.read().toString().trim();
-
+            spawnedProcess.stdout.on('data', data => {
+                sysroot = data.toString().trim();
+            });
+            spawnedProcess.on('close', code => {
+                if (code === 0 && sysroot) {
                     resolve(sysroot);
                 } else {
                     resolve(undefined);

@KalitaAlexey
Copy link
Member

It will try to find a solution.
Thank you for your observation.

@amilajack
Copy link

amilajack commented Mar 13, 2017

Correct me if i'm wrong. I think i'm experiencing something similar. My autocomplete isnt working. I clicked on the 'Install Rust Tools' yellow text in the bottom right corner and after a while, the packages finished installing. But i didnt notice any difference in the IDE suggestions. Any idea what's causing this?

screen shot 2017-03-12 at 9 26 37 pm

Compared to rusty-code's screenshot, the suggestions seem to be a bit off.

@KalitaAlexey
Copy link
Member

@amilajack,
Did you restart VSCode after installing?

@amilajack
Copy link

amilajack commented Mar 13, 2017

Yea, clicked the reload icon. That didn't work so I I closed it and reopened it manually. I should also note my vscode config:

{
  "rust.racerPath": null,
  "rust.rustfmtPath": null,
  "rust.rustsymPath": null,
  "rust.rustLangSrcPath": null,
  "rust.showOutput": true,
  "rust.cargoPath": null,
  "rust.cargoHomePath": null,
  "rust.cargoEnv": null,
  "rust.cargoCwd": null,
  "rust.executeCargoCommandInTerminal": false,
  "rust.actionOnStartingCommandIfThereIsRunningCommand": "Stop running command",
  "rust.actionOnSave": null,
  "rust.buildArgs": [],
  "rust.checkArgs": [],
  "rust.clippyArgs": [],
  "rust.runArgs": [],
  "rust.testArgs": [],
  "rust.customBuildConfigurations": [
    {
      "title": "Release",
      "args": [
        "--release"
      ]
    }
  ],
  "rust.customCheckConfigurations": [
    {
      "title": "Release",
      "args": [
        "--release"
      ]
    }
  ],
  "rust.customClippyConfigurations": [],
  "rust.customRunConfigurations": [
    {
      "title": "Release",
      "args": [
        "--release"
      ]
    }
  ],
  "rust.customTestConfigurations": [
    {
      "title": "Release",
      "args": [
        "--release"
      ]
    }
  ],

  // Rust Language Server configuration
  "rust.rls": null,
}

@KalitaAlexey
Copy link
Member

@amilajack,
After installing you should have restarted VSCode via closing and opening a window.
I have some problems to fix, after them I will clarify what to do.

@amilajack
Copy link

@KalitaAlexey I updated my comment to add my config. Hopefully that helps you with debugging

@amilajack
Copy link

I just noticed a small button saying 'Racer crashed':

screen shot 2017-03-12 at 10 02 02 pm

@KalitaAlexey
Copy link
Member

@amilajack,
I am unsure whether " repeated 2 times is okay.
I will look what can I do.
If you want to workaround right now, you can set rust.rustLangSrcPath.

@KalitaAlexey
Copy link
Member

Open a new issue for that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants