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

Direnv seems to set path a bit too late for other extensions to pick up #109

Open
arianvp opened this issue Apr 19, 2022 · 25 comments
Open
Labels
bug Something isn't working

Comments

@arianvp
Copy link

arianvp commented Apr 19, 2022

I noticed that say if I open vscode and I have a go file open; that visual studio code complains that it can't find the go binary eventhough it is in my direnv file. If I open vscode but the first file that gets loaded is not a .go file but say a .md file then I do not get the error and if I then open a go file it can find the go binary and language server works.

I often fix this scenario by closing all go files; opening an unrelated file, and then run Reload window to reload the direnv plugin. so that the other plugins pick up the paths that direnv plugin set.

It seems as if the direnv plugin gets loaded too late. I don't know if this is something that we can influence but it's a bit of an annoying bug to work around.

@mkhl
Copy link
Contributor

mkhl commented Apr 20, 2022

thanks for the report, sadly load order is not something we really have influence over: we're already asking to be activated as early as possible.

fwiw vscode logs when and why it activates which extensions: in the bottom panel, in the Output tab, select Log (Extension Host) in the dropdown on the right.

oh and just to make sure: you're using the latest version of the extension, which prompts you to restart extensions after the environment generated in your .envrc changes, and that doesn't help?

if you close all windows, Reload window, wait until direnv is done, and then load a go source file, does that work as well, or is the intermediate unrelated file necessary?

@ivan770
Copy link

ivan770 commented Sep 8, 2022

Hi! I've been encountering the same problem.

you're using the latest version of the extension, which prompts you to restart extensions after the environment generated in your .envrc changes, and that doesn't help?

Version 0.6.1, extension sometimes prompts about the restart, but if the environment isn't changed overall that won't happen.

if you close all windows, Reload window, wait until direnv is done, and then load a go source file, does that work as well, or is the intermediate unrelated file necessary?

No file changes are necessary. The problem can be triggered just by opening some .go files, closing a window and then reopening it again.

@mkhl
Copy link
Contributor

mkhl commented Sep 16, 2022

i haven't managed to reproduce this yet but i'll keep trying

@arianvp
Copy link
Author

arianvp commented Sep 17, 2022 via email

@mkhl
Copy link
Contributor

mkhl commented Oct 2, 2022

sorry, i thought i had replied already 😔

I'll see if i can make a video if that helps

that would be great, thanks!

@andronat
Copy link

andronat commented Apr 3, 2023

It's quite often the case for me when I'm using direnv-vscode v0.10.1 with rust-lang.rust-analyzer v0.3.1459 that rust-analyzer fails as direnv is not loaded early enough. For me to fix this issue, I disable rust-lang.rust-analyzer, vscode needs to be restarted, then I re-enable rust-lang.rust-analyzer and everything works.

@diego-vicente
Copy link

@andronat just in case it can be useful to you, I am able to "gain enough time" for direnv-vscode to load if I make sure that the first file that opens in a project window is not a Golang one. In your case, instead of disabling the extension, maybe is easier to just open a non-Rust file (Markdown, .gitignore, whatever) and just re-open the window.

@georgefst
Copy link

I've just switched to using this extension after nix-env-selector stopped working (arrterian/nix-env-selector#80). I never had this sort of issue there. Instead the whole of VSCode would seem to freeze until that extension had finished initialising the environment. It may be worth looking at their source to see what was being done differently.

@andronat just in case it can be useful to you, I am able to "gain enough time" for direnv-vscode to load if I make sure that the first file that opens in a project window is not a Golang one.

This does actually seem to reliably work! At least for language servers which don't start until a relevant source file is viewed (e.g. Haskell works, but I haven't tested Rust yet, which starts earlier in the background). Anyway, obviously it's still not ideal.

@mkhl
Copy link
Contributor

mkhl commented Apr 17, 2023

Could y'all try the build attached at https://github.com/direnv/direnv-vscode/actions/runs/4722972778 and check if it improves things, and if it doesn't attach the contents of that window's "Extension Host" Output log?
I'm still trying to figure out how much blocking during activation we need/can get away with…

