Using an Erlang LSP server with Sublime Text 3

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using an Erlang LSP server with Sublime Text 3

Torben Hoffmann
Hi,

I'm trying to get this to work, but I'm running into problems, so I was wondering if others had tried this at any point?

I have posted this in the LSP room for ST on Discord, but that room seems pretty dead…
Looking in the console for ST3 I find a complaint about Rebar (the ancient one, so I'm ignoring that for now) and a problem wrt reading a config file:
Unable to open /Users/torben.hoffmann/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings
Which is a bit confusing because that file is at Packages/User/LSP.sublime-settings. 
This seems to be an LSP problem rather than something to do with the LS I have installed for Erlang.
I'm using ST3 3.2.2, 3211 on Mac Mojave. Happy to provide additional information - at this point I don't know what else to provide.

I'm using this language server for Erlang: github.com/erlang-ls/erlang_ls
But given the nature of the error messages I don't think that is the issue, at least not yet ;-)

Cheers,
Torben

--
Reply | Threaded
Open this post in threaded view
|

Re: Using an Erlang LSP server with Sublime Text 3

Roberto Aloi-6
Hi Torben!

I'm using this language server for Erlang: github.com/erlang-ls/erlang_ls
 
Nice that you are taking Erlang LS for a spin. We haven't tried the server with Sublime text yet, so I gave Sublime I try just now (I think I have all possible editors on my laptop now). Disclaimer: I am not a Sublime user, so take my response with a grain of salt.

Looking in the console for ST3 I find a complaint about Rebar (the ancient one, so I'm ignoring that for now) and a problem wrt reading a config file:
Unable to open /Users/torben.hoffmann/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings
Which is a bit confusing because that file is at Packages/User/LSP.sublime-settings.

I wouldn't worry about that. It seems the LSP Package for Sublime uses a default settings file (the one in [...]/LSP/LSP.sublime-settings)
and one for the user overrides (the one in [...]/User/LSP.sublime-settings).

So, what I did to get the connection to the Erlang LS working:

Preferences -> Package Settings -> LSP -> Settings

Added:

{
    "clients":
    {
        "erlang-ls":
        {
            "command":
            [
                "/path/to/my/erlang_ls", "--transport", "stdio"
            ],
            "enabled": true,
            "languageId": "erlang",
            "scopes":
            [
                "source.erlang"
            ],
            "syntaxes":
            [
                "Packages/Erlang/Erlang.sublime-syntax"
            ]
        }
    }
}

Even if I have `erlang_ls` in my $PATH, I had to use an absolute path. I guess there's some way to pass the correct $PATH to Sublime, but I haven't tried that. Some Sublime user may help with that.
That's all it was required to get things working. One thing I noticed is that, if you open a single .erl file, Sublime will complain about an error during the error initialization.
Instead, you should open the "project" first (i.e. the directory containing your Erlang file), then the file. This seems due to a bug in Erlang LS which always expects a non-null "root path" to be passed during initialization and in Sublime that happens only if you open a directory first. Indeed the LSP protocol specifies that the "root path" can be null, so we will fix that. Fro the time being, please use the workaround.

I will add the above to the Erlang LS README. We should also try to get Erlang LS included in the Sublime LSP Package to ease installation. Contributions are always welcome :)

But given the nature of the error messages I don't think that is the issue, at least not yet ;-)
Now that you are in Erlang LS land, feel free to use the #language-server channel in the Erlanger Slack or our github issue tracker at github.com/erlang-ls/erlang_ls to get in touch!

Best,

Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Using an Erlang LSP server with Sublime Text 3

Torben Hoffmann
Hi Roberto,

Thanks for taking the time to look into this. Sorry about the lag - I'm on a business trip and have been rather busy.

I have tried using your config settings, but I still get the "Unable to open…" error message and there is no Erlang LS in sight when I try to enable it.

At this point I'm suspecting that this is a problem between Sublime and LSP, so I'll try to get some help on that.
I will report back with my findings.

Cheers,
Torben

On Sat, 18 Jan 2020 at 20:52, Roberto Aloi <[hidden email]> wrote:
Hi Torben!

I'm using this language server for Erlang: github.com/erlang-ls/erlang_ls
 
Nice that you are taking Erlang LS for a spin. We haven't tried the server with Sublime text yet, so I gave Sublime I try just now (I think I have all possible editors on my laptop now). Disclaimer: I am not a Sublime user, so take my response with a grain of salt.

Looking in the console for ST3 I find a complaint about Rebar (the ancient one, so I'm ignoring that for now) and a problem wrt reading a config file:
Unable to open /Users/torben.hoffmann/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings
Which is a bit confusing because that file is at Packages/User/LSP.sublime-settings.

I wouldn't worry about that. It seems the LSP Package for Sublime uses a default settings file (the one in [...]/LSP/LSP.sublime-settings)
and one for the user overrides (the one in [...]/User/LSP.sublime-settings).

So, what I did to get the connection to the Erlang LS working:

Preferences -> Package Settings -> LSP -> Settings

Added:

{
    "clients":
    {
        "erlang-ls":
        {
            "command":
            [
                "/path/to/my/erlang_ls", "--transport", "stdio"
            ],
            "enabled": true,
            "languageId": "erlang",
            "scopes":
            [
                "source.erlang"
            ],
            "syntaxes":
            [
                "Packages/Erlang/Erlang.sublime-syntax"
            ]
        }
    }
}

Even if I have `erlang_ls` in my $PATH, I had to use an absolute path. I guess there's some way to pass the correct $PATH to Sublime, but I haven't tried that. Some Sublime user may help with that.
That's all it was required to get things working. One thing I noticed is that, if you open a single .erl file, Sublime will complain about an error during the error initialization.
Instead, you should open the "project" first (i.e. the directory containing your Erlang file), then the file. This seems due to a bug in Erlang LS which always expects a non-null "root path" to be passed during initialization and in Sublime that happens only if you open a directory first. Indeed the LSP protocol specifies that the "root path" can be null, so we will fix that. Fro the time being, please use the workaround.

I will add the above to the Erlang LS README. We should also try to get Erlang LS included in the Sublime LSP Package to ease installation. Contributions are always welcome :)

But given the nature of the error messages I don't think that is the issue, at least not yet ;-)
Now that you are in Erlang LS land, feel free to use the #language-server channel in the Erlanger Slack or our github issue tracker at github.com/erlang-ls/erlang_ls to get in touch!

Best,

Roberto



--