From 7c4b8516c83746b7f212dadd0f593f39defbb760 Mon Sep 17 00:00:00 2001 From: Troy Brown Date: Sun, 29 Sep 2024 17:59:04 -0400 Subject: [PATCH] Add missing configuration options for the Ada Language Server. Additionally, prefer "initialization-options" over "initialized-fn" as the Ada Language Server prefers to know the project file as part of initialization, and will have to create a default one if it's not specified as part of these options. If a project file is not specified as part of the initialization options, the server might also display a diagnostic about no project being specified until a workspace/didChangeConfiguration is received specifying the project file. Add support for Ada run-time library folders via the new user option `lsp-ada-library-folders`, defaulting to detecting the run-time directory with it's unique "adainclude" folder. --- clients/lsp-ada.el | 195 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 185 insertions(+), 10 deletions(-) diff --git a/clients/lsp-ada.el b/clients/lsp-ada.el index 703b98beda..96fa08931f 100644 --- a/clients/lsp-ada.el +++ b/clients/lsp-ada.el @@ -29,8 +29,11 @@ (defgroup lsp-ada nil "Settings for Ada Language Server." - :group 'tools - :tag "Language Server" + :group 'lsp-mode + :link `(url-link :tag "Settings Documentation" + ,(concat "https://github.com/AdaCore/ada_language_server" + "/blob/master/doc/settings.md")) + :prefix "lsp-ada-" :package-version '(lsp-mode . "6.2")) (lsp-defcustom lsp-ada-project-file nil @@ -57,18 +60,166 @@ environment." ;;;###autoload(put 'lsp-ada-project-file 'safe-local-variable 'stringp) (lsp-defcustom lsp-ada-option-charset "UTF-8" - "The charset to use by the Ada Language server. Defaults to \\='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") :lsp-path "ada.defaultCharset") +;;;###autoload(put 'lsp-ada-option-charset 'safe-local-variable 'stringp) + +(lsp-defcustom lsp-ada-display-method-ancestry-on-navigation nil + "Policy for displaying overriding/overridden subprograms on navigation requests." + :type '(choice (const "never") + (const "usage_and_abstract_only") + (const "definition_only") + (const "always") + (const :tag "Not Specified" nil)) + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.displayMethodAncestryOnNavigation") +;;;###autoload(put 'lsp-ada-display-method-ancestry-on-navigation 'safe-local-variable 'stringp) + +(lsp-defcustom lsp-ada-documentation-style nil + "Style used to extract documentation for an entity." + :type '(choice (const "gnat") + (const "leading") + (const :tag "Not Specified" nil)) + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.documentationStyle") +;;;###autoload(put 'lsp-ada-documentation-style 'safe-local-variable 'stringp) (lsp-defcustom lsp-ada-enable-diagnostics t - "A boolean to disable diagnostics. Defaults to true." + "A boolean to disable diagnostics. Defaults to true." :type 'boolean :group 'lsp-ada :package-version '(lsp-mode . "6.2") :lsp-path "ada.enableDiagnostics") +;;;###autoload(put 'lsp-ada-enable-diagnostics 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-enable-indexing t + "Whether the server indexes the source files after loading a project." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "6.2") + :lsp-path "ada.enableIndexing") +;;;###autoload(put 'lsp-ada-enable-indexing 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-fold-comments t + "Whether the server sends information to control folding comment blocks." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.foldComments") +;;;###autoload(put 'lsp-ada-fold-comments 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-follow-symlinks t + "Whether the server attempts to resolve symlinks for file names." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.followSymlinks") +;;;###autoload(put 'lsp-ada-follow-symlinks 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-insert-with-clauses t + "Whether to automatically insert missing with-clauses for completions." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.insertWithClauses") +;;;###autoload(put 'lsp-ada-insert-with-clauses 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-named-notation-threshold nil + "Number of parameters when named notation is used in completion snippets." + :type 'integer + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.namedNotationThreshold") +;;;###autoload(put 'lsp-ada-named-notation-threshold 'safe-local-variable 'integerp) + +(lsp-defcustom lsp-ada-on-type-formatting-indent-only t + "Whether textDocument/onTypeFormatting request only indents a new line." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.onTypeFormatting.indentOnly") +;;;###autoload(put 'lsp-ada-on-type-formatting-indent-only 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-project-diagnostics t + "Whether the Ada Language Server should emit project diagnostics. + +This setting is ignored if `lsp-ada-enable-diagnostics' is nil. A +workspace reload is necessary to refresh the diagnostics after modifying +this setting." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.projectDiagnostics") +;;;###autoload(put 'lsp-ada-project-diagnostics 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-relocate-build-tree nil + "Path to use for out-of-tree builds." + :type 'string + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.relocateBuildTree") +;;;###autoload(put 'lsp-ada-relocate-build-tree 'safe-local-variable 'stringp) + +(lsp-defcustom lsp-ada-root-dir nil + "The root directory for artifact relocation. + +This setting must be used in conjunction with `lsp-ada-relocate-build-tree'." + :type 'string + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.rootDir") +;;;###autoload(put 'lsp-ada-root-dir 'safe-local-variable 'stringp) + +(lsp-defcustom lsp-ada-rename-in-comments nil + "Whether to apply textDocument/rename to comments." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.renameInComments") +;;;###autoload(put 'lsp-ada-rename-in-comments 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-scenario-variables nil + "Scenario variables for project." + :type '(alist :tag "Scenario Variable(s)" + :key-type (symbol :tag "Variable Name") + :value-type (string :tag "Value")) + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.scenarioVariables") +;;;###autoload +(put 'lsp-ada-scenario-variables + 'safe-local-variable + (lambda (object) + (while (and (consp object) + (consp (car object)) + (symbolp (caar object)) + (stringp (cdar object))) + (setq object (cdr object))) + (null object))) + +(lsp-defcustom lsp-ada-use-completion-snippets t + "Whether to enable snippets in completion results." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.useCompletionSnippets") +;;;###autoload(put 'lsp-ada-use-completion-snippets 'safe-local-variable 'booleanp) + +(lsp-defcustom lsp-ada-use-gnatformat nil + "Enables GNATformat as the formatting provider for Ada source files. + +This option controls the formatting provider. If disabled, GNATpp is +used instead." + :type 'boolean + :group 'lsp-ada + :package-version '(lsp-mode . "9.0.1") + :lsp-path "ada.useGnatformat") +;;;###autoload(put 'lsp-ada-use-gnatformat 'safe-local-variable 'booleanp) (defcustom lsp-ada-als-executable "ada_language_server" "Command to start the Ada language server." @@ -76,6 +227,24 @@ environment." :risky t :type 'file) +(defcustom lsp-ada-library-folders #'lsp-ada--default-library-folders + "List of Ada library folders. + +Library folders contain source which may be visited from a workspace, +but whose source files are not themselves considered a separate +workspace. This typically applies to language run-time source file +folders. + +Instead of a list of a folders, a function may be provided, which will +be called with the most recently active workspace as a parameter and +must return a list of Ada library folders, or nil if none." + :group 'lsp-ada + :type '(choice function + (repeat :tag "Library Folders" + (directory :tag "Library Folder"))) + :package-version '(lsp-mode . "9.0.1")) +;;;###autoload(put 'lsp-ada-library-folders 'safe-local-variable 'list-of-strings-p) + (defcustom lsp-ada-semantic-token-face-overrides '(("namespace" . default) ("modifier" . lsp-face-semhl-keyword)) @@ -139,6 +308,11 @@ environment." (lsp-ada--als-latest-release-url) "ada-ls")))) +(defun lsp-ada--default-library-folders (_workspace) + "Determine the set of Ada library folders." + (when (string-match-p "/adainclude/" (buffer-file-name)) + (list (file-name-directory (buffer-file-name))))) + (lsp-dependency 'ada-ls '(:download :url lsp-ada--als-latest-release-url @@ -153,16 +327,17 @@ environment." (lambda () (lsp-package-path 'ada-ls))) :major-modes '(ada-mode ada-ts-mode) :priority -1 - :initialized-fn (lambda (workspace) - (with-lsp-workspace workspace - (lsp--set-configuration - (lsp-configuration-section "ada")))) + :initialization-options (lambda () + (ht-get (lsp-configuration-section "ada") "ada")) + :library-folders-fn (lambda (workspace) + (if (functionp lsp-ada-library-folders) + (funcall lsp-ada-library-folders workspace) + lsp-ada-library-folders)) :download-server-fn (lambda (_client callback error-callback _update?) (lsp-package-ensure 'ada-ls callback error-callback)) :semantic-tokens-faces-overrides `( :types ,lsp-ada-semantic-token-face-overrides :modifiers ,lsp-ada-semantic-token-modifier-face-overrides) - :server-id 'ada-ls - :synchronize-sections '("ada"))) + :server-id 'ada-ls)) (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection