Skip to content

Commit d5d124e

Browse files
committed
feat: new ctags mode and refresh for dep tree
* Feature: added new `sdml-mode-ctags-mode` minor mode that provides a command to generate tag files using [Universal Ctags](https://ctags.io/). * Feature: added a refresh command, bound to `g`, to the dependency tree view. * Refactor: module `sdml-mode-cli` now more generic for other clients. * Build: reworked the Eldev workflow for Github actions. * Fix: regex for compilation mode, error tracking in validation command now working correctly. * Fix: added guard to commands to be relevant only in `sdml-mode`. * Fix: removed `property_def` rule from highlighting.
1 parent 105c0fd commit d5d124e

File tree

6 files changed

+232
-79
lines changed

6 files changed

+232
-79
lines changed

.github/workflows/emacs-eldev.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
runs-on: ${{matrix.os}}
1717
continue-on-error: ${{matrix.emacs_version == 'snapshot' || (matrix.emacs_version == '29.4' && matrix.os == 'windows-latest')}}
1818
env:
19+
ELDEV: eldev
1920
ELDEV_ARGS: --debug --trace --time --backtrace-on-abort --color
2021

2122
steps:
@@ -31,14 +32,14 @@ jobs:
3132
uses: actions/checkout@v4
3233

3334
- name: Ensure that copyright notices are up-to-date
34-
run: eldev $ELDEV_ARGS doctor up-to-date-copyright --all-tests
35+
run: ${ELDEV} "${ELDEV_ARGS} doctor up-to-date-copyright --all-tests"
3536

3637
- name: Lint the project
37-
run: eldev $ELDEV_ARGS lint
38+
run: ${ELDEV} "${ELDEV_ARGS} lint"
3839

3940
- name: Compile the project
40-
run: eldev $ELDEV_ARGS compile --warnings-as-errors
41+
run: ${ELDEV} "${ELDEV_ARGS} compile --warnings-as-errors"
4142

4243
- name: Test the project
4344
# Add --expect 10 to ensure a minimum number of tests!
44-
run: eldev $ELDEV_ARGS test
45+
run: ${ELDEV} "${ELDEV_ARGS} test"

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ will add the value of the Emacs variable `locale-language` as the language tag.
111111

112112
* `C-c C-s d` -- open the tree-sitter debug view
113113
* `C-c C-s q` -- open the tree-sitter query builder
114+
* `C-c C-s t` -- open a dependency tree view
115+
* `C-c C-s v` -- run the validator in a compilation window
114116

115117
## Add-Ons
116118

@@ -131,13 +133,27 @@ including:
131133
* `package-lint`
132134
* `checkdoc`
133135

136+
Automated checks are done in the Github action workflow using Eldev.
137+
134138
## License
135139

136140
This package is released under the Apache License, Version 2.0. See the LICENSE
137141
file in the repository for details.
138142

139143
## Changes
140144

145+
### Version 0.1.9
146+
147+
* Feature: added new `sdml-mode-ctags-mode` minor mode that provides a command to
148+
generate tag files using [Universal Ctags](https://ctags.io/).
149+
* Feature: added a refresh command, bound to `g`, to the dependency tree view.
150+
* Refactor: module `sdml-mode-cli` now more generic for other clients.
151+
* Build: reworked the Eldev workflow for Github actions.
152+
* Fix: regex for compilation mode, error tracking in validation command now
153+
working correctly.
154+
* Fix: added guard to commands to be relevant only in `sdml-mode`.
155+
* Fix: removed `property_def` rule from highlighting.
156+
141157
### Version 0.1.8
142158

143159
* Feature: update to latest tree-sitter grammar (0.3.2).

sdml-mode-cli.el

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
;;; Code:
2626

2727
(require 'ansi-color) ;; built-in
28+
(require 'seq)
2829

2930
;; --------------------------------------------------------------------------
3031
;; Customization
@@ -53,6 +54,12 @@
5354
:type '(repeat directory)
5455
:group 'sdml)
5556

57+
(defcustom sdml-mode-cli-no-color nil
58+
"Suppress color output from the command line tool."
59+
:tag "Suppress color"
60+
:type 'boolean
61+
:group 'sdml)
62+
5663
;; --------------------------------------------------------------------------
5764
;; Section heading
5865
;; --------------------------------------------------------------------------
@@ -61,62 +68,73 @@
6168

6269
(defconst sdml-mode-cli-default-error-buffer-name "*SDML Command-Line Errors*")
6370

64-
(defun sdml-mode-cli-make-arg (plist-args key &optional arg-name ignore-me)
65-
"Make a CLI argument with KEY from PLIST-ARGS."
66-
(when (not ignore-me)
67-
(let ((value (plist-get plist-args key))
68-
(arg-name (if arg-name
69-
arg-name
70-
(substring (symbol-name key) 1))))
71-
(if (null value) "" (format "--%s %s" arg-name value)))))
72-
73-
(defun sdml-mode-cli-make-command (command &rest plist-args)
74-
"Make an sdml COMMAND with additional PLIST-ARGS."
75-
(interactive)
76-
(when (derived-mode-p 'sdml-mode)
71+
(defun sdml-mode-cli-make-arg (name value)
72+
"Make an argument string from NAME and VALUE."
73+
(format "--%s %s" name value))
74+
75+
(defun sdml-mode-cli-make-command (command &rest args)
76+
"Make an sdml COMMAND with additional ARGS."
77+
(when (or t (derived-mode-p 'sdml-mode))
7778
(let* ((cli-name (or sdml-mode-cli-name "sdml"))
7879
(cmd-name (executable-find cli-name))
79-
(file-name (buffer-file-name (current-buffer))))
80+
(pre-args (list
81+
cmd-name
82+
(sdml-mode-cli-make-arg 'log-filter sdml-mode-cli-log-filter)
83+
(if sdml-mode-cli-no-color "--no-color" nil)
84+
command))
85+
(args (mapcar (lambda (arg) (cond
86+
((eq arg 'current-buffer)
87+
(sdml-mode-cli-make-arg 'input (buffer-file-name)))
88+
(t arg)))
89+
args)))
8090
(cond
8191
((null cmd-name)
8292
(message "couldn't find the sdml cli: %s" cli-name))
83-
((null file-name)
84-
(message "buffer doesn't have a file name"))
8593
(t
86-
(string-join
87-
(list cmd-name
88-
(sdml-mode-cli-make-arg plist-args :log-filter)
89-
command
90-
(sdml-mode-cli-make-arg plist-args :validation-level "level" (not (string= command "validate")))
91-
(sdml-mode-cli-make-arg plist-args :depth nil (not (string= command "deps")))
92-
(sdml-mode-cli-make-arg plist-args :output-format)
93-
(sdml-mode-cli-make-arg plist-args :output-file)
94-
(or (sdml-mode-cli-make-arg plist-args :input-file)
95-
(let ((arg-value (plist-get plist-args :input-module)))
96-
(if (null arg-value) "" arg-value))))
97-
" "))))))
98-
99-
100-
(defun sdml-mode-cli-run-command (command &optional output-buffer-name error-buffer-name)
94+
(string-join (append pre-args args) " "))))))
95+
96+
(defun sdml-mode-cli--make-refresh-cmd (cmd env out err)
97+
"Return a lambda to refresh the output buffer from a command.
98+
CMD is the command-line to run, ENV is the environment variables
99+
to add, OUT is the output buffer and ERR the error buffer."
100+
(lambda ()
101+
(interactive)
102+
(setq buffer-read-only nil)
103+
(delete-region (point-min) (point-max))
104+
(with-environment-variables (("SDML_PATH" env))
105+
(shell-command cmd out err)
106+
;; colorize output
107+
(ansi-color-apply-on-region (point-min) (point-max))
108+
(setq buffer-read-only t))))
109+
110+
(defun sdml-mode-cli-run-command (command &optional output-buffer-name error-buffer-name refresh-fn)
101111
"Run COMMAND with output to OUTPUT-BUFFER-NAME and ERROR-BUFFER-NAME.
102112
103-
If not specified `output-buffer-name' is set to
104-
`sdml-cli-default-output-buffer-name' and `error-buffer-name' is set
105-
to `sdml-cli-default-error-buffer-name'."
106-
(let ((output-buffer-name (or output-buffer-name sdml-mode-cli-default-output-buffer-name))
107-
(current-load-path (or (getenv "SDML_PATH") "")))
108-
(with-environment-variables (("SDML_PATH" (concat current-load-path
109-
(string-join sdml-mode-cli-load-path ":"))))
110-
(with-output-to-temp-buffer output-buffer-name
111-
(shell-command command
112-
output-buffer-name
113-
(or error-buffer-name sdml-mode-cli-default-error-buffer-name))
114-
(pop-to-buffer output-buffer-name)
115-
;; colorize output
116-
(ansi-color-apply-on-region (point-min) (point-max))
117-
;; make read-only
118-
(special-mode)))))
113+
If not specified OUTPUT-BUFFER-NAME is set to
114+
`sdml-cli-default-output-buffer-name' and ERROR-BUFFER-NAME is set
115+
to `sdml-cli-default-error-buffer-name'.
119116
117+
The boolean REFRESH-FN indicates that a refresh function should
118+
be added to the buffer with a key binding to \"g\"."
119+
(let ((output-buffer-name (or output-buffer-name sdml-mode-cli-default-output-buffer-name))
120+
(load-path (concat (or (getenv "SDML_PATH") "")
121+
(string-join sdml-mode-cli-load-path ":"))))
122+
(with-environment-variables (("SDML_PATH" load-path))
123+
(shell-command command
124+
output-buffer-name
125+
(or error-buffer-name sdml-mode-cli-default-error-buffer-name))
126+
(pop-to-buffer output-buffer-name)
127+
;; colorize output
128+
(ansi-color-apply-on-region (point-min) (point-max))
129+
;; make read-only
130+
(special-mode)
131+
(when refresh-fn
132+
;; install refresh command
133+
(use-local-map (copy-keymap special-mode-map))
134+
(local-set-key "g" (sdml-mode-cli--make-refresh-cmd command
135+
load-path
136+
output-buffer-name
137+
error-buffer-name))))))
120138

121139
(provide 'sdml-mode-cli)
122140

sdml-mode-ctags.el

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
;;; sdml-mode-ctags.el --- Universal Ctags Support -*- lexical-binding: t; -*-
2+
3+
;; Author: Simon Johnston <[email protected]>
4+
5+
;;; License:
6+
7+
;; Copyright (c) 2023, 2024 Simon Johnston
8+
;;
9+
;; Licensed under the Apache License, Version 2.0 (the "License");
10+
;; you may not use this file except in compliance with the License.
11+
;; You may obtain a copy of the License at
12+
;;
13+
;; http://www.apache.org/licenses/LICENSE-2.0
14+
;;
15+
;; Unless required by applicable law or agreed to in writing, software
16+
;; distributed under the License is distributed on an "AS IS" BASIS,
17+
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
;; See the License for the specific language governing permissions and
19+
;; limitations under the License.
20+
21+
;;; Commentary:
22+
23+
;; To enable SDML tagging you will need to install the Universal Ctags
24+
;; configuration file from:
25+
;;
26+
;; https://github.com/sdm-lang/sdml-ctags
27+
;;
28+
;; Internal module.
29+
30+
;;; Code:
31+
32+
;; --------------------------------------------------------------------------
33+
;; Requirements, both of these are optional
34+
;; --------------------------------------------------------------------------
35+
36+
(defvar company-ctags-modes)
37+
(declare-function company-ctags-find-table "company-ctags")
38+
39+
(declare-function projectile-acquire-root "projectile")
40+
41+
42+
;; --------------------------------------------------------------------------
43+
;; Customization
44+
;; --------------------------------------------------------------------------
45+
46+
(defcustom sdml-mode-ctags-command "/opt/homebrew/bin/ctags"
47+
"The command path/name for Universal Ctags."
48+
:tag "U-Ctags command path"
49+
:type 'file
50+
:group 'sdml)
51+
52+
53+
(defcustom sdml-mode-ctags-output-file-name "tags"
54+
"The name of the generated tag file."
55+
:tag "ctags output file name"
56+
:type 'file
57+
:group 'sdml)
58+
59+
60+
;; --------------------------------------------------------------------------
61+
;; Universal Ctag generation
62+
;; --------------------------------------------------------------------------
63+
64+
(defun sdml-mode-ctags-tag-file-path (&optional file-path)
65+
"Return a path to a tag file for the current buffer.
66+
If FILE-PATH is provided the tag file is found relative to that
67+
path instead."
68+
(let* ((current-buffer-dir (file-name-directory
69+
(or file-path (buffer-file-name))))
70+
(fallback (concat current-buffer-dir
71+
sdml-mode-ctags-output-file-name)))
72+
(cond ((featurep 'company-ctags)
73+
(let ((found (company-ctags-find-table)))
74+
(if found (car found) fallback)))
75+
((featurep 'projectile)
76+
(concat (projectile-acquire-root current-buffer-dir)
77+
sdml-mode-ctags-output-file-name))
78+
(t fallback))))
79+
80+
(defun sdml-mode-ctags-generate ()
81+
"Generate a TAGS file for the current SDML project."
82+
(interactive)
83+
(let ((tag-file-path (sdml-mode-ctags-tag-file-path)))
84+
(shell-command (format "%s -R -e -o %s" sdml-mode-ctags-command tag-file-path))))
85+
86+
;; --------------------------------------------------------------------------
87+
;; Ctags Minor Mode
88+
;; --------------------------------------------------------------------------
89+
90+
;;;###autoload
91+
(define-minor-mode
92+
sdml-mode-ctags-mode
93+
"Minor mode to provide tagging of SDML source."
94+
95+
:group 'sdml
96+
97+
:tag "Enable SDML tagging minor mode"
98+
99+
:lighter nil
100+
101+
(let ((map (make-sparse-keymap)))
102+
(define-key map (kbd "C-c C-s T") 'sdml-mode-ctags-generate)
103+
(add-to-list 'minor-mode-map-alist (cons 'sdml-mode-ctags-mode map)))
104+
105+
(when (featurep 'company-ctags)
106+
(add-to-list 'company-ctags-modes 'sdml-mode)))
107+
108+
(provide 'sdml-mode-ctags)
109+
110+
;;; sdml-mode-ctags.el ends here

sdml-mode-hl.el

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@
206206
name: (identifier) @type.definition
207207
source: (identifier_reference) @type)
208208

209-
(property_def
210-
member: (member_def
211-
name: (identifier) @type.definition))
212-
213209
(structure_def name: (identifier) @type.definition)
214210

215211
(union_def name: (identifier) @type.definition)

0 commit comments

Comments
 (0)