golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.84k stars 735 forks source link

vscode installed from flatpak fails to access the default go installation location /usr/local/go #3063

Open TheUncleRemus opened 9 months ago

TheUncleRemus commented 9 months ago

proposal

I have published a simple repo for go-vscode configuration when vscode is installed from flatpak. You can to reach the repo at this link:

https://github.com/TheUncleRemus/flapak-vscode-as-go-ide.git

Can you consider this configuration as proposal?

Thx!

hyangah commented 9 months ago

@TheUncleRemus Thanks for sharing your setup to workaround. Are you proposing to add this to a doc?

It looks like the key is to install go in a location flatpak allows vscode to access and make the extension know about the location.

TheUncleRemus commented 9 months ago

Hi @hyangah yes! The key is to install go to a custom path that is "visible" to flatpak sandbox

My proposal can be:

thx. :)

hyangah commented 9 months ago

The suggestion is:

"go.alternateTools": { "go": "<path_to_go_binary>" }
TheUncleRemus commented 9 months ago

Hi @hyangah , my objection points are:

hyangah commented 9 months ago

@TheUncleRemus if it is about using go with other flatpak app, is there any flatpak community that can host the doc and review the contents?

TheUncleRemus commented 9 months ago

Hi @hyangah , I have checked your configuration and I confirm to you that it doesn't works! If you want to setup the go-configuration vscode-side, the minimum setup that works fine is:

{
    "go.alternateTools": {
        "go": "<path_to_go_bin>"
    },
    "go.goroot": "<path_to_goroot>",
    "go.gopath": "<path_to_go_bin>"
}

In every way...

thx

hyangah commented 9 months ago

Can you tell us more details what doesn't work? go.goroot is GOROOT envvar which we don't recommend to configure with recent go except a few exceptions. go.gopath is GOPATH envvar and path to go binary shouldn't be the right value.

We can add a section in faq or advanced setting doc to mention your link, but we don't want to ask users to run a shell script that we don't understand or manage.

TheUncleRemus commented 9 months ago

Hi @hyangah , yeah, correct! I means just this! When you run vscode by flatpak, your vscode run insiede in a sandbox and the environemnt variables like $PATH are differet!

from the flatpak documentation Description. Flatpak is a tool for managing applications and the runtimes they use. In the Flatpak model, applications can be built and distributed independently from the host system they are used on, and they are isolated from the host system ('sandboxed') to some degree, at runtime.

In fact if you see the error tooltip in vscode the value of the printed $PATH is not uquals to the $PATH environment variable host-wide.

For this reason I have opened this thred. In summary:

After that you can use your go instalaltion inside your vscode and the go instalaltion strictly depends by $GOROOT env setupped as showed above. But you must be warry up because if you use go from the outside of vscode and go inside of vscode, you have two differetn set of the go-environment variables - except for the $GOROOT - (one of for the host-wide and one of for the flatpak-side. As showed in the GOBIN*.png figures)

from the host terminal

go env 

GOBIN_host-side

from the vscode terminal

go env

GOBIN

For this reason in my opinion a solid documentation will be useful for the user, also because I had read this thred and there are confusing opinion.

Appendix: tooltip error in vscode configuration

Schermata del 2023-12-01 14-08-54

Schermata del 2023-12-01 14-10-24

If you want I can suppor to to you for docs pull requst.

I apologize for the hentropic text :)

TheUncleRemus commented 9 months ago

@hyangah do you have any updates?

hyangah commented 8 months ago

Thanks for sharing the screenshots. From the screenshots, I guess the settings were not configured correctly.

"go.alternateTools": { "go": ... } should point to the path to the exact binary, not its directory. I assume ~/.golang/go/bin is a directory.

Moreover, is your "go" command located in ~/.golang/go/bin? You seemed to configure GOPATH ("go.gopath") to be the same directory. That's very unusual. For the meaning of GOPATH, see https://pkg.go.dev/cmd/go#hdr-GOPATH_environment_variable and https://pkg.go.dev/cmd/go#hdr-GOPATH_and_Modules. I admit the official doc is a bit confusing, but it's historically used to set up a project workspace.

Can you try to fix the configuration errors and come up with a minimal configuration?

TheUncleRemus commented 8 months ago

Hi @hyangah , don't focus to screenshots, because the point is not: "how can I configure my vscode for golang". The point is: "How can I configure my flatpak vscode for golang".

The point is not: the collision between he GOPATH var and vscode go configuration (the screenshoots are misleading). The point is: have you a documentation section that describe this situation? Thus, your documentation describe the scenario when vscode is installed from flatpak (the answear is: no!).

Yes, I known, this is not a vscode "problem" or a go problem, but with the new era (potentially) of immutable OS, this scenario could be recurring.

I then I open this "issue" to propose an additional section to your doc. useful to describe this scenario.

hyangah commented 8 months ago

Thanks. But we want to provide accurate info. Please correct errors. Then we are happy to have a place to link. (Wiki). For example, setting GOROOT and GOPATH isn't necessary nowadays and sometimes setting it can lead to confusion. I asked to test if they can be avoided, but it looks like the option wasn't tested correctly.

On Wed, Jan 10, 2024, 9:23 AM TheUncleRemus @.***> wrote:

Hi @hyangah https://github.com/hyangah , don't focus to screenshots, because the point is not: "how can I configure my vscode for golang". The point is: "How can I configure my flatpak vscode for golang".

The point is not: the collision between he GOPATH var and vscode go configuration (the screenshoots are misleading). The point is: have you a documentation section that describe this situation? Thus, your documentation describe the scenario when vscode is installed from flatpak (the answear is: no!).

Yes, I known, this is not a vscode "problem" or a go problem, but with the new era (potentially) of immutable OS, this scenario could be recurring.

I then I open this "issue" to propose an additional section to your doc. useful to describe this scenario.

— Reply to this email directly, view it on GitHub https://github.com/golang/vscode-go/issues/3063#issuecomment-1884945750, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGESL3KQQ3XN324H2AC4XTYN2P77AVCNFSM6AAAAAA72AYXJCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBUHE2DKNZVGA . You are receiving this because you were mentioned.Message ID: @.***>

TheUncleRemus commented 8 months ago

@hyangah onestly I don't understand. The point, for me, is: if you have this environment

You can configure your vscode what you want, but it doesn't work...

If you want a "green" setup (using flatpak), you need:

I don't have any other suggestions to you. If you want you can consider my observations useful to enrich your vscode docs, otherwise I don't know 😅😁

TuR