[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 2cd3cf9 216/486: Merge pull request #116 from Wi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 2cd3cf9 216/486: Merge pull request #116 from Wilfred/type_annotation_highlighting |
Date: |
Sat, 7 Aug 2021 09:25:22 -0400 (EDT) |
branch: elpa/rust-mode
commit 2cd3cf93853fc8e46011f4d98bd95ffa695c6257
Merge: 061e6d8 dd6d417
Author: Niko Matsakis <niko@alum.mit.edu>
Commit: Niko Matsakis <niko@alum.mit.edu>
Merge pull request #116 from Wilfred/type_annotation_highlighting
Fix type annotations incorrectly highlighted as modules.
---
rust-mode-tests.el | 21 +++++++++++++++++++++
rust-mode.el | 20 ++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index e7a0429..e41245f 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1403,6 +1403,27 @@ this_is_not_a_string();)"
"\"/*! doc */\""
'("\"/*! doc */\"" font-lock-string-face)))
+(ert-deftest font-lock-module ()
+ (rust-test-font-lock
+ "foo::bar"
+ '("foo" font-lock-type-face)))
+
+(ert-deftest font-lock-submodule ()
+ (rust-test-font-lock
+ "foo::bar::baz"
+ '("foo" font-lock-type-face
+ "bar" font-lock-type-face)))
+
+(ert-deftest font-lock-type-annotation ()
+ "Ensure type annotations are not confused with modules."
+ (rust-test-font-lock
+ "parse::<i32>();"
+ ;; Only the i32 should have been highlighted.
+ '("i32" font-lock-type-face))
+ (rust-test-font-lock
+ "foo:: <i32>"
+ ;; Only the i32 should have been highlighted.
+ '("i32" font-lock-type-face)))
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
diff --git a/rust-mode.el b/rust-mode.el
index 8049273..4697c70 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -14,6 +14,7 @@
;;; Code:
(eval-when-compile (require 'rx)
+ (require 'cl)
(require 'compile)
(require 'url-vars))
@@ -525,6 +526,21 @@ function or trait. When nil, where will be aligned with
fn or trait."
(concat "\\_<" (regexp-opt words t) "\\_>"))
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
+
+(defun rust-module-font-lock-matcher (limit)
+ "Matches module names \"foo::\" but does not match type annotations
\"foo::<\"."
+ (block nil
+ (while t
+ (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp
,rust-re-ident)) "::")))
+ (match (re-search-forward symbol-then-colons limit t)))
+ (cond
+ ;; If we didn't find a match, there are no more occurrences
+ ;; of foo::, so return.
+ ((null match) (return nil))
+ ;; If this isn't a type annotation foo::<, we've found a
+ ;; match, so a return it!
+ ((not (looking-at (rx (0+ space) "<"))) (return match)))))))
+
(defvar rust-mode-font-lock-keywords
(append
`(
@@ -548,8 +564,8 @@ function or trait. When nil, where will be aligned with fn
or trait."
;; Field names like `foo:`, highlight excluding the :
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1
font-lock-variable-name-face)
- ;; Module names like `foo::`, highlight including the ::
- (,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face)
+ ;; Module names like `foo::`, highlight excluding the ::
+ (rust-module-font-lock-matcher 1 font-lock-type-face)
;; Lifetimes like `'foo`
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1
font-lock-variable-name-face)
- [nongnu] elpa/rust-mode ac92ff6 037/486: etc: add the `in` keyword to the emacs mode., (continued)
- [nongnu] elpa/rust-mode ac92ff6 037/486: etc: add the `in` keyword to the emacs mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9640fe8 051/486: Indent return type to align with arguments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0256f02 302/486: Fix stupid mistake in rustfmt conditional, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3220937 304/486: Merge pull request #209 from tromey/default-keyword, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a33b684 207/486: Fix #103: comment indentation after struct members, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 339afba 206/486: Highlight the unsafe keyword, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fa5b38f 218/486: Merge pull request #117 from TheBB/fix-closing-delim, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1ceac8b 212/486: Re-fontify buffer after it is reverted, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 01db4cb 225/486: Fix font-locking for Unicode escapes in character literals., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b874bbe 213/486: Merge pull request #113 from MicahChalmer/fix-issue-104, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2cd3cf9 216/486: Merge pull request #116 from Wilfred/type_annotation_highlighting,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 3517321 230/486: Merge pull request #129 from MicahChalmer/fix-issue-127, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8400638 241/486: update README.md and Package-Requires to require emacs 24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c3feac1 243/486: Fill regular block comments correctly too, in addition to rustdoc comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1587839 268/486: Merge pull request #169 from mrBliss/fix-168, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 664c7b0 277/486: improve position recovery in rust-format-buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 46e7fc0 285/486: fix PR link in README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 35298ed 288/486: Don't use "&optional &rest", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3301c70 047/486: Align field names in struct expressions with fields on same line as the opening curly brace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fe55b71 046/486: Multiline comments with leading *s line up the *s, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode af2aba9 049/486: Indent correctly after opening square bracket, ELPA Syncer, 2021/08/07