[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 9d948d9 429/496: Add parser for function parame
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 9d948d9 429/496: Add parser for function parameters for Imenu |
Date: |
Sun, 29 Aug 2021 11:34:21 -0400 (EDT) |
branch: elpa/swift-mode
commit 9d948d9e07f48063b434904a5243818592f0372f
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Add parser for function parameters for Imenu
---
swift-mode-imenu.el | 89 ++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 75 insertions(+), 14 deletions(-)
diff --git a/swift-mode-imenu.el b/swift-mode-imenu.el
index 48ad200..df771e2 100644
--- a/swift-mode-imenu.el
+++ b/swift-mode-imenu.el
@@ -30,6 +30,7 @@
;;; Code:
(require 'swift-mode-lexer)
+(require 'seq)
;;;###autoload
(defgroup swift-mode:imenu nil
@@ -102,7 +103,8 @@ names."
"Scan declarations from current point.
Return found declarations in reverse order."
- (let (next-token
+ (let (previous-token
+ next-token
next-type
next-text
name-token
@@ -178,21 +180,35 @@ Return found declarations in reverse order."
(swift-mode:declaration (intern next-text) name-token nil)
declarations)))
- ((equal next-text "func")
+ ((member next-text '("func" "init" "subscript"))
(setq last-class-token nil)
- (setq name-token
- (swift-mode:forward-token-or-list-except-curly-bracket))
- ;; TODO parse parameter names?
- (when (memq (swift-mode:token:type name-token) '(identifier operator))
- (push
- (swift-mode:declaration 'func name-token nil)
- declarations)))
+ (unless (equal next-text "func")
+ (goto-char (swift-mode:token:start next-token)))
+ (let ((declaration-type (intern next-text))
+ (names (swift-mode:scan-function-name-and-parameter-names)))
+ (when names
+ (setq name-token (car names))
+ (push
+ (swift-mode:declaration
+ declaration-type
+ (swift-mode:token
+ (swift-mode:token:type name-token)
+ (concat (swift-mode:token:text name-token)
+ "("
+ (mapconcat
+ (lambda (token)
+ (concat (swift-mode:token:text token) ":"))
+ (cdr names)
+ "")
+ ")")
+ (swift-mode:token:start name-token)
+ (swift-mode:token:end name-token))
+ nil)
+ declarations))))
- ((member next-text '("init" "deinit" "subscript"))
+ ((equal next-text "deinit")
(setq last-class-token nil)
- (push
- (swift-mode:declaration (intern next-text) next-token nil)
- declarations))
+ (push (swift-mode:declaration 'deinit next-token nil) declarations))
((member next-text '("let" "var"))
(setq last-class-token nil)
@@ -208,7 +224,7 @@ Return found declarations in reverse order."
(when (equal (swift-mode:token:text next-token) "operator")
(setq name-token
(swift-mode:forward-token-or-list-except-curly-bracket))
- (when (eq (swift-mode:token:type name-token) 'operator)
+ (when (eq (swift-mode:token:type name-token) 'identifier)
(push
(swift-mode:declaration 'operator name-token nil)
declarations))))
@@ -297,6 +313,51 @@ TYPE is one of `case', `let', or `var'."
(goto-char (swift-mode:token:start next-token)))
items))
+(defun swift-mode:scan-function-name-and-parameter-names ()
+ (let* ((name-token
+ (swift-mode:forward-token-or-list-except-curly-bracket))
+ next-token
+ parameter-end
+ (parameter-names '())
+ (is-operator (seq-contains "/=-+!*%<>&|^~?."
+ (elt (swift-mode:token:text name-token)
0))))
+ (cond
+ ((eq (swift-mode:token:type name-token) 'identifier)
+ (while (progn
+ (setq next-token
+ (swift-mode:forward-token-or-list-except-curly-bracket))
+ (not (memq (swift-mode:token:type next-token)
+ '(\(\) \( { \; implicit-\; outside-of-buffer)))))
+ (if (eq (swift-mode:token:type next-token) '\(\))
+ (progn
+ (setq parameter-end (swift-mode:token:end next-token))
+ (goto-char (swift-mode:token:start next-token))
+ (swift-mode:forward-token)
+
+ (while (< (point) parameter-end)
+ (setq next-token (swift-mode:forward-token))
+
+ (when (eq (swift-mode:token:type next-token) 'identifier)
+ (when (or is-operator
+ (and (equal (swift-mode:token:text name-token)
+ "subscript")
+ (eq (swift-mode:token:type
+ (swift-mode:forward-token-or-list))
+ ':)))
+ (setq next-token (swift-mode:token
+ 'identifier
+ "_"
+ (swift-mode:token:start next-token)
+ (swift-mode:token:end next-token))))
+ (push next-token parameter-names))
+
+ (while (and (< (point) parameter-end)
+ (not (eq (swift-mode:token:type next-token) '\,)))
+ (setq next-token (swift-mode:forward-token-or-list))))
+ (cons name-token (reverse parameter-names)))
+ (list name-token)))
+ (t nil))))
+
(defun swift-mode:format-for-imenu:flat (declarations)
"Convert list of DECLARATIONS to alist for `imenu--index-alist'.
- [nongnu] elpa/swift-mode 604610d 399/496: Fix LLDB breakpoint option, (continued)
- [nongnu] elpa/swift-mode 604610d 399/496: Fix LLDB breakpoint option, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6fdb3cd 403/496: Fix `swift-mode:debug-swift-module`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d2f2f1d 410/496: Bump version to 6.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f847923 419/496: Highlight more compiler directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0b1e5e8 420/496: Support raw texts, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 348e153 422/496: Change buffer name of REPL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0eca818 431/496: Add test for Imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ddc7ae6 436/496: Fix `adaptive-fill-regexp` for multiline comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2e9bdc6 430/496: Ignore import declarations in Imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b2d9cca 434/496: Fix small bugs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9d948d9 429/496: Add parser for function parameters for Imenu,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 1362849 435/496: Use `seq-mapcat` instead of `apply` '`nonc` and `mapcar`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 64dff57 441/496: Update standard types, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 62cf880 437/496: Update electric indent inside multiline comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 04c8a62 442/496: Fix beginning-of-defun hanging at the beginning of buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 286b46e 459/496: Highlight #filePath, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode fa22f12 461/496: Add tests for multiple trailing closures, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2ab9ea1 458/496: Bump version to 8.0.2, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a067fe7 454/496: Add travis emacs version 26.2 and 26.3, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 29759f5 456/496: Fix indentation of generic-parameter-clause, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5eb806b 470/496: Fix GitHub Action, ELPA Syncer, 2021/08/29