config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-cucumber.el (3562B)


      1 ;;; lsp-cucumber.el --- LSP Clients for Cucumber  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2024  Shen, Jen-Chieh
      4 
      5 ;; This file is not part of GNU Emacs.
      6 
      7 ;; This program is free software: you can redistribute it and/or modify
      8 ;; it under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation, either version 3 of the License, or
     10 ;; (at your option) any later version.
     11 
     12 ;; This program is distributed in the hope that it will be useful,
     13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;; GNU General Public License for more details.
     16 
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
     19 
     20 ;;; Commentary:
     21 ;;
     22 ;; LSP server implementation for Cucumber
     23 ;;
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-cucumber nil
     30   "LSP server implementation for Cucumber."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/cucumber/language-server"))
     33 
     34 (defcustom lsp-cucumber-server-path nil
     35   "Path points for Cucumber language server.
     36 
     37 This is only for development use."
     38   :type 'string
     39   :group 'lsp-cucumber)
     40 
     41 (defcustom lsp-cucumber-active-modes
     42   '( feature-mode)
     43   "List of major mode that work with Cucumber language server."
     44   :type '(list symbol)
     45   :group 'lsp-cucumber)
     46 
     47 (lsp-defcustom lsp-cucumber-features
     48   ["src/test/**/*.feature" "features/**/*.feature" "tests/**/*.feature" "*specs*/**/*.feature"]
     49   "Configure where the extension should look for .feature files."
     50   :type '(repeat string)
     51   :group 'lsp-cucumber
     52   :package-version '(lsp-mode . "9.0.0")
     53   :lsp-path "cucumber.features")
     54 
     55 (lsp-defcustom lsp-cucumber-glue
     56   ["*specs*/**/*.cs" "features/**/*.js" "features/**/*.jsx" "features/**/*.php" "features/**/*.py" "features/**/*.rs" "features/**/*.rb" "features/**/*.ts" "features/**/*.tsx" "features/**/*_test.go" "**/*_test.go" "src/test/**/*.java" "tests/**/*.py" "tests/**/*.rs"]
     57   "Configure where the extension should look for source code where
     58 step definitions and parameter types are defined."
     59   :type '(repeat string)
     60   :group 'lsp-cucumber
     61   :package-version '(lsp-mode . "9.0.0")
     62   :lsp-path "cucumber.glue")
     63 
     64 (lsp-defcustom lsp-cucumber-parameter-types []
     65   "Configure parameters types to convert output parameters to your own types.
     66 
     67 Details at https://github.com/cucumber/cucumber-expressions#custom-parameter-types.
     68 Sample:
     69 [(:name \"actor\"
     70   :regexp \"[A-Z][a-z]+\")]"
     71   :type '(lsp-repeatable-vector plist)
     72   :group 'lsp-cucumber
     73   :package-version '(lsp-mode . "9.0.0")
     74   :lsp-path "cucumber.parameterTypes")
     75 
     76 (defun lsp-cucumber--server-command ()
     77   "Generate startup command for Cucumber language server."
     78   (or (and lsp-cucumber-server-path
     79            (list lsp-cucumber-server-path "--stdio"))
     80       (list (lsp-package-path 'cucumber-language-server) "--stdio")))
     81 
     82 (lsp-dependency 'cucumber-language-server
     83                 '(:system "cucumber-language-server")
     84                 '(:npm :package "@cucumber/language-server"
     85                        :path "cucumber-language-server"))
     86 
     87 (lsp-register-client
     88  (make-lsp-client
     89   :new-connection (lsp-stdio-connection #'lsp-cucumber--server-command)
     90   :major-modes lsp-cucumber-active-modes
     91   :priority -1
     92   :server-id 'cucumber-language-server
     93   :download-server-fn (lambda (_client callback error-callback _update?)
     94                         (lsp-package-ensure 'cucumber-language-server callback error-callback))))
     95 
     96 (provide 'lsp-cucumber)
     97 ;;; lsp-cucumber.el ends here