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

How to access binaries in the users PATH from RawCommandServerDefinition #275

Open
buschco opened this issue Sep 21, 2022 · 8 comments
Open
Labels

Comments

@buschco
Copy link

buschco commented Sep 21, 2022

Description:

First of all, thanks for the great work!

I was wondering about what is available in the PATH for the RawCommandServerDefinition.

This is my PreloadingActivity:

class MyPreloadingActivity : PreloadingActivity() {

    override fun preload(indicator: ProgressIndicator) {
        IntellijLanguageClient.addServerDefinition(
            RawCommandServerDefinition(
                "js",
                arrayOf(
                    "node",
                    "node_modules/.bin/my-nodejs-lsp", "--stdio"
                )
            )
        )
    }
}

If I launch Idea with my plugin installed, I get this error:

Can't start server due to Cannot run program "node" (in directory "/Users/colin/Documents/sample-repo"): error=2, No such file or directory
  • As a workaround I can put the absolute path to a node binary instead of node, but this will only work on my machine.

  • Another solution could be, adding a configuration so users will have to put the path to theirs node binary into my plugins config.

What do you think?

Steps to reproduce:

  • Take my PreloadingActivity and try to execute something with node.

Affected Versions: 0.95.0

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@nixel2007
Copy link
Contributor

Ehm. do you have node in your PATH? did you install node via nvm (which adds variables in sh-init scripts) or via package panager of your distro?

@buschco
Copy link
Author

buschco commented Sep 21, 2022

I use nvm. Is the .zshrc not taken into account?

$ which node
/Users/colin/.nvm/versions/node/v16.17.0/bin/node

In my PATH this (/Users/colin/.nvm/versions/node/v16.17.0/bin/node) is also included.

@nixel2007
Copy link
Contributor

Is the .zshrc not taken into account?

Nope, java takes raw path variable, cause it runs process without any shell. You could try to run node via macos analogue of windows' cmd /C node, maybe it'll take zshrc into account

@nixel2007
Copy link
Contributor

In my PATH this ( /Users/colin/.nvm/versions/node/v16.17.0/bin/node ) is also included.

PATH should lead to directory, not a file

@buschco
Copy link
Author

buschco commented Sep 21, 2022

@nixel2007 thanks for your answer.

PATH should lead to directory, not a file

Yes sorry only this part is in my PATH: /Users/colin/.nvm/versions/node/v16.17.0/bin which includes the binaries fornode yarn etc.

...cmd /C node, maybe it'll take zshrc into account

I am not sure what cmd /C node is exactly.

Ok this is harder than I thought. I think the only solution is to add a config so users can add a path to a node binary 😕

I also tried this:

            IntellijLanguageClient.addServerDefinition(
                RawCommandServerDefinition(
                    "js",
                    arrayOf(
                        "sh", "-c", "'node node_modules/.bin/my-nodejs-lsp --stdio'"
                    )
                )
            )

or a similar approach with the ProcessBuilder but had no success either while sh -c 'node node_modules/.bin/my-nodejs-lsp --stdio' works linke a charm from my shell.

@nixel2007
Copy link
Contributor

Try zsh instead of sh in process builder

@buschco
Copy link
Author

buschco commented Sep 22, 2022

Same result. Always Stream closed

WARN - #o.w.l.c.l.w.LanguageServerWrapper - org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Stream closed
java.util.concurrent.ExecutionException: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Stream closed
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)

With the ProcessBuilder method I was not able to start the LSP. Event with the strings that worked fine at RawCommandServerDefinition.

@suarezjulian
Copy link

suarezjulian commented Dec 15, 2022

Facing a similar issue, I've noticed that when I start IntelliJ from command line I have access to the full PATH defined in my .zshrc file, but if I launch IntelliJ from Spotlight in Mac Os (CMD+Space) I only have access to a very barebones PATH which lacks some of the command line utilities my Language Server depends on. I'm sure others have run into this, wondering what would be the best solution

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

No branches or pull requests

3 participants