Skip to content

Commit 897c85a

Browse files
committed
imenu: Fix indexing of delegates.
With or without namespace. Add tests. This closes #80.
1 parent 7baacd5 commit 897c85a

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

csharp-mode-tests.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@
234234
"(method) AbstractMethod("
235235
"(method) UnsafeCopy(")
236236

237+
(def-imenutest imenu-parsing-supports-delegates
238+
"./test-files/imenu-delegate-test.cs"
239+
"delegate PromptCallback"
240+
"delegate PromptStateCallback"
241+
"delegate PromptStateCallback<T>"
242+
"delegate Foobar.TargetCallback"
243+
"delegate Foobar.TargetStateCallback"
244+
"delegate Foobar.TargetStateCallback<T>")
245+
237246
(ert-deftest imenu-indexing-resolves-correct-container ()
238247
(let* ((testcase-no-namespace '( ("class Global" . 10)
239248
(("namespace_a" . 20) ("namespace_b" . 30))

csharp-mode.el

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,9 +1893,9 @@ to the beginning of the prior namespace.
18931893
return-type space
18941894
"\\("
18951895
generic-identifier
1896+
"\\)"
18961897
optional-space
18971898
parameter-list
1898-
"\\)"
18991899
;; optional // or /* comment at end
19001900
optional-space
19011901
";") 1)
@@ -2113,10 +2113,19 @@ to the beginning of the prior namespace.
21132113
;; `helm-imenu', but there's nothing we can do about that.
21142114
;; The alternative is making it a menu with -1- submenu which
21152115
;; says "( top )" but that will be very clicky...
2116+
2117+
;; before adding delegates, we need to pad the entry so that it
2118+
;; matches the "<type> <name>" signature used by all the other
2119+
;; imenu entries
2120+
(let ((delegates (cdr (assoc "delegate" index))))
2121+
(dolist (delegate delegates)
2122+
(setf (car delegate) (concat "delegate " (car delegate)))))
2123+
21162124
(dolist (type '("enum" "delegate"))
21172125
(dolist (item (cdr (assoc type index)))
21182126
(let ((item-name (csharp--imenu-get-class-name item namespaces)))
2119-
(setq result (cons (cons item-name (cdr item)) result)))))
2127+
(setq result (cons (cons item-name (cdr item))
2128+
result)))))
21202129

21212130
;; sort individual sub-lists
21222131
(dolist (item result)

test-files/imenu-delegate-test.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22

3-
namespace Boo
3+
public delegate void PromptCallback( Mobile from, string text );
4+
public delegate void PromptStateCallback( Mobile from, string text, object state );
5+
public delegate void PromptStateCallback<T>( Mobile from, string text, T state );
6+
7+
namespace Foobar
48
{
59
public delegate void TargetCallback( Mobile from, object targeted );
610
public delegate void TargetStateCallback( Mobile from, object targeted, object state );
711
public delegate void TargetStateCallback<T>( Mobile from, object targeted, T state );
812
}
9-
10-
public delegate void PromptCallback( Mobile from, string text );
11-
public delegate void PromptStateCallback( Mobile from, string text, object state );
12-
public delegate void PromptStateCallback<T>( Mobile from, string text, T state );

0 commit comments

Comments
 (0)