Skip to content

Commit a8d8ef8

Browse files
committed
imenu: Index delegates
Partially addresses #80.
1 parent 717bf76 commit a8d8ef8

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

csharp-mode.el

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ to the beginning of the prior namespace.
17781778
(defconst csharp--imenu-expression
17791779
(let* ((single-space "[ \t\n\r\f\v]")
17801780
(optional-space (concat single-space "*"))
1781-
(bol (concat "^" optional-space))
1781+
(bol "^[ \t]*") ;; BOL shouldnt accept lineshift.
17821782
(space (concat single-space "+"))
17831783
(access-modifier (regexp-opt '( "public" "private" "protected" "internal"
17841784
"static" "sealed" "partial" "override" "virtual"
@@ -1882,6 +1882,23 @@ to the beginning of the prior namespace.
18821882
optional-space
18831883
;; abstract/extern methods are terminated with ;
18841884
";") 1)
1885+
;; delegates are almost like abstract methods, so pick them up here
1886+
(list "delegate"
1887+
(concat bol
1888+
;; we MUST require modifiers, or else we cannot reliably
1889+
;; identify declarations, without also dragging in lots of
1890+
;; if statements and what not.
1891+
access-modifier-list "+"
1892+
"delegate" space
1893+
return-type space
1894+
"\\("
1895+
generic-identifier
1896+
optional-space
1897+
parameter-list
1898+
"\\)"
1899+
;; optional // or /* comment at end
1900+
optional-space
1901+
";") 1)
18851902
(list "prop"
18861903
(concat bol
18871904
;; must require access modifiers, or else we
@@ -2089,16 +2106,17 @@ to the beginning of the prior namespace.
20892106
(name (car (last type))))
20902107
(csharp--imenu-append-items-to-menu result key name index classes namespaces)))
20912108

2092-
;; add enums to main result list, as own items.
2109+
;; add enums and delegates to main result list, as own items.
20932110
;; We don't support nested types. EOS.
20942111
;;
2095-
;; This has the issue that it gets reported as "function" in
2112+
;; This has the issue that they get reported as "function" in
20962113
;; `helm-imenu', but there's nothing we can do about that.
20972114
;; The alternative is making it a menu with -1- submenu which
20982115
;; says "( top )" but that will be very clicky...
2099-
(dolist (enum (cdr (assoc "enum" index)))
2100-
(let ((enum-name (csharp--imenu-get-class-name enum namespaces)))
2101-
(setq result (cons (cons enum-name (cdr enum)) result))))
2116+
(dolist (type '("enum" "delegate"))
2117+
(dolist (item (cdr (assoc type index)))
2118+
(let ((item-name (csharp--imenu-get-class-name item namespaces)))
2119+
(setq result (cons (cons item-name (cdr item)) result)))))
21022120

21032121
;; sort individual sub-lists
21042122
(dolist (item result)

test-files/imenu-delegate-test.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Boo
4+
{
5+
public delegate void TargetCallback( Mobile from, object targeted );
6+
public delegate void TargetStateCallback( Mobile from, object targeted, object state );
7+
public delegate void TargetStateCallback<T>( Mobile from, object targeted, T state );
8+
}
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)