Skip to content

Commit

Permalink
Initial implementation of section synchronization (#3167)
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
yyoncho authored Oct 27, 2021
1 parent 6157b3d commit 491d667
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
23 changes: 11 additions & 12 deletions clients/lsp-ada.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)

Expand Down
29 changes: 28 additions & 1 deletion lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand Down

0 comments on commit 491d667

Please sign in to comment.