config

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

lsp-openscad.el (3783B)


      1 ;;; lsp-openscad.el --- openscad client         -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2022 Len Trigg
      4 
      5 ;; Author: Len Trigg
      6 ;; Keywords: openscad lsp
      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-openscad client
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-openscad nil
     30   "LSP support for openscad."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/Leathong/openscad-LSP"))
     33 
     34 (defcustom lsp-openscad-server
     35   "openscad-lsp"
     36   "Path to the openscad language server."
     37   :group 'lsp-openscad
     38   :risky t
     39   :type 'file)
     40 
     41 (defcustom lsp-openscad-server-connection-type
     42   'tcp
     43   "Type of connection to use with the OpenSCAD Language Server: tcp or stdio."
     44   :group 'lsp-openscad
     45   :risky t
     46   :type 'symbol)
     47 
     48 (defcustom lsp-openscad-search-paths ""
     49   "Customized search path."
     50   :type 'string
     51   :group 'lsp-openscad)
     52 
     53 (defcustom lsp-openscad-format-exe "clang-format"
     54   "Path to the clang-format executable."
     55   :type 'string
     56   :group 'lsp-openscad)
     57 
     58 (defcustom lsp-openscad-format-style "file"
     59   "Style argument to use with clang-format."
     60   :type 'string
     61   :group 'lsp-openscad)
     62 
     63 (lsp-register-custom-settings
     64  '(("openscad.search_paths" lsp-openscad-search-paths)
     65    ("openscad.fmt_exe" lsp-openscad-format-exe)
     66    ("openscad.fmt_style" lsp-openscad-format-style)))
     67 
     68 (defun lsp-openscad-server-stdio-start-fun ()
     69   "Create arguments to start openscad language server in stdio mode."
     70   `(,lsp-openscad-server "--stdio" ))
     71 
     72 (defun lsp-openscad-server-tcp-start-fun (port)
     73   "Create arguments to start openscad language server in TCP mode on PORT."
     74   `(,lsp-openscad-server "--port" ,(number-to-string port)))
     75 
     76 (defun lsp-openscad-server-connection ()
     77   "Create command line arguments to start openscad language server."
     78   (if (eq lsp-openscad-server-connection-type 'tcp)
     79       (lsp-tcp-connection 'lsp-openscad-server-tcp-start-fun)
     80     (lsp-stdio-connection 'lsp-openscad-server-stdio-start-fun)))
     81 
     82 (lsp-register-client
     83  (make-lsp-client :new-connection (lsp-openscad-server-connection)
     84                   :major-modes '(scad-mode)
     85                   :priority -1
     86                   :initialized-fn (lambda (workspace)
     87                                     ;; OpenSCAD-LSP returns an empty list of
     88                                     ;; completion options at initialization
     89                                     ;; so completionProvider capability is {}
     90                                     ;; When using plists, this value is parsed as
     91                                     ;; null/nil so we need to force it to "t"
     92                                     ;; to enable completion
     93                                     (let ((caps (lsp--workspace-server-capabilities workspace)))
     94                                       (unless (lsp-get caps :completionProvider)
     95                                         (lsp:set-server-capabilities-completion-provider? caps t)))
     96                                     (with-lsp-workspace workspace
     97                                       (lsp--set-configuration
     98                                        (lsp-configuration-section "openscad"))))
     99                   :server-id 'openscad))
    100 
    101 (provide 'lsp-openscad)
    102 ;;; lsp-openscad.el ends here