@georgefst
Copy link

georgefst commented Apr 17, 2023

No visible difference. I still have to wait before opening a Haskell file, to avoid Could not find a HLS binary at haskell-language-server! (direnv+nix provides the binary, and it all works if I wait).

2023-04-17 16:39:52.627 [info] Extension host with pid 11023 started
2023-04-17 16:39:52.627 [info] Skipping acquiring lock for /Users/gthomas/Library/Application Support/Code/User/workspaceStorage/f3186ed653cc74f005319af4ae86da0c.
2023-04-17 16:39:52.639 [info] ExtensionService#_doActivateExtension vscode.emmet, startup: false, activationEvent: 'onLanguage'
2023-04-17 16:39:52.647 [info] ExtensionService#_doActivateExtension justusadam.language-haskell, startup: false, activationEvent: 'onLanguage:haskell', root cause: haskell.haskell
2023-04-17 16:39:52.649 [info] ExtensionService#_doActivateExtension eamodio.gitlens, startup: false, activationEvent: 'onView:gitlens.views.repositories'
2023-04-17 16:39:52.737 [info] ExtensionService#_doActivateExtension haskell.haskell, startup: false, activationEvent: 'onLanguage:haskell'
2023-04-17 16:39:52.786 [info] ExtensionService#_doActivateExtension vscode.git-base, startup: false, activationEvent: 'api', root cause: eamodio.gitlens
2023-04-17 16:39:52.821 [info] ExtensionService#_doActivateExtension AntiAntiSepticeye.vscode-color-picker, startup: true, activationEvent: '*'
2023-04-17 16:39:52.822 [info] ExtensionService#_doActivateExtension arturock.gitstash, startup: true, activationEvent: '*'
2023-04-17 16:39:52.829 [info] ExtensionService#_doActivateExtension ms-vscode.test-adapter-converter, startup: true, activationEvent: '*', root cause: hbenl.vscode-test-explorer
2023-04-17 16:39:52.831 [info] ExtensionService#_doActivateExtension mkhl.direnv, startup: true, activationEvent: '*'
2023-04-17 16:39:52.834 [info] ExtensionService#_doActivateExtension vscode.npm, startup: true, activationEvent: 'workspaceContains:package.json'
2023-04-17 16:39:52.848 [info] ExtensionService#_doActivateExtension vscode.git, startup: false, activationEvent: 'api', root cause: eamodio.gitlens
2023-04-17 16:39:52.885 [info] ExtensionService#_doActivateExtension vscode.github, startup: true, activationEvent: '*'
2023-04-17 16:39:52.975 [info] ExtensionService#_doActivateExtension hbenl.vscode-test-explorer, startup: true, activationEvent: '*'
2023-04-17 16:39:53.024 [info] ExtensionService#_doActivateExtension vscode.github-authentication, startup: false, activationEvent: 'onAuthenticationRequest:github'
2023-04-17 16:39:53.469 [info] ExtensionService#_doActivateExtension vscode.microsoft-authentication, startup: false, activationEvent: 'onAuthenticationRequest:microsoft'
2023-04-17 16:39:53.598 [info] Eager extensions activated
2023-04-17 16:39:53.601 [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch, startup: false, activationEvent: 'onStartupFinished'
2023-04-17 16:39:53.603 [info] ExtensionService#_doActivateExtension vscode.merge-conflict, startup: false, activationEvent: 'onStartupFinished'
2023-04-17 16:39:53.606 [info] ExtensionService#_doActivateExtension bradlc.vscode-tailwindcss, startup: false, activationEvent: 'onStartupFinished'
2023-04-17 16:39:53.614 [info] ExtensionService#_doActivateExtension dbaeumer.vscode-eslint, startup: false, activationEvent: 'onStartupFinished'
2023-04-17 16:39:53.629 [info] ExtensionService#_doActivateExtension esbenp.prettier-vscode, startup: false, activationEvent: 'onStartupFinished'
2023-04-17 16:39:53.673 [info] ExtensionService#_doActivateExtension Gruntfuggly.todo-tree, startup: false, activationEvent: 'onStartupFinished'

@mkhl
Copy link
Contributor

mkhl commented Apr 17, 2023

Thanks

@mkhl
Copy link
Contributor

mkhl commented Apr 17, 2023

@georgefst
Copy link

Yep, that works! Awesome, thanks.

@mkhl mkhl closed this as completed in 70ad990 Apr 17, 2023
@mkhl
Copy link
Contributor

mkhl commented Apr 17, 2023

I assume this is fixed now, feel free to reopen otherwise.
Thanks everyone for reporting and testing!

@arianvp
Copy link
Author

arianvp commented Apr 18, 2023

Unfortunately the issue is still present for me in 0.12.0

Open https://github.com/arianvp/auth in VSCode I still get
image

even though go is in path in the terminal

I can not reopen the issue myself

@arianvp
Copy link
Author

arianvp commented Apr 18, 2023

Logs:

2023-04-18 10:53:20.687 [info] Extension host with pid 46754 started
2023-04-18 10:53:20.687 [info] Skipping acquiring lock for /Users/arian/Library/Application Support/Code/User/workspaceStorage/8f72801095470972a4ee818602e91bb7.
2023-04-18 10:53:20.705 [info] ExtensionService#_doActivateExtension vscode.emmet, startup: false, activationEvent: 'onLanguage'
2023-04-18 10:53:20.709 [info] ExtensionService#_doActivateExtension mkhl.direnv, startup: false, activationEvent: 'onLanguage'
2023-04-18 10:53:20.711 [info] ExtensionService#_doActivateExtension golang.go, startup: false, activationEvent: 'onLanguage:go'
2023-04-18 10:53:20.747 [error] Activating extension golang.go failed due to an error:
2023-04-18 10:53:20.747 [error] undefined
2023-04-18 10:53:20.757 [info] ExtensionService#_doActivateExtension vscode.git-base, startup: true, activationEvent: '*', root cause: vscode.git
2023-04-18 10:53:20.785 [info] ExtensionService#_doActivateExtension vscode.git, startup: true, activationEvent: '*'
2023-04-18 10:53:20.794 [info] ExtensionService#_doActivateExtension vscode.github, startup: true, activationEvent: '*'
2023-04-18 10:53:20.823 [info] Eager extensions activated
2023-04-18 10:53:20.834 [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch, startup: false, activationEvent: 'onStartupFinished'
2023-04-18 10:53:20.835 [info] ExtensionService#_doActivateExtension vscode.merge-conflict, startup: false, activationEvent: 'onStartupFinished'
2023-04-18 10:53:20.980 [info] ExtensionService#_doActivateExtension vscode.github-authentication, startup: false, activationEvent: 'onAuthenticationRequest:github'
2023-04-18 10:53:21.022 [info] ExtensionService#_doActivateExtension vscode.microsoft-authentication, startup: false, activationEvent: 'onAuthenticationRequest:microsoft'

@arianvp
Copy link
Author

arianvp commented Apr 18, 2023

These are the activation events for go:

  "activationEvents": [
    "onLanguage:go",
    "workspaceContains:*.go",
    "workspaceContains:*/*.go",
    "workspaceContains:*/*/*.go",
    "onCommand:go.gopath",
    "onCommand:go.goroot",
    "onCommand:go.tools.install",
    "onCommand:go.locate.tools",
    "onCommand:go.show.commands",
    "onCommand:go.run.modinit",
    "onDebugInitialConfigurations",
    "onDebugResolve:go",
    "onWebviewPanel:welcomeGo",
    "onView:go.test.profile"
  ],

I'm wondering if the:

    "workspaceContains:*.go",
    "workspaceContains:*/*.go",
    "workspaceContains:*/*/*.go",

part is causing issues. as the Haskell language server extension does not have that

@mkhl
Copy link
Contributor

mkhl commented Apr 19, 2023

It would've been too nice I guess…

Can you try the build at https://github.com/direnv/direnv-vscode/actions/runs/4737391176?pr=464 and see if it helps?

@mkhl mkhl reopened this Apr 19, 2023
@arianvp
Copy link
Author

arianvp commented Apr 19, 2023

Unfortunately this did not help.

@jonjonw
Copy link

jonjonw commented Apr 23, 2023

I'm running into a similar issue with the ruby-lsp extension. If anyone has any tips on how to work around this issue please post them!

@mkhl mkhl added the bug Something isn't working label Apr 24, 2023
@Teebor-Choka
Copy link

@andronat just in case it can be useful to you, I am able to "gain enough time" for direnv-vscode to load if I make sure that the first file that opens in a project window is not a Golang one. In your case, instead of disabling the extension, maybe is easier to just open a non-Rust file (Markdown, .gitignore, whatever) and just re-open the window.

This works like magic.

@peterwaller-arm
Copy link

I'm finding that direnv doesn't seem to work with rust-analyzer at the moment. It was working well at some point in the past. In my setup the 'cargo' binary is found via direnv, and the extension fails to find it.

@eikooc
Copy link

eikooc commented Oct 5, 2023

The same situation applies to the Deno language server. When a TS file is opened to start with, this is what is logged:

Error: Could not resolve Deno executable. Please ensure it is available on the PATH used by VS Code or set an explicit "deno.path" setting.

I don't know if this is also relevant, but here are the logs from the TypeScript server as well:

2023-10-05 07:12:53.365 [info] Starting TS Server undefined
2023-10-05 07:12:53.365 [info] Using tsserver from: /nix/store/23lwwdqyjy59i722c8038rrrwlrmz3wb-vscode-1.82.2/lib/vscode/resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-10-05 07:12:53.365 [info] <syntax> Forking...
2023-10-05 07:12:53.365 [info] <syntax> Starting...
2023-10-05 07:12:53.365 [info] <semantic> Forking...
2023-10-05 07:12:53.365 [info] <semantic> Starting...
2023-10-05 07:56:13.687 [error] TSServer exited. Code: null. Signal: SIGTERM
2023-10-05 07:56:13.687 [info] Starting TS Server undefined
2023-10-05 07:56:13.687 [info] Not starting server: disposed undefined
2023-10-05 07:56:14.451 [info] Starting TS Server undefined
2023-10-05 07:56:14.451 [info] Using tsserver from: /nix/store/23lwwdqyjy59i722c8038rrrwlrmz3wb-vscode-1.82.2/lib/vscode/resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-10-05 07:56:14.451 [info] <syntax> Forking...
2023-10-05 07:56:14.451 [info] <syntax> Starting...
2023-10-05 07:56:14.451 [info] <semantic> Forking...
2023-10-05 07:56:14.451 [info] <semantic> Starting...
2023-10-05 07:58:07.487 [error] TSServer exited. Code: null. Signal: SIGTERM
2023-10-05 07:58:07.487 [info] Starting TS Server undefined
2023-10-05 07:58:07.487 [info] Not starting server: disposed undefined
2023-10-05 07:58:27.784 [info] Starting TS Server undefined
2023-10-05 07:58:27.784 [info] Using tsserver from: /nix/store/23lwwdqyjy59i722c8038rrrwlrmz3wb-vscode-1.82.2/lib/vscode/resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-10-05 07:58:27.784 [info] <syntax> Forking...
2023-10-05 07:58:27.784 [info] <syntax> Starting...
2023-10-05 07:58:27.784 [info] <semantic> Forking...
2023-10-05 07:58:27.784 [info] <semantic> Starting...

@EduardoRFS
Copy link

At least for OCaml the issue was that it was accessing process.env right after load and not every time the LSP was executed. This fixes that https://github.com/ocamllabs/vscode-ocaml-platform/pull/1322/files

@thernstig
Copy link

@mkhl would maybe not the proper way be to write an issue on VS Code itself, that the extension host needs an event to signify when the environment is ready, and have some extensions use this in some way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests