branch: externals/csharp-mode commit 897c85aef828f24148a782d591c7f70844627c39 Author: Jostein Kjønigsen <jost...@kjonigsen.net> Commit: Jostein Kjønigsen <jost...@kjonigsen.net>
imenu: Fix indexing of delegates. With or without namespace. Add tests. This closes https://github.com/josteink/csharp-mode/issues/80. --- csharp-mode-tests.el | 9 +++++++++ csharp-mode.el | 13 +++++++++++-- test-files/imenu-delegate-test.cs | 10 +++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/csharp-mode-tests.el b/csharp-mode-tests.el index 98bda72..ea98ee7 100644 --- a/csharp-mode-tests.el +++ b/csharp-mode-tests.el @@ -234,6 +234,15 @@ "(method) AbstractMethod(" "(method) UnsafeCopy(") +(def-imenutest imenu-parsing-supports-delegates + "./test-files/imenu-delegate-test.cs" + "delegate PromptCallback" + "delegate PromptStateCallback" + "delegate PromptStateCallback<T>" + "delegate Foobar.TargetCallback" + "delegate Foobar.TargetStateCallback" + "delegate Foobar.TargetStateCallback<T>") + (ert-deftest imenu-indexing-resolves-correct-container () (let* ((testcase-no-namespace '( ("class Global" . 10) (("namespace_a" . 20) ("namespace_b" . 30)) diff --git a/csharp-mode.el b/csharp-mode.el index c328299..1a3481b 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -1893,9 +1893,9 @@ to the beginning of the prior namespace. return-type space "\\(" generic-identifier + "\\)" optional-space parameter-list - "\\)" ;; optional // or /* comment at end optional-space ";") 1) @@ -2113,10 +2113,19 @@ to the beginning of the prior namespace. ;; `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... + + ;; before adding delegates, we need to pad the entry so that it + ;; matches the "<type> <name>" signature used by all the other + ;; imenu entries + (let ((delegates (cdr (assoc "delegate" index)))) + (dolist (delegate delegates) + (setf (car delegate) (concat "delegate " (car delegate))))) + (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))))) + (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 index 77d7a4b..3127958 100644 --- a/test-files/imenu-delegate-test.cs +++ b/test-files/imenu-delegate-test.cs @@ -1,12 +1,12 @@ using System; -namespace Boo +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 ); + +namespace Foobar { 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 );