Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing configuration options for the Ada Language Server. #4567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 189 additions & 8 deletions clients/lsp-ada.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,25 +60,191 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to autoload all these custom variables? 🤔

Copy link
Contributor Author

@brownts brownts Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added them is that any of those could potentially be specified in a .dir-locals.el. I find it annoying to have to manually approve the "potentially unsafe" settings in my .dir-locals.el. If you think this is too much, I can cut these back to the most frequently used options. I could of course add safety settings in my init.el, but since other people use this mode as well, it would require others to do the same in their init.el, and I was going for ease of use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cut back for now since it's unusual for only this file to do that. 🤔 We can open a new issue, discuss this, and see what others think.


(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."
:group 'lsp-ada
: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))
Expand Down Expand Up @@ -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
Expand All @@ -153,16 +327,23 @@ environment."
(lambda () (lsp-package-path 'ada-ls)))
:major-modes '(ada-mode ada-ts-mode)
:priority -1
:initialization-options (lambda ()
(ht-get (lsp-configuration-section "ada") "ada"))
;; Send workspace/didChangeConfiguration as a workaround for:
;; https://github.com/AdaCore/ada_language_server/issues/1209
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration
(lsp-configuration-section "ada"))))
(lsp--set-configuration
(lsp-configuration-section "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
Expand Down
Loading