From 359e692d8e4b8960b1f02fa5a3213ff4b9d0ae40 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 27 Sep 2023 11:51:24 +0100 Subject: [PATCH] feat(language/protobuf): enable use of bufls language server --- modules/languages/siren-protobuf.el | 11 ++++- vendor/lsp-bufls/lsp-bufls.el | 66 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 vendor/lsp-bufls/lsp-bufls.el diff --git a/modules/languages/siren-protobuf.el b/modules/languages/siren-protobuf.el index b4d725b..812e937 100644 --- a/modules/languages/siren-protobuf.el +++ b/modules/languages/siren-protobuf.el @@ -28,7 +28,12 @@ (if (not (flycheck-protobuf-buf-project-root)) (clang-format-on-save-mode t) (setq-local flycheck-checker 'protobuf-buf) - (buf-format-on-save-mode t))) + (buf-format-on-save-mode t)) + + (lsp) + (when (fboundp 'flycheck-select-checker) + (flycheck-select-checker 'protobuf-buf) + (flycheck-add-next-checker 'protobuf-buf 'lsp))) (defun flycheck-protobuf-buf-project-root (&optional _checker) "Return the nearest directory holding the buf.yaml configuration." @@ -58,5 +63,9 @@ See URL `https://github.com/bufbuild/buf'." (add-to-list 'flycheck-checkers 'protobuf-buf)) +(use-package lsp-bufls + ;; from vendor directory + :straight (:type built-in)) + (provide 'siren-protobuf) ;;; siren-protobuf.el ends here diff --git a/vendor/lsp-bufls/lsp-bufls.el b/vendor/lsp-bufls/lsp-bufls.el new file mode 100644 index 0000000..c0e9a9a --- /dev/null +++ b/vendor/lsp-bufls/lsp-bufls.el @@ -0,0 +1,66 @@ +;;; lsp-bufls.el --- bufls-langserver Client settings -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Jim Myhrberg + +;; Author: Jim Myhrberg +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; lsp-bufls client + +;;; Code: + +(require 'lsp-mode) +(require 'lsp-go) + +(defgroup lsp-bufls nil + "Configuration options for lsp-bufls." + :group 'lsp-mode + :link '(url-lint "https://github.com/bufbuild/buf-language-server")) + +(defcustom lsp-bufls-args nil + "Arguments to pass to bufls serve." + :type '(repeat string) + :group 'lsp-bufls) + +(defcustom lsp-bufls-path "bufls" + "Command to run bufls." + :type 'string + :group 'lsp-bufls) + +(defun lsp-bufls-server--stdio-command () + "Return the command and args to start bufls-langserver." + (let ((args (list lsp-bufls-path "serve"))) + (when (and (listp lsp-bufls-args) + (length> lsp-bufls-args 0)) + (setq args (append args lsp-bufls-args))) + args)) + +(add-to-list 'lsp-language-id-configuration '(protobuf-mode . "protobuf")) + +(lsp-register-client + (make-lsp-client :new-connection (lsp-stdio-connection + #'lsp-bufls-server--stdio-command) + :activation-fn (lsp-activate-on "protobuf") + :language-id "protobuf" + :priority 0 + :server-id 'bufls)) + +(lsp-consistency-check lsp-bufls) + +(provide 'lsp-bufls) +;;; lsp-bufls.el ends here