branch: externals/csharp-mode commit a8d8ef8cba289ad4b87b1dc9637fc6994d186185 Author: Jostein Kjønigsen <jost...@kjonigsen.net> Commit: Jostein Kjønigsen <jost...@kjonigsen.net>
imenu: Index delegates Partially addresses https://github.com/josteink/csharp-mode/issues/80. --- csharp-mode.el | 30 ++++++++++++++++++++++++------ test-files/imenu-delegate-test.cs | 12 ++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/csharp-mode.el b/csharp-mode.el index fbbcaff..c328299 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -1778,7 +1778,7 @@ to the beginning of the prior namespace. (defconst csharp--imenu-expression (let* ((single-space "[ \t\n\r\f\v]") (optional-space (concat single-space "*")) - (bol (concat "^" optional-space)) + (bol "^[ \t]*") ;; BOL shouldnt accept lineshift. (space (concat single-space "+")) (access-modifier (regexp-opt '( "public" "private" "protected" "internal" "static" "sealed" "partial" "override" "virtual" @@ -1882,6 +1882,23 @@ to the beginning of the prior namespace. optional-space ;; abstract/extern methods are terminated with ; ";") 1) + ;; delegates are almost like abstract methods, so pick them up here + (list "delegate" + (concat bol + ;; we MUST require modifiers, or else we cannot reliably + ;; identify declarations, without also dragging in lots of + ;; if statements and what not. + access-modifier-list "+" + "delegate" space + return-type space + "\\(" + generic-identifier + optional-space + parameter-list + "\\)" + ;; optional // or /* comment at end + optional-space + ";") 1) (list "prop" (concat bol ;; must require access modifiers, or else we @@ -2089,16 +2106,17 @@ to the beginning of the prior namespace. (name (car (last type)))) (csharp--imenu-append-items-to-menu result key name index classes namespaces))) - ;; add enums to main result list, as own items. + ;; add enums and delegates to main result list, as own items. ;; We don't support nested types. EOS. ;; - ;; This has the issue that it gets reported as "function" in + ;; This has the issue that they get reported as "function" in ;; `helm-imenu', but there's nothing we can do about that. ;; The alternative is making it a menu with -1- submenu which ;; says "( top )" but that will be very clicky... - (dolist (enum (cdr (assoc "enum" index))) - (let ((enum-name (csharp--imenu-get-class-name enum namespaces))) - (setq result (cons (cons enum-name (cdr enum)) result)))) + (dolist (type '("enum" "delegate")) + (dolist (item (cdr (assoc type index))) + (let ((item-name (csharp--imenu-get-class-name item namespaces))) + (setq result (cons (cons item-name (cdr item)) result))))) ;; sort individual sub-lists (dolist (item result) diff --git a/test-files/imenu-delegate-test.cs b/test-files/imenu-delegate-test.cs new file mode 100644 index 0000000..77d7a4b --- /dev/null +++ b/test-files/imenu-delegate-test.cs @@ -0,0 +1,12 @@ +using System; + +namespace Boo +{ + public delegate void TargetCallback( Mobile from, object targeted ); + public delegate void TargetStateCallback( Mobile from, object targeted, object state ); + public delegate void TargetStateCallback<T>( Mobile from, object targeted, T state ); +} + +public delegate void PromptCallback( Mobile from, string text ); +public delegate void PromptStateCallback( Mobile from, string text, object state ); +public delegate void PromptStateCallback<T>( Mobile from, string text, T state );