module: add :lang ada

This commit is contained in:
Henrik Lissner
2025-09-13 18:00:36 -04:00
parent 9dbeafe212
commit 286f04c6ef
6 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
:PROPERTIES:
:ID: 0903d239-7eab-47d7-8b88-00420fe6a50f
:END:
#+title: :lang ada
#+subtitle: In strong typing we (blindly) trust
#+created: September 13, 2025
#+since: 25.10.0
* Description :unfold:
This module adds support for the Ada and SPARK programming languages.
- Syntax highlighting (optionally via tree-sitter)
- Code completion (via company or corfu)
- LSP support (with [[https://github.com/AdaCore/ada_language_server][ada_language_server]])
- Alire integration (alr build, alr run, alr clean)
** Maintainers
*This module needs a maintainer.* [[doom-contrib-maintainer:][Become a maintainer?]]
** Module flags
# Flags should be in alphanumerical order.
- +lsp ::
Enable LSP support for ~ada-mode~ / ~ada-ts-mode~. Requires [[doom-module::tools lsp]]
and a langserver (supports [[https://github.com/AdaCore/ada_language_server][ada_language_server]]).
- +tree-sitter ::
Leverages tree-sitter for better syntax highlighting and structural text
editing. Requires [[doom-module::tools tree-sitter]] and Emacs 29.1+.
** Packages
- [[doom-package:ada-mode]]
- [[doom-package:ada-ts-mode]] if [[doom-module:+tree-sitter]]
** Hacks
- ~ada-ts-mode~ has been advised not to set ~treesit-language-source-alist~ and
~eglot-server-programs~ buffer-locally, because this overrides global settings
(by the user or Doom modules) in a non-standard way.
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]
#+begin_quote
󱌣 /No installation steps have been documented./ [[doom-contrib-module:][Document them?]]
#+end_quote
* Usage
#+begin_quote
󱌣 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]]
#+end_quote
* TODO Configuration
#+begin_quote
󱌣 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]]
#+end_quote
* Troubleshooting
/There are no known problems with this module./ [[doom-report:][Report one?]]
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]]
* TODO Appendix
#+begin_quote
󱌣 This module has no appendix yet. [[doom-contrib-module:][Write one?]]
#+end_quote

View File

@@ -0,0 +1,27 @@
;;; lang/ada/auoload.el -*- lexical-binding: t; -*-
(defun +ada--barf-unless-project ()
(unless (locate-dominating-file defaul-directory "alire.toml")
(user-error "Not inside an Alire project")))
;;;###autoload
(defun +ada/alr-build ()
"Run 'alr build' in the current project."
(interactive)
(+ada--barf-unless-project)
(compile "alr build"))
;;;###autoload
(defun +ada/alr-run ()
"Run 'alr run' in the current project."
(interactive)
(+ada--barf-unless-project)
(compile "alr run"))
;;;###autoload
(defun +ada/alr-clean ()
"Run 'alr clean' in the current project."
(interactive)
(+ada--barf-unless-project)
(compile "alr clean"))

View File

@@ -0,0 +1,44 @@
;;; lang/ada/config.el -*- lexical-binding: t; -*-
;;
;;; Packages
(defun +ada-common-config (mode)
(when (modulep! +lsp)
(add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append))
(map! :map ,(intern (format "%s-map" mode))
:localleader
:desc "Build Alire Project" "b" #'+ada/alr-build
:desc "Run Alire Project" "r" #'+ada/alr-run
:desc "Clean Alire Project" "c" #'+ada/alr-clean))
(use-package! ada-mode
:mode "\\.gpr\\'"
:config
(+ada-common-config 'ada-mode))
(use-package! ada-ts-mode
:when (modulep! +tree-sitter)
:defer t
:init
(set-tree-sitter! 'ada-mode 'ada-ts-mode
'((ada :url "https://github.com/briot/tree-sitter-ada")))
:config
(+ada-common-config 'ada-ts-mode)
(setq ada-ts-mode-grammar-install nil) ; redundant w/ `treesit-auto-install-grammar'
;; HACK: `ada-ts-mode' sets buffer-local values for
;; `treesit-language-source-alist' and `eglot-server-program' during major
;; mode activation. This is poor ettiquite, overshadowing any user changes
;; to the global values of these variables. Not to mention, it's redundant
;; with ~set-tree-sitter!~ and ~eglot~ already handling support for
;; ada-ts-mode.
;; REVIEW: Undo buffer-local changes to these variables upstream.
(defadvice! +ada--suppress-side-effects-a (&rest _)
:after #'ada-ts-mode
(kill-local-variable 'treesit-language-source-alist)
(kill-local-variable 'eglot-server-programs)))

View File

@@ -0,0 +1,8 @@
;;; lang/ada/doctor.el -*- lexical-binding: t; -*-
(unless (executable-find "alr")
(warn! "Alire (alr) not found in $PATH"))
(when (modulep! +lsp)
(unless (executable-find "ada_language_server")
(warn! "ada_language_server not found in $PATH; LSP support won't work")))

View File

@@ -0,0 +1,6 @@
;; -*- no-byte-compile: t; -*-
;;; lang/ada/packages.el
(package! ada-mode :pin "ce8a2dfebc2b738f32b61dbe2668f7acb885db93")
(when (and (modulep! +tree-sitter) (treesit-available-p))
(package! ada-ts-mode :pin "d0c1c124b236b402b884188948cb1f3502ef8779"))