harry-cpp / code-nautilus

VSCode extension for Nautilus
The Unlicense
419 stars 77 forks source link

Issue with PATH when opening code from this shortcut #30

Open miguel-negrao opened 1 year ago

miguel-negrao commented 1 year ago

If I open vscode via this shortcut, the Haskell language package cannot find the executable ghcup, although it is in the PATH. If If I open vscode normally (via gnome manager) then it finds the program. I'm using debian, where the default system shell is "dash". If I run dash and enter "ghcup" it does find the program.

anujdatar commented 1 year ago

does ghcup run if you run it in bash instead of dash? it may not be in your bashrc path.

miguel-negrao commented 1 year ago

does ghcup run if you run it in bash instead of dash? it may not be in your bashrc path.

Yes, it does run in bash.

anujdatar commented 1 year ago

do you still have this problem? are you using the deb, flatpak or snap package?

harry-cpp commented 1 year ago

How curious, is Nautilus installed as a deb package or a flatpak package?

miguel-negrao commented 1 year ago

Yes, I still have the problem. I just avoid using the nautilus shortcut for haskell coding. This a debian system, I have no flatpak packages installed.

miguel@legion:~$ apt list --installed | grep -e nautilus | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

gir1.2-nautilus-3.0/stable,now 3.38.2-1+deb11u1 amd64 [installed]
libnautilus-extension1a/stable,now 3.38.2-1+deb11u1 amd64 [installed]
nautilus-actions/now 3.2.3-1+b2 amd64 [installed,local]
nautilus-admin/stable,stable,now 1.1.9-3.1 all [installed]
nautilus-data/stable,stable,now 3.38.2-1+deb11u1 all [installed,automatic]
nautilus-extension-brasero/stable,now 3.12.2-6 amd64 [installed]
nautilus-extension-gnome-terminal/stable,now 3.38.3-1 amd64 [installed,automatic]
nautilus-sendto/stable,now 3.8.6-3.1 amd64 [installed,automatic]
nautilus/stable,now 3.38.2-1+deb11u1 amd64 [installed]
python3-nautilus/stable,now 1.2.3-3+b1 amd64 [installed,automatic]
anujdatar commented 1 year ago

hmm.. could you try one thing for me, if you haven't tried it already? use the full path of the your VS Code binary in the extension's py file?

update line 13 in code-nautilus.py with the result from which code https://github.com/harry-cpp/code-nautilus/blob/master/code-nautilus.py#L13

# replace
VSCODE = 'code'

# with
VSCODE = '/usr/bin/code'
# or
VSCODE='/usr/share/code/bin/code'
VSCODE='/var/lib/snapd/snap/bin/code'
VSCODE='/snap/bin/code'
VSCODE='/var/lib/flatpak/exports/bin/com.visualstudio.code'
# or whatever your location is
anujdatar commented 1 year ago

Okay, so I recreated the issue, and might have a temporary fix. You can probably ignore my previous message. That does not work.

So I installed ghcup from the official website: https://www.haskell.org/ghcup/install/

I installed VS Code using the official deb package. VS Code Insiders using a snap package from snapstore. And, VSCodium using a flatpak. Then I installed the Haskell plugin on all three. Here's what I found.

  1. ghcup didn't work with VSCodium flatpak because of some confinement issue I guess. I believe it should already have full host fs access, but I didn't look into it.

  2. VS Code from the official deb package, and VS Code Insiders snap package (installed in classic mode) both have the problem as you described it.

    • If you open them through terminal or launcher ghcup is discovered.
    • If you open them using the nautilus plugin, they don't discover ghcup
  3. But there is a way around it though. In VS Code, Code-Insiders and VSCodium settings, go to Haskell plugin settings and manually add the Ghcup executable path. This seems to work for all three: deb, snap and flatpak packages.

Screenshot

PS: I am not a Haskell developer, so I don't know if this works for all use cases. It is just something I found.

Edit: I don't know why this is happening, i.e. why ghcup auto discovery won't work if the app is launched from nautilus. That needs further investigation.

miguel-negrao commented 1 year ago

Thanks for looking into this and reproducing the issue ! That was also my fix at the time, but that also breaks using ghcup with dev containers, because in a container it gets installed in a different folder. Since I use dev containers from time to time that is not a very confortable solution. But did you manage to understand what causes the issue ?

anujdatar commented 1 year ago

but that also breaks using ghcup with dev containers

Aah I see. Makes sense. Have you tried using tailored vs-code settings per project? Located in a /<project-path>/.vscode/settings.json? I use this option sometimes to overwrite my global settings for some projects.

{
    "haskell.manageHLS": "GHCup",
    "haskell.ghcupExecutablePath": "/path-to-container-ghcup-exec"
}

I don't know how it works with dev containers. I don't usually use those, ssh remote dev worked in my case though.

But did you manage to understand what causes the issue ?

I haven't tried to work on it yet. But I will keep you posted.

miguel-negrao commented 1 year ago

Aah I see. Makes sense. Have you tried using tailored vs-code settings per project?

ah, right, I could do it that way too.

harry-cpp commented 1 year ago

Whats the PATH variable set to when you launch vscode from the application menu, and what is it set to when you open it from Nautilus?

Also maybe VSCode or Nautilus .dekstop files set something extra so post those as well.

anujdatar commented 1 year ago

Yeah, so you are right, something changes in the path or env when we use Nautilus to launch VS Code. I am using fresh VMs for testing, with the default bash shell.

  1. On Ubuntu 22.04: launching VS Code from Nautilus causes the integrated terminal to use /bin/sh instead of /bin/bash and my path completely changes.
  2. On Fedora 38: my shell and path do not change. Shell stays the same /bin/bash, and my path still has ghcup in it. But VS Code does not discover ghcup anymore. I don't know why.

The default .desktop file for code uses --unity-launch %F. I don't think --unity-launch really does anything in our case, but I tried them both with the plugin anyway. It did not help.

I am pretty sure the culprit here is Nautilus. While I can't find Naultilus' .desktop file to see if there are any variables there, if I launch nautilus from the terminal (just nautilus) everything works fine. Both Ubuntu and Fedora keep my default shell and path, and the Haskell plugin finds ghcup. This works for code and code-insiders via snap, deb, or rpm packages. It sadly did not work for VSCodium which I had installed as a flatpak on both systems.

Edit: I think that is an issue with Flatpak itself. Code and Codium launch with /bin/sh as shell and a different PATH when you use a flatpak. I think you have to change the default shell and use flatpak --host bash/zsh or something. I have not been able to get ghcup to work though.

anujdatar commented 1 year ago

Okay, found nautilus.desktop in /usr/share/applications/org.gnome.Nautilus.desktop. but the exec is just

Exec=nautilus --new-window %U

So I'm not sure what's causing the issue

anujdatar commented 1 year ago

weirdly, i just upgraded my fedora 38 beta to release.. and everything is working just fine.. using the nautilus plugin to launch VSCode finds ghcup.. Ubuntu 22.04 does not.. 🤷