branch: elpa/swift-mode commit 07f643479789ef219ad3e3d009e641ad954363f9 Author: ap4y <l...@pisem.net> Commit: ap4y <l...@pisem.net>
Fix indentation issues with type annotations --- swift-mode.el | 10 +++++++++- test/indentation-tests.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/swift-mode.el b/swift-mode.el index bee995e..ac810cd 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -66,7 +66,7 @@ (smie-merge-prec2s (smie-bnf->prec2 '((id) - (type) + (type (type) (type "<T" types "T>")) (types (type) (type "," type)) (class-decl-exp (id) (id ":" types)) @@ -194,6 +194,10 @@ ";") ((looking-at "{") (forward-char 1) "{") ((looking-at "}") (forward-char 1) "}") + ((looking-at "<") (forward-char 1) + (if (looking-at "[[:upper:]]") "<T" "OP")) + ((looking-at ">") (forward-char 1) + (if (looking-back "[[:space:]]>" 2 t) "OP" "T>")) ((looking-at swift-smie--operators-regexp) (goto-char (match-end 0)) "OP") ((looking-at swift-smie--decl-specifier-regexp) @@ -209,6 +213,10 @@ ";") ((eq (char-before) ?\{) (backward-char 1) "{") ((eq (char-before) ?\}) (backward-char 1) "}") + ((eq (char-before) ?<) (backward-char 1) + (if (looking-at "<[[:upper:]]") "<T" "OP")) + ((eq (char-before) ?>) (backward-char 1) + (if (looking-back "[[:space:]]" 1 t) "OP" "T>")) ((looking-back swift-smie--operators-regexp (- (point) 3) t) (goto-char (match-beginning 0)) "OP") ((looking-back swift-smie--decl-specifier-regexp (- (point) 8) t) diff --git a/test/indentation-tests.el b/test/indentation-tests.el index 24c8b72..4c9152a 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -721,6 +721,55 @@ let foo = [ ] ") +(check-indentation indents-declaration/7 + " +var result = Dictionary<String, V>() + |foo +" " +var result = Dictionary<String, V>() +|foo +") + +(check-indentation indents-type-annotations/1 + " +typealias Foo = Bar<Foo.Baz, Foo> + |foo +" " +typealias Foo = Bar<Foo.Baz, Foo> +|foo +") + +(check-indentation indents-type-annotations/2 + " +typealias Foo = Bar<Foo.Baz, +|Foo> +" " +typealias Foo = Bar<Foo.Baz, + |Foo> +") + +(check-indentation indents-type-works-with-less-operator/1 + " +typealias Foo = Bar<Foo.Baz, Foo> +let foo = bar < +|baz +" " +typealias Foo = Bar<Foo.Baz, Foo> +let foo = bar < + |baz +") + +(check-indentation indents-type-works-with-less-operator/2 + " +typealias Foo = Bar<Foo.Baz, Foo> +let foo = bar > +|baz +" " +typealias Foo = Bar<Foo.Baz, Foo> +let foo = bar > + |baz +") + (provide 'indentation-tests) ;;; indentation-tests.el ends here