lsp-rf.el (5949B)
1 ;;; lsp-rf.el --- description -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020 emacs-lsp maintainers 4 5 ;; Author: emacs-lsp maintainers 6 ;; Keywords: lsp, rf, robot 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 ;; LSP Clients for the Robot Framework. 24 25 ;;; Code: 26 27 (require 'lsp-mode) 28 29 (defgroup lsp-rf nil 30 "Settings for Robot Framework Language Server." 31 :group 'lsp-mode 32 :link '(url-link "https://github.com/tomi/vscode-rf-language-server")) 33 34 (defcustom lsp-rf-language-server-start-command '("~/.nvm/versions/node/v9.11.2/bin/node" "~/.vscode/extensions/tomiturtiainen.rf-intellisense-2.8.0/server/server.js") 35 "Path to the server.js file of the rf-intellisense server. 36 Accepts a list of strings (path/to/interpreter path/to/server.js)" 37 :type '(list string) 38 :group 'lsp-rf) 39 40 (defcustom lsp-rf-language-server-include-paths [] 41 "An array of files that should be included by the parser. 42 Glob patterns as strings are accepted (eg. *.robot between double quotes)" 43 :type 'lsp-string-vector 44 :group 'lsp-rf) 45 46 (defcustom lsp-rf-language-server-exclude-paths [] 47 "An array of files that should be ignored by the parser. 48 Glob patterns as strings are accepted (eg. *bad.robot between double quotes)" 49 :type 'lsp-string-vector 50 :group 'lsp-rf) 51 52 (defcustom lsp-rf-language-server-dir "~/.vscode/extensions/tomiturtiainen.rf-intellisense-2.8.0/server/library-docs/" 53 "Libraries directory for libraries in `lsp-rf-language-server-libraries'" 54 :type 'string 55 :group 'lsp-rf) 56 57 (defcustom lsp-rf-language-server-libraries ["BuiltIn-3.1.1" "Collections-3.0.4"] 58 "Libraries whose keywords are suggested with `auto-complete'." 59 :type '(repeat string) 60 ;; :type 'lsp-string-vector 61 :group 'lsp-rf) 62 63 (defcustom lsp-rf-language-server-log-level "debug" 64 "What language server log messages are printed." 65 :type 'string 66 ;; :type '(choice (:tag "off" "errors" "info" "debug")) 67 :group 'lsp-rf) 68 69 (defcustom lsp-rf-language-server-trace-server "verbose" 70 "Traces the communication between VSCode and the rfLanguageServer service." 71 :type 'string 72 ;; :type '(choice (:tag "off" "messages" "verbose")) 73 :group 'lsp-rf) 74 75 (defun parse-rf-language-server-library-dirs (dirs) 76 (vconcat (mapcar 77 (lambda (x) 78 (concat 79 (expand-file-name 80 lsp-rf-language-server-dir) 81 x 82 ".json")) 83 dirs))) 84 85 (defun expand-start-command () 86 (mapcar 'expand-file-name lsp-rf-language-server-start-command)) 87 88 (defun parse-rf-language-server-globs-to-regex (vector) 89 "Convert a VECTOR of globs to a regex." 90 (--> (mapcan #'lsp-glob-to-regexps vector) 91 (s-join "\\|" it) 92 (concat "\\(?:" it "\\)"))) 93 94 (defun parse-rf-language-server-include-path-regex (vector) 95 "Creates regexp to select files from workspace directory." 96 (let ((globs (if (eq vector []) 97 ["*.robot" "*.resource"] 98 vector))) 99 (parse-rf-language-server-globs-to-regex globs))) 100 101 (defun parse-rf-language-server-exclude-paths (seq) 102 "Creates regexp to select files from workspace directory." 103 (if (eq lsp-rf-language-server-exclude-paths []) 104 seq 105 (cl-delete-if (lambda (x) (string-match-p 106 (parse-rf-language-server-globs-to-regex 107 lsp-rf-language-server-exclude-paths) 108 x)) 109 seq))) 110 111 (lsp-register-custom-settings 112 '( 113 ("rfLanguageServer.trace.server" lsp-rf-language-server-trace-server) 114 ("rfLanguageServer.logLevel" lsp-rf-language-server-log-level) 115 ("rfLanguageServer.libraries" lsp-rf-language-server-libraries) 116 ("rfLanguageServer.excludePaths" lsp-rf-language-server-exclude-paths) 117 ("rfLanguageServer.includePaths" lsp-rf-language-server-include-paths))) 118 119 (lsp-register-client 120 (make-lsp-client :new-connection (lsp-stdio-connection 121 (expand-start-command)) 122 :major-modes '(robot-mode) 123 :server-id 'rf-intellisense 124 ;; :library-folders-fn (lambda (_workspace) 125 ;; lsp-rf-language-server-libraries) 126 :library-folders-fn (lambda (_workspace) 127 (parse-rf-language-server-library-dirs 128 lsp-rf-language-server-libraries)) 129 :initialized-fn (lambda (workspace) 130 (with-lsp-workspace workspace 131 (lsp--set-configuration 132 (lsp-configuration-section "rfLanguageServer")) 133 (lsp-request "buildFromFiles" 134 (list :files 135 (vconcat 136 (parse-rf-language-server-exclude-paths 137 (directory-files-recursively 138 (lsp--workspace-root workspace) 139 (parse-rf-language-server-include-path-regex 140 lsp-rf-language-server-include-paths)))))))))) 141 142 143 144 (lsp-consistency-check lsp-rf) 145 146 (provide 'lsp-rf) 147 ;;; lsp-rf.el ends here