From 491d667d1e113bd6b43d1f88d47383e7fb137ddb Mon Sep 17 00:00:00 2001 From: Ivan Yonchovski Date: Wed, 27 Oct 2021 19:44:53 +0300 Subject: [PATCH] Initial implementation of section synchronization (#3167) - added `defcustom-lsp` and :section-synchronization property to the client. `defcustom-lsp` will automatically register the property and also it will post notification to the servers with matching `:section-synchronization` --- clients/lsp-ada.el | 23 +++++++++++------------ lsp-mode.el | 29 ++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/clients/lsp-ada.el b/clients/lsp-ada.el index 9b105b3a1ae..d0d8f227b46 100644 --- a/clients/lsp-ada.el +++ b/clients/lsp-ada.el @@ -32,31 +32,29 @@ :tag "Language Server" :package-version '(lsp-mode . "6.2")) -(defcustom lsp-ada-project-file "default.gpr" +(defcustom-lsp lsp-ada-project-file "default.gpr" "Set the project file full path to configure the language server with. The ~ prefix (for the user home directory) is supported. See https://github.com/AdaCore/ada_language_server for a per-project configuration example." :type 'string :group 'lsp-ada - :package-version '(lsp-mode . "6.2")) + :package-version '(lsp-mode . "6.2") + :lsp-path "ada.projectFile") -(defcustom lsp-ada-option-charset "UTF-8" +(defcustom-lsp lsp-ada-option-charset "UTF-8" "The charset to use by the Ada Language server. Defaults to 'UTF-8'." :type 'string :group 'lsp-ada - :package-version '(lsp-mode . "6.2")) + :package-version '(lsp-mode . "6.2") + :lsp-path "ada.defaultCharset") -(defcustom lsp-ada-enable-diagnostics t +(defcustom-lsp lsp-ada-enable-diagnostics t "A boolean to disable diagnostics. Defaults to true." :type 'boolean :group 'lsp-ada - :package-version '(lsp-mode . "6.2")) - -(lsp-register-custom-settings - '(("ada.projectFile" lsp-ada-project-file) - ("ada.enableDiagnostics" lsp-ada-enable-diagnostics) - ("ada.defaultCharset" lsp-ada-option-charset))) + :package-version '(lsp-mode . "6.2") + :lsp-path "ada.enableDiagnostics") (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection '("ada_language_server")) @@ -66,7 +64,8 @@ (with-lsp-workspace workspace (lsp--set-configuration (lsp-configuration-section "ada")))) - :server-id 'ada-ls)) + :server-id 'ada-ls + :synchronize-sections '("ada"))) (lsp-consistency-check lsp-ada) diff --git a/lsp-mode.el b/lsp-mode.el index 0f056d1b3ec..0c1ed0064a1 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -1496,7 +1496,8 @@ return value of `body' or nil if interrupted." (async-request-handlers (make-hash-table :test 'equal)) download-server-fn download-in-progress? - buffers) + buffers + synchronize-sections) (defun lsp-clients-executable-find (find-command &rest args) "Finds an executable by invoking a search command. @@ -7840,6 +7841,31 @@ TBL - a hash table, PATHS is the path to the nested VALUE." (ht-set! tbl path temp-tbl) temp-tbl)))) (lsp-ht-set nested-tbl rst value))))) + +;; sections + +(defmacro defcustom-lsp (symbol standard doc &rest args) + "Defines `lsp-mode' server property." + (let ((path (plist-get args :lsp-path))) + (cl-remf args :lsp-path) + `(progn + (lsp-register-custom-settings + (quote ((,path ,symbol ,(equal ''boolean (plist-get args :type)))))) + + (defcustom ,symbol ,standard ,doc + :set (lambda (sym val) + (lsp--set-custom-property sym val ,path)) + ,@args)))) + +(defun lsp--set-custom-property (sym val path) + (set sym val) + (let ((section (cl-first (s-split "\\." path)))) + (mapc (lambda (workspace) + (when (-contains? (lsp--client-synchronize-sections (lsp--workspace-client workspace)) + section) + (with-lsp-workspace workspace + (lsp--set-configuration (lsp-configuration-section section))))) + (lsp--session-workspaces (lsp-session))))) (defun lsp-configuration-section (section) "Get settings for SECTION." @@ -7857,6 +7883,7 @@ TBL - a hash table, PATHS is the path to the nested VALUE." lsp-client-settings) ret)) + (defun lsp--start-connection (session client project-root) "Initiates connection created from CLIENT for PROJECT-ROOT. SESSION is the active session."