Lexical - A Language Server for Elixir

Good idea. Here it is: Add instructions for LunarVim installation by dimitarvp · Pull Request #510 · lexical-lsp/lexical · GitHub

1 Like

Just found out that lexical does not yet support listing symbols in the current file and in the workspace. That’s a deal breaker for the moment. I’ll wait until that feature is announced and will then resume using lexical.

2 Likes

Sorry to hear that, but we’ll be adding that once the indexing work is complete.

3 Likes

It looks like this guide along with Lexical’s own installation docs should get things up and running!

I followed that guide but cannot get Lexical to work on Sublime. I get permission denied on a popup when Sublime tries to start Lexical. I can start the script from the command line and the script has executable permissions for everyone:

$   ls -al ~/Downloads/lexical/_build/dev/package/lexical/bin
total 32
drwxr-xr-x@ 6 exadra37  staff   192B  3 Jan 16:20 .
drwxr-xr-x@ 7 exadra37  staff   224B  3 Jan 16:25 ..
-rwxr-xr-x@ 1 exadra37  staff   1.9K  3 Jan 16:25 activate_version_manager.sh
-rwxr-xr-x@ 1 exadra37  staff   580B  3 Jan 16:25 boot.exs
-rwxr-xr-x@ 1 exadra37  staff   230B  3 Jan 16:25 debug_shell.sh
-rwxr-xr-x@ 1 exadra37  staff   483B  3 Jan 17:00 start_lexical.sh

My LSP settings:

"clients": {
    "elixir-lexical": {
      // enable this configuration
      "enabled": true,
      // the startup command -- what you would type in a terminal
      "command": ["/Users/Exadra37/Downloads/lexical/_build/dev/package/lexical/bin", "start_lexical.sh"],
      // the selector that selects which type of buffers this language server attaches to
      "selector": "source.elixir"
    }
  }

Am i missing something?

There are a couple scripts that lexical needs to have execute permission, ensure all of them have that permission:

./lexical/bin/activate_version_manager.sh
./lexical/bin/debug_shell.sh
./lexical/bin/start_lexical.sh
./lexical/priv/port_wrapper.sh

Did the error have any more information other than permission denied?

The only thing it says is the lack of permission, as per screenshot:

Output from Sublime console:

Unable to start subprocess for elixir-lexical
Traceback (most recent call last):
  File "/Users/exadra37/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 273, in start_async
    transport = create_transport(transport_config, transport_cwd, session)
  File "/Users/exadra37/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 265, in create_transport
    process = start_subprocess()
  File "/Users/exadra37/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 253, in start_subprocess
    return _start_subprocess(config.command, stdin, stdout, subprocess.PIPE, startupinfo, config.env, cwd)
  File "/Users/exadra37/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 339, in _start_subprocess
    cwd=cwd)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1452, in _execute_child
PermissionError: [Errno 13] Permission denied``

All the scripts have executable permissions as per ls -al output I pasted before:

$   ls -al ~/Downloads/lexical/_build/dev/package/lexical/bin
total 32
drwxr-xr-x@ 6 exadra37  staff   192B  3 Jan 16:20 .
drwxr-xr-x@ 7 exadra37  staff   224B  3 Jan 16:25 ..
-rwxr-xr-x@ 1 exadra37  staff   1.9K  3 Jan 16:25 activate_version_manager.sh
-rwxr-xr-x@ 1 exadra37  staff   580B  3 Jan 16:25 boot.exs
-rwxr-xr-x@ 1 exadra37  staff   230B  3 Jan 16:25 debug_shell.sh
-rwxr-xr-x@ 1 exadra37  staff   483B  3 Jan 17:00 start_lexical.sh

There are more executable files than you’ve listed above, which is why I asked. There’s an important file that’s not in the bin directory, which is ./lexical/priv/port_wrapper.sh. Though It would be odd for the permission denied error on that file to bubble up to the editor.

Honestly, that error isn’t super helpful without telling me what it’s trying to execute. Very annoying, sublime.

If you want more real-time help, please pop in to our discord server.

There’s an important file that’s not in the bin directory, which is ./lexical/priv/port_wrapper.sh.

The path doesn’t exist on my repo, but I can find the script at other location wiht executable permissions:

➜  lexical git:(main) l apps/remote_control/priv/
total 8
drwxr-xr-x@  3 exadra37  staff    96B  3 Jan 16:16 .
drwxr-xr-x@ 10 exadra37  staff   320B  8 Jan 16:24 ..
-rwxr-xr-x@  1 exadra37 staff   470B  3 Jan 16:16 port_wrapper.sh

Honestly, that error isn’t super helpful without telling me what it’s trying to execute. Very annoying, sublime.

I will see if I can find more detailed logs.

That file should exist in the _build/dev/package/lexical/priv directory.

Yes, I can see it there, and has executable permissions for everyone:

$ l _build/dev/package/lexical/priv
total 24
drwxr-xr-x@ 5 exadra37  staff   160B  3 Jan 16:20 .
drwxr-xr-x@ 7 exadra37  staff   224B  3 Jan 16:25 ..
-rw-r--r--@ 1 exadra37  staff     6B  3 Jan 16:25 .elixir
-rw-r--r--@ 1 exadra37  staff     6B  3 Jan 16:25 .erlang
-rwxr-xr-x@ 1 exadra37  staff   470B  3 Jan 16:25 port_wrapper.sh

This is indeed weird :thinking:

1 Like

Lexical 0.5 Has been released

This release includes a ton of bugfixes and feature improvements, and debuts our search and indexing framework, which powers find references and go to definition, and will power a host of other features.

Highlights include:

  • Support for elixir version 1.16
  • Handled renaming of rtx to mise
  • Multiple improvements to the hover popup
  • Improved ease of writing new code actions
  • Undefined variables diagnostics error for HEEx templates
  • Code action: Suggested function names
  • Completions for typespecs
  • Improved nix flake

See the full release notes here

17 Likes

Hi, someone else reported issues with Sublime and pointed to your post, so sharing in case someone else also trips over this:

I think your “command” configuration is wrong, you specify the directory as the first item, so Python is trying to run that as an executable with the file name as it’s arguments. I think the first item in that list should be the full path to the start_lexical shell script.

Basically:
"command": ["/Users/Exadra37/Downloads/lexical/_build/dev/package/lexical/bin", "start_lexical.sh"] is trying to do this: /Users/Exadra37/Downloads/lexical/_build/dev/package/lexical/bin start_lexical.sh, which if you try in your shell, probably won’t work.
I think it should be:
"command": ["/Users/Exadra37/Downloads/lexical/_build/dev/package/lexical/bin/start_lexical.sh"]

Hope that helps

1 Like

It’s been a while, but we figured it out.

4 Likes

@dimitarvp Document symbols has been merged into main and I have a draft PR for workspace symbols open.

3 Likes

Very nice, thank you!

Looking forward to the workspace symbols as well and then I’m pretty sure I’ll only use Lexical. :slight_smile:

Since you use workspace symbols, try the branch and give me feedback!

Well, you got your first, and very unhelpful, bug report from me. :smile:

I’m going to expose myself as an LSP ignoramus here:

Lexical gives warnings for files like .iex.exs (unsed aliases and imports) and seeds.exs (could not look up Ecto repo). Is this something the editor integration should be responsible for (I’m thinking ignoring files, though that isn’t ideal) or something to report to Lexical? I was unable to find any discussion in gh issues.

Thanks!

1 Like

Script files (.exs) are a bit tricky in elixir and it’s hard to say without seeing the sources, but for .iex.exs files, you often have and want unused imports and aliases, because that’s the point. You’re setting up an execution environment for iex, not building a “normal” module that should be all neat and tidy.

As for seeds, i’m not sure, I don’t know what you have in there, but it sounds like your ecto repository hasn’t been started, which is normal in a language server. Having the language server connect to the database seems like it would cause a bunch of problems for people.

If you want more detail, either hop into our discord or file an issue on github.

1 Like

Ah, sorry, I was clearly unclear! I understand why the errors are happening and that they are expected and was looking for a way to silence them, ideally without having to disable for the entire file. I’ll open an issue in github. Thanks for your response!!

EDIT: Here’s the issue, thanks!