lsp-nix.el (5706B)
1 ;;; lsp-nix.el --- lsp-mode nix integration -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020 lsp-mode maintainers 4 5 ;; Author: Seong Yong-ju <sei40kr@gmail.com> 6 ;; Keywords: languages 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; Client for the rnix language server. 24 25 ;;; Code: 26 27 (require 'lsp-mode) 28 29 (defgroup lsp-nix-rnix nil 30 "LSP support for Nix, using rnix-lsp." 31 :group 'lsp-mode 32 :link '(url-link "https://github.com/nix-community/rnix-lsp")) 33 34 (defcustom lsp-nix-rnix-server-path "rnix-lsp" 35 "Executable path for the server." 36 :group 'lsp-nix-rnix 37 :type 'string 38 :package-version '(lsp-mode . "8.0.0")) 39 40 (lsp-register-client 41 (make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-nix-rnix-server-path)) 42 :major-modes '(nix-mode nix-ts-mode) 43 :server-id 'rnix-lsp 44 :priority -2)) 45 46 (defgroup lsp-nix-nixd nil 47 "LSP support for Nix, using nixd language server." 48 :group 'lsp-mode 49 :link '(url-link "https://github.com/nix-community/nixd")) 50 51 (defcustom lsp-nix-nixd-server-path "nixd" 52 "Executable path for the server." 53 :group 'lsp-nix-nixd 54 :type 'string 55 :package-version '(lsp-mode . "8.0.0")) 56 57 (lsp-defcustom lsp-nix-nixd-formatting-command nil 58 "External formatter command with arguments. 59 60 Example: `[\"nixpkgs-fmt\"]`" 61 :type 'lsp-string-vector 62 :group 'lsp-nix-nixd 63 :lsp-path "nixd.formatting.command" 64 :package-version '(lsp-mode . "9.0.1")) 65 66 (lsp-defcustom lsp-nix-nixd-nixpkgs-expr nil 67 "This expression will be interpreted as \"nixpkgs\" toplevel 68 Nixd provides package, lib completion/information from it. 69 70 Resource Usage: Entries are lazily evaluated, entire nixpkgs takes 200~300MB 71 for just \"names\". Package documentation, versions, are evaluated by-need. 72 73 Example: `\"import <nixpkgs> { }\"`" 74 :type 'string 75 :group 'lsp-nix-nixd 76 :lsp-path "nixd.nixpkgs.expr" 77 :package-version '(lsp-mode . "9.0.1")) 78 79 (lsp-defcustom lsp-nix-nixd-nixos-options-expr nil 80 "Option set for NixOS option completion. If this is omitted, the default 81 search path (`<nixpkgs>`) will be used. 82 83 Example: 84 `\"(builtins.getFlake \"/home/nb/nix\").nixosConfigurations.mnd.options\"`" 85 :type 'string 86 :group 'lsp-nix-nixd 87 :lsp-path "nixd.options.nixos.expr" 88 :package-version '(lsp-mode . "9.0.1")) 89 90 (lsp-defcustom lsp-nix-nixd-home-manager-options-expr nil 91 "Option set for home-manager option completion. 92 93 Example: 94 `\"(builtins.getFlake \"/home/nb/nix\").homeConfigurations.\"nb@mnd\".options\"`" 95 :type 'string 96 :group 'lsp-nix-nixd 97 :lsp-path "nixd.options.home-manager.expr" 98 :package-version '(lsp-mode . "9.0.1")) 99 100 (lsp-register-client 101 (make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-nix-nixd-server-path)) 102 :major-modes '(nix-mode nix-ts-mode) 103 :initialized-fn (lambda (workspace) 104 (with-lsp-workspace workspace 105 (lsp--set-configuration 106 (lsp-configuration-section "nixd")))) 107 :synchronize-sections '("nixd") 108 :server-id 'nixd-lsp 109 :priority -1)) 110 111 (defgroup lsp-nix-nil nil 112 "LSP support for Nix, using nil." 113 :group 'lsp-mode 114 :link '(url-link "https://github.com/oxalica/nil")) 115 116 (defcustom lsp-nix-nil-server-path "nil" 117 "Executable path for the server." 118 :group 'lsp-nix-nil 119 :type 'string 120 :package-version '(lsp-mode . "9.0.0")) 121 122 (lsp-defcustom lsp-nix-nil-formatter nil 123 "External formatter command with arguments. 124 125 Example [nixpkgs-fmt]." 126 :type 'lsp-string-vector 127 :group 'lsp-nix-nil 128 :lsp-path "nil.formatting.command" 129 :package-version '(lsp-mode . "9.0.0")) 130 131 (lsp-defcustom lsp-nix-nil-ignored-diagnostics nil 132 "Ignored diagnostic kinds." 133 :type 'lsp-string-vector 134 :group 'lsp-nix-nil 135 :lsp-path "nil.diagnostics.ignored" 136 :package-version '(lsp-mode . "9.0.0")) 137 138 (lsp-defcustom lsp-nix-nil-exclude-files-diagnostic nil 139 "Files to exclude from showing diagnostics." 140 :type 'lsp-string-vector 141 :group 'lsp-nix-nil 142 :lsp-path "nil.diagnostics.excludedFiles" 143 :package-version '(lsp-mode . "9.0.0")) 144 (lsp-defcustom lsp-nix-nil-max-mem 10000 145 "Max Memory MB" 146 :type 'number 147 :group 'lsp-nix-nil 148 :lsp-path "nil.nix.maxMemoryMB" 149 :package-version '(lsp-mode . "9.0.0")) 150 (lsp-defcustom lsp-nix-nil-auto-eval-inputs t 151 "Auto Eval Inputs" 152 :type 'boolean 153 :group 'lsp-nix-nil 154 :lsp-path "nil.nix.flake.autoEvalInputs" 155 :package-version '(lsp-mode . "9.0.0")) 156 157 (lsp-register-client 158 (make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-nix-nil-server-path)) 159 :major-modes '(nix-mode nix-ts-mode) 160 :initialized-fn (lambda (workspace) 161 (with-lsp-workspace workspace 162 (lsp--set-configuration 163 (lsp-configuration-section "nil")))) 164 :synchronize-sections '("nil") 165 :server-id 'nix-nil)) 166 167 (lsp-consistency-check lsp-nix) 168 169 (provide 'lsp-nix) 170 ;;; lsp-nix.el ends here