|
| 1 | +;;; lsp-c3.el --- C3 Client settings -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2025 Bruno Dias |
| 4 | + |
| 5 | +;; Author: Bruno Dias |
| 6 | +;; Keywords: c3 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-c3 client |
| 24 | + |
| 25 | +;;; Code: |
| 26 | + |
| 27 | +(require 'lsp-mode) |
| 28 | + |
| 29 | +(defgroup lsp-c3 nil |
| 30 | + "LSP support for the C3 programming language, using the server from https://github.com/pherrymason/c3-lsp." |
| 31 | + :group 'lsp-mode |
| 32 | + :link '(url-link "https://github.com/pherrymason/c3-lsp")) |
| 33 | + |
| 34 | +(defcustom lsp-c3-c3-language-server-path nil |
| 35 | + "Path for c3-language-server. |
| 36 | +Prefer to build by hand for now." |
| 37 | + :group 'lsp-c3 |
| 38 | + :risky t |
| 39 | + :type 'file) |
| 40 | + |
| 41 | +(defcustom lsp-c3-c3-path "" |
| 42 | + "The path to your C3 executable." |
| 43 | + :type 'file |
| 44 | + :group 'lsp-c3) |
| 45 | + |
| 46 | +(defcustom lsp-c3-c3-format-path "" |
| 47 | + "The path to your c3-format executable. |
| 48 | +
|
| 49 | +There is an effort to bring formatting/linting to c3." |
| 50 | + :type 'file |
| 51 | + :group 'lsp-c3) |
| 52 | + |
| 53 | +(defcustom lsp-c3-server-args '() |
| 54 | + "Arguments to pass to the server." |
| 55 | + :type '(repeat string) |
| 56 | + :group 'lsp-c3) |
| 57 | + |
| 58 | +(defun lsp-c3--c3-language-server-command () |
| 59 | + "Generate LSP startup command for the C3 Language Server." |
| 60 | + (cons |
| 61 | + (or lsp-c3-c3-language-server-path |
| 62 | + (lsp-package-path 'c3-language-server)) |
| 63 | + lsp-c3-server-args)) |
| 64 | + |
| 65 | +(defun lsp-clients-c3--make-init-options () |
| 66 | + "Init options for C3-language-server." |
| 67 | + `(:c3Path ,lsp-c3-c3-path |
| 68 | + :c3FormatPath ,lsp-c3-c3-format-path)) |
| 69 | + |
| 70 | +(lsp-register-client |
| 71 | + (make-lsp-client |
| 72 | + :new-connection (lsp-stdio-connection #'lsp-c3--c3-language-server-command) |
| 73 | + :language-id "c3-ts" |
| 74 | + :major-modes '(c3-ts-mode) |
| 75 | + :priority 0 |
| 76 | + :initialization-options #'lsp-clients-c3--make-init-options |
| 77 | + :server-id 'c3lsp |
| 78 | + :download-server-fn (lambda (_client callback _error-callback _update?) |
| 79 | + (message "To use this lsp, you need to build it |
| 80 | +and use `lsp-c3-c3-language-server-path` to define where the executable is located. |
| 81 | +
|
| 82 | +Hope soon, we integrate with the lsp installation system.") |
| 83 | + (funcall callback)))) |
| 84 | + |
| 85 | +(lsp-consistency-check lsp-c3) |
| 86 | + |
| 87 | +(provide 'lsp-c3) |
| 88 | +;;; lsp-c3.el ends here |
0 commit comments