[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode d0f3f45 431/486: imenu: fn items: match async/co
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode d0f3f45 431/486: imenu: fn items: match async/const and all pub variants. (#346) |
Date: |
Sat, 7 Aug 2021 09:26:08 -0400 (EDT) |
branch: elpa/rust-mode
commit d0f3f45cc4fe1c5b72466253f051294d275a4b64
Author: Nathan Moreau <nathan.moreau@m4x.org>
Commit: GitHub <noreply@github.com>
imenu: fn items: match async/const and all pub variants. (#346)
---
rust-mode-tests.el | 49 +++++++++++++++++++++++++++++++++++++++----------
rust-mode.el | 48 +++++++++++++++++++++++++++++++++++++++---------
2 files changed, 78 insertions(+), 19 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index e2e1218..b680548 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -3078,29 +3078,58 @@ type Foo<T> where T: Copy = Box<T>;
(ert-deftest rust-test-imenu-extern-unsafe-fn ()
(test-imenu
"
-fn one() {
+fn f1() {
}
-unsafe fn two() {
+unsafe fn f2() {
}
-extern \"C\" fn three() {
+extern \"C\" fn f3() {
}
-pub extern fn four() {
+pub extern fn f4() {
+}
+
+extern \"rust-intrinsic\" fn f5() {
+}
+
+async fn f6() {
+}
+
+const fn f7() {
+}
+async const fn not_a_match() {
}
-extern \"rust-intrinsic\" fn five() {
+fn f8<'a>() {
+}
+
+pub ( in self::super ) fn f9() {
+}
+
+pub ( in super ) fn f10() {
+}
+
+pub(in crate) fn f11() {
+}
+pub (in self) fn f12() {
}
"
'(("Fn"
- "one"
- "two"
- "three"
- "four"
- "five"))))
+ "f1"
+ "f2"
+ "f3"
+ "f4"
+ "f5"
+ "f6"
+ "f7"
+ "f8"
+ "f9"
+ "f10"
+ "f11"
+ "f12"))))
(ert-deftest rust-test-imenu-impl-with-lifetime ()
(test-imenu
diff --git a/rust-mode.el b/rust-mode.el
index 026b481..92f7daa 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -35,12 +35,16 @@
"Set variable VAR to value VAL in current buffer."
(list 'set (list 'make-local-variable (list 'quote var)) val))))
+(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
+(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
+(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
+
(defconst rust-re-ident
"[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
(defconst rust-re-lc-ident
"[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
(defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
-(defconst rust-re-vis "pub")
(defconst rust-re-unsafe "unsafe")
(defconst rust-re-extern "extern")
+(defconst rust-re-async-or-const "async\\|const")
(defconst rust-re-generic
(concat "<[[:space:]]*'" rust-re-ident "[[:space:]]*>"))
(defconst rust-re-union
@@ -50,9 +54,34 @@
(group symbol-start "union" symbol-end)
(+ space) (regexp ,rust-re-ident))))
+(defvar rust-re-vis
+ ;; pub | pub ( crate ) | pub ( self ) | pub ( super ) | pub ( in SimplePath
)
+ (concat
+ "pub"
+ (rust-re-shy
+ (concat
+ "[[:space:]]*([[:space:]]*"
+ (rust-re-shy
+ (concat "crate" "\\|"
+ "\\(?:s\\(?:elf\\|uper\\)\\)" "\\|"
+ ;; in SimplePath
+ (rust-re-shy
+ (concat
+ "in[[:space:]]+"
+ rust-re-ident
+ (rust-re-shy (concat "::" rust-re-ident)) "*"))))
+ "[[:space:]]*)"))
+ "?"))
+
;;; Start of a Rust item
(defvar rust-top-item-beg-re
- (concat "\\s-*\\(?:priv\\|pub\\)?\\s-*"
+ (concat "\\s-*"
+ ;; TODO some of this does only make sense for `fn' (unsafe, extern...)
+ ;; and not other items
+ (rust-re-shy (concat (rust-re-shy rust-re-vis) "[[:space:]]+")) "?"
+
+ (rust-re-shy (concat (rust-re-shy rust-re-async-or-const)
"[[:space:]]+")) "?"
+ (rust-re-shy (concat (rust-re-shy rust-re-unsafe) "[[:space:]]+")) "?"
(regexp-opt
'("enum" "struct" "union" "type" "mod" "use" "fn" "static" "impl"
"extern" "trait"))
@@ -578,17 +607,18 @@ buffer."
symbol-end))
(defconst rust-re-pre-expression-operators "[-=!%&*/:<>[{(|.^;}]")
-(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
-(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
-(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
(defun rust-re-item-def (itype)
(concat (rust-re-word itype)
- (rust-re-shy rust-re-generic) "?"
- "[[:space:]]+" (rust-re-grab rust-re-ident)))
+ (rust-re-shy rust-re-generic) "?"
+ "[[:space:]]+" (rust-re-grab rust-re-ident)))
+
+;; TODO some of this does only make sense for `fn' (unsafe, extern...)
+;; and not other items
(defun rust-re-item-def-imenu (itype)
(concat "^[[:space:]]*"
- (rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?"
+ (rust-re-shy (concat rust-re-vis "[[:space:]]+")) "?"
(rust-re-shy (concat (rust-re-word "default") "[[:space:]]+")) "?"
+ (rust-re-shy (concat (rust-re-shy rust-re-async-or-const)
"[[:space:]]+")) "?"
(rust-re-shy (concat (rust-re-word rust-re-unsafe) "[[:space:]]+"))
"?"
(rust-re-shy (concat (rust-re-word rust-re-extern) "[[:space:]]+"
(rust-re-shy "\"[^\"]+\"[[:space:]]+") "?")) "?"
@@ -1292,7 +1322,7 @@ whichever comes first."
(defvar rust-imenu-generic-expression
(append (mapcar #'(lambda (x)
(list (capitalize x) (rust-re-item-def-imenu x) 1))
- '("async fn" "enum" "struct" "union" "type" "mod" "fn"
"trait" "impl"))
+ '("enum" "struct" "union" "type" "mod" "fn" "trait" "impl"))
`(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1)))
"Value for `imenu-generic-expression' in Rust mode.
- [nongnu] elpa/rust-mode 7fd78f0 444/486: rust-goto-format-problem: make sure to always just to a buffer that exists., (continued)
- [nongnu] elpa/rust-mode 7fd78f0 444/486: rust-goto-format-problem: make sure to always just to a buffer that exists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9e03890 478/486: Create rust-compile.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 41642f0 481/486: rust-end-of-string: Move definition, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d548425 483/486: Create rust-playpen.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eb5270b 437/486: rust-before-save-hook: log errors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2df6cf7 439/486: Don't fail on re-search-forward. (#359), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ca415e9 470/486: Add rust-check function, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e327658 274/486: Merge pull request #178 from ryuslash/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7e2533f 415/486: Fix rustc-compilation-regexps: match error messages with dashes. (#331), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9107989 424/486: review, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d0f3f45 431/486: imenu: fn items: match async/const and all pub variants. (#346),
ELPA Syncer <=
- [nongnu] elpa/rust-mode 7afad7b 464/486: rearrange II: Regexp variables and functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bbb3792 473/486: Remove "-face" suffix from names of faces, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3eb6d2f 485/486: Create rust-utils.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b81c723 467/486: Various cosmetic changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1f8a763 446/486: Fix typos, ELPA Syncer, 2021/08/07