unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: "João Távora" <joaotavora@gmail.com>
Cc: 61868@debbugs.gnu.org
Subject: bug#61868: 29.0.60; Eglot: setting "workspace" configurations should be easier
Date: Tue, 28 Feb 2023 22:16:10 +0100	[thread overview]
Message-ID: <87ilfla3tx.fsf@gmail.com> (raw)
In-Reply-To: <87sfepa5pz.fsf@gmail.com> (Augusto Stoffel's message of "Tue, 28 Feb 2023 21:35:20 +0100")

On Tue, 28 Feb 2023 at 21:35, Augusto Stoffel wrote:

>> My bet is that that two-liner would go a long way.
>
> No, this is not enough.  At the very least I need a history variable to
> look at the previous configurations.  This feature has to be a thing on
> top of of `eglot-show-workspace-configuration'.

Here's a hasty sketch of what I have in mind, sans the history commands.

--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-

(defvar eglot-configuration-map
  (let ((map (make-sparse-keymap)))
    (define-key map "\C-c\C-c" #'eglot-configuration-save)
    (define-key map "\C-c\C-v" #'eglot-configuration-apply)
    (define-key map "\C-c\C-k" #'kill-current-buffer)
    map))

(define-minor-mode eglot-configuration--mode
  "Mode to edit LSP config"
  :interactive nil
  :keymap eglot-configuration-map
  (setq-local header-line-format (substitute-command-keys "\
\\<eglot-configuration-map>\
Press \\[eglot-configuration-apply] to apply, \\[eglot-configuration-save] to save, \\[kill-current-buffer] to abort.")))

(defun eglot-configuration-apply (&optional save)
  (interactive)
  (let ((eglot-workspace-configuration
         (save-excursion
           (goto-char (point-min))
           (jsonrpc--json-read))))
    (with-current-buffer eglot-configure--buffer
      (eglot-signal-didChangeConfiguration (eglot--current-server-or-lose))
      (when save
        (save-window-excursion
          (let ((default-directory (project-root (eglot--current-project))))
            (add-dir-local-variable
             nil ;; Tricky choice
             'eglot-workspace-configuration
             eglot-workspace-configuration)
            (save-buffer)))))))

(defun eglot-configuration-save ()
  (interactive)
  (eglot-configuration-apply t))

(defvar-local eglot-configure--buffer nil) ;; Ugh, get rid of this?

(defun eglot-configure (&optional server)
  "Dump `eglot-workspace-configuration' as JSON for debugging."
  (interactive (list (and (eglot-current-server)
                          (eglot--read-server "Server configuration"
                                              (eglot-current-server)))))
  (let ((buffer (current-buffer))
        (conf (eglot--workspace-configuration-plist server)))
    (with-current-buffer (get-buffer-create "*EGLOT workspace configuration*")
      (erase-buffer)
      (insert (jsonrpc--json-encode conf))
      (with-no-warnings
        (require 'json)
        (when (functionp #'js-json-mode) (js-json-mode))
        (json-pretty-print-buffer))
      (setq eglot-configure--buffer buffer)
      (eglot-configuration--mode)
      (pop-to-buffer (current-buffer)))))
--8<---------------cut here---------------end--------------->8---





  reply	other threads:[~2023-02-28 21:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 12:49 bug#61868: 29.0.60; Eglot: setting "workspace" configurations should be easier Augusto Stoffel
2023-02-28 19:33 ` João Távora
2023-02-28 20:35   ` Augusto Stoffel
2023-02-28 21:16     ` Augusto Stoffel [this message]
2023-03-01  2:02     ` João Távora
2023-03-01  7:39       ` Augusto Stoffel
2023-03-01 13:20         ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilfla3tx.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=61868@debbugs.gnu.org \
    --cc=joaotavora@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).