From d9ff1b000baeee10848b03b55b334628535e9cc8 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sat, 11 Apr 2026 17:48:42 +0200 Subject: [PATCH] lsp/presets/phan: init --- modules/plugins/lsp/presets/default.nix | 1 + modules/plugins/lsp/presets/phan.nix | 45 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 modules/plugins/lsp/presets/phan.nix diff --git a/modules/plugins/lsp/presets/default.nix b/modules/plugins/lsp/presets/default.nix index 1615ef5e..7d6a99da 100644 --- a/modules/plugins/lsp/presets/default.nix +++ b/modules/plugins/lsp/presets/default.nix @@ -4,6 +4,7 @@ ./deno.nix ./harper.nix ./lemminx.nix + ./phan.nix ./phpactor.nix ./pyrefly.nix ./pyright.nix diff --git a/modules/plugins/lsp/presets/phan.nix b/modules/plugins/lsp/presets/phan.nix new file mode 100644 index 00000000..281da772 --- /dev/null +++ b/modules/plugins/lsp/presets/phan.nix @@ -0,0 +1,45 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.options) mkEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.phan; +in { + options.vim.lsp.presets.phan = { + enable = mkEnableOption "the Phan Language Server"; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.phan = { + enable = true; + cmd = [ + (getExe pkgs.php85Packages.phan) + "-m" + "json" + "--no-color" + "--no-progress-bar" + "-x" + "-u" + "-S" + "--language-server-on-stdin" + "--allow-polyfill-parser" + ]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + local cwd = assert(vim.uv.cwd()) + local root = vim.fs.root(fname, { 'composer.json', '.git' }) + + -- prefer cwd if root is a descendant + on_dir(root and vim.fs.relpath(cwd, root) and cwd) + end + ''; + }; + }; +}