summaryrefslogtreecommitdiffstats
path: root/modules/plugins/lsp/presets/elixir-ls.nix
blob: e0446f84f35d792854d621948e5236998051e799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
  config,
  lib,
  pkgs,
  ...
}: let
  inherit (lib.modules) mkIf;
  inherit (lib.nvim.types) mkLspPresetEnableOption;
  inherit (lib.meta) getExe;
  inherit (lib.generators) mkLuaInline;

  cfg = config.vim.lsp.presets.elixir-ls;
in {
  options.vim.lsp.presets.elixir-ls = {
    enable = mkLspPresetEnableOption {
      option = "elixir-ls";
      display = "Elixir";
    };
  };

  config = mkIf cfg.enable {
    vim.lsp.servers.elixir-ls = {
      enable = true;
      cmd = [(getExe pkgs.beamPackages.elixir-ls)];
      root_dir = mkLuaInline ''
        function(bufnr, on_dir)
          local fname = vim.api.nvim_buf_get_name(bufnr)
          local matches = vim.fs.find({ 'mix.exs' }, { upward = true, limit = 2, path = fname })
          local child_or_root_path, maybe_umbrella_path = unpack(matches)
          local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path)

          on_dir(root_dir)
        end
      '';
    };
  };
}