summaryrefslogtreecommitdiff
path: root/rust-mode-tests.el
AgeCommit message (Collapse)Author
2017-08-21Added test for if-let font lockJonas Westlund
2017-08-14Fix recognition of "<" as operator in some contextTom Tromey
rust-mode identifies the "<<" as open angle brackets in let x = a[i][(1 << i)]; This patch fixes the problem by changing rust-is-in-expression-context to treat "]" as starting an expression in brace context. Fixes #212
2017-08-10Use `font-lock-variable-name-face' for `let' bindings.Aankhen
2017-08-05Merge pull request #220 from Aankhen/highlight-string-interpolationTom Tromey
Highlight interpolation in arguments to print! &c.
2017-08-02Make rust-beginning-of-defun ignore comments and stringsTom Tromey
Change rust-beginning-of-defun to keep searching when it stops in a comment or a string. Fixes #222.
2017-08-02Highlight interpolation in arguments to print! &c.Aankhen
2017-07-30Add syntax highlighting and imenu support for `union`Wilfred Hughes
`union` is a contextual keyword, so highlight it in the correct context. Otherwise, treat `union` similarly to `struct`.
2017-07-28Highlight question mark operator using new `rust-question-mark-face'.Aankhen
2017-07-13Define `rust-test-project-located' conditionally instead of using `skip-unless'.Aankhen
2017-07-13Skip `rust-test-project-located' without cargo and avoid `find-file' in test.Aankhen
2017-07-13Add `rust-run-clippy' and `rust-buffer-project' with testing paraphernalia.Aankhen
2017-05-06Add support for "default" keywordTom Tromey
Add context-sensitive fontification for the "default" keyword.
2017-04-11fix rust indentation bugTom Tromey
This patch fixes a bug I found where rust-mode would misindent code like: fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F) -> bool where F: FnMut(&'a str) -> bool { } fn test_split_within() { } In particular the second "fn" would be indented a level. On the "fn" line, rust-mode-indent-line was calling rust-beginning-of-defun, which would go to the previous defun. Fixing this required moving the definition of rust-top-item-beg-re higher in the file, before its first use (recent versions of Emacs insist on this). And, this required removing the "^" from this regexp, which is ok because the sole use is already adding a "^". Additionally, I moved the "\\_>" into the regexp, rather than have it added at the point of use, so that the new use would also benefit. This patch includes two new test cases.
2017-04-11Merge pull request #201 from tromey/question-indentationNiko Matsakis
fix syntax of "<" appearing after "?"
2017-04-11Merge pull request #197 from tromey/syntax-propertizeNiko Matsakis
Syntax propertize
2017-04-05fix syntax of "<" appearing after "?"Tom Tromey
The "<" syntax-setting code could be confused after a "?". This patch changes the code to treat "?" as an "ambiguous operator" and adjust according to further context. Fixes #200
2017-03-19set open-paren-in-column-0-is-defun-start to nilTom Tromey
Set open-paren-in-column-0-is-defun-start to nil in rust-mode. This setting is a performance hack in Emacs, at the expense of correctness in some cases. However, due to the syntax-ppss cache, I doubt whether this hack is needed for Rust code. Fixes #107
2017-03-15Use syntax-propertize-function, not font-lock-syntactic-keywordsTom Tromey
font-lock-syntactic-keywords have been obsolete since Emacs 24.1, the earliest version supported by rust-mode. Instead, modes are encouraged to use syntax-propertize-function. syntax-propertize-function provides a generally better experience. Syntax propertization is not tied to font lock,so angle bracket matching will still work when font-lock is disabled. There's no longer a need to call font-lock-fontify-buffer or font-lock-ensure (you can see this in the tests). The resulting code is also shorter. I removed a few tests: * font-lock-raw-string-constant was written assuming font-lock based syntax propertization, but that's no longer the case. * font-lock-extend-region-in-string and rust-test-revert-hook-preserves-point both called functions that no longer exist. There's a fix for a hidden bug in rust-is-in-expression-context. This previously could signal in some situations, but the signal was hidden by font-lock. It was visible now when running tests, hence the new call to condition-case. I suspect this might fix #192, but I haven't tried it.
2017-03-14Don't use "&optional &rest"Tom Tromey
rust-mode-tests.el uses "&optional &rest" in some function signatures. This was never really correct, and newer versions of Emacs complain about it. &rest implies &optional, so removing &optional is all that is needed.
2017-01-12Recognize "extern" imenu itemsmrBliss
Fixes #188.
2016-10-22Handle comments when indenting method chainsmrBliss
Previously, indentation went wrong when the comment on the line above looked like a method call/member access: fn main() { // Lorem ipsum lorem ipsum lorem ipsum lorem.ipsum foo.bar() } With this patch: fn main() { // Lorem ipsum lorem ipsum lorem ipsum lorem.ipsum foo.bar() } Also, a blank line or a comment broke method-chain indentation: fn main() { something.a.do_it // A comment .aligned .more_alignment(); } With this patch: fn main() { something.a.do_it // A comment .aligned .more_alignment(); } Note that comments interleaving a method chain are not aligned with the '.' of the method chain.
2016-09-09Test #169mrBliss
Before applying #169 the new test fails with a stack overflow, with #169 it passes.
2016-08-02rust--after-revert-hook should preserve point position.Wilfred Hughes
Otherwise, rust-format-buffer always moves point to the end of the buffer.
2016-04-25Properly fix #151mrBliss
Always check whether we're not in a string or comment when looking for the `where` keyword. Use two helpers for this: `rust-looking-at-where` and `rust-rewind-to-where`.
2016-04-24Fix #151mrBliss
When looking for a `where` in `rust-rewind-to-beginning-of-current-level-expr`, check that it is not part of a string or comment.
2016-04-06Fix failing tests, and add a test for the fix.Brian Mastenbrook
2016-03-09remove emacs 23 supportTom Tromey
This removes the various Emacs 23 compatibility hacks. Fixes #137. Fixes #139. This also obsoletes PR #141.
2016-02-25Fix font-locking for Unicode escapes in character literals.Georg Brandl
* There is only \u, no \U * \u requires braces, but allows 1-6 hex digits
2016-02-14Change font-lock face for module names.Georg Brandl
Use font-lock-constant-face instead of font-lock-type-face. Especially in paths, this tones down the importance of the path prefix, and makes the suffix more visible.
2016-01-15Fix indentation of closing delimitersEivind Fonn
2016-01-05Fix type annotations incorrectly highlighted as modules.Wilfred Hughes
Previously, we were always treating :: as a module, but Rust allows type annotations using :: e.g. parse::<i32>(); This also changes module highlighting so that only the module name is highlighted, excluding the ::. This makes rust-mode consistent with other Emacs modes, such as c++-mode and ruby-mode.
2015-12-15Re-fontify buffer after it is revertedMicah Chalmer
Fix #104
2015-12-03Merge pull request #110 from mrBliss/fix-103Niko Matsakis
Fix #103
2015-12-02Fix the special case for the first linemrBliss
This special case broke indentation of `where` clauses.
2015-12-02Correctly indent where clausesmrBliss
Revisit #82. Now rustfmt has a default style for `where` clauses, it makes sense to let rust-mode support it by default. How rust-mode currently indents `where` clauses is totally broken anyway. The line starting with `where` itself, the following lines that are part of the `where` clause, and the body were all indented incorrectly. This commit fixes this. **Note that this commit does not prescribe a certain indentation style for where clauses, but supports the most common ones, including rustfmt's default.** By choosing the location of (1) `where` and (2) the type parameter bounds, the user can follow three major indentation styles. There is no need for a configuration option to choose the style, as the locations of 1 and 2 dictate the style to follow. So all three styles can be used together in the same file. For each major style, the opening brace can be on the last line of the type parameter bounds or on a new line (a or b in the examples). All 6 styles are supported without having to change any configuration option. See the examples below and the new test cases. There is one more style that is unfortunately incompatible with the default `where` indentation style of rustfmt: when the user does not want `where` to be indented, but aligned with the `fn` or `trait` on the line before (see examples `foo4a` and `foo4b` below). To enable this style, the user has to set the new option `rust-indent-where-clause` to nil (it defaults to t). Putting `where` and the type parameter bounds on the same line as the function header is still supported of course (see examples `fooa` and `foob` below). As there is no indentation, this commit does not influence this. Note that rust-mode's indentation has a different goal than rustfmt. rustfmt reflows code, adds or removes line breaks, reindents, etc. rust-mode's indentation only indents lines. The goal is not to imitate rustfmt, but after running rustfmt on a file, reindenting it with rust-mode should be idempotent. This way, users do not have to deal with the eternal battle of differing indentation styles of rustfmt and rust-mode. The supported styles: ```rust fn foo1a(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } fn foo1b(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } ``` ```rust fn foo2a(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } fn foo2b(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } ``` ```rust fn foo3a(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } fn foo3b(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } ``` If the user wants `foo4` instead of `foo1`, `rust-indent-where-clause` must be set to nil. `foo2` and `foo3` are not influenced by this. ```rust fn foo4a(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } fn foo4a(a: A, b: B) -> C where A: Clone + Default, B: Eq, C: PartialEq { let body; } ``` Unchanged: ```rust fn fooa(a: A, b: B) -> C where A: Clone + Default, ... { let body; } fn foob(a: A, b: B) -> C where A: Clone + Default, ... { let body; } ```
2015-12-01Fix #103: comment indentation after struct membersmrBliss
Correctly indent comments that come after struct members that do not have a trailing comma. Before: struct A { x: u8 // TOO FAR } After: struct A { x: u8 // CORRECT }
2015-08-15Correcting highlighting of capitals in function names.Wilfred Hughes
Previously, code of the form: fn foo_Bar () {} would be incorrectly highlighted, because the regex matched on word boundaries rather than symbol boundaries. Test added.
2015-07-30Recognize runaway raw stringsMicah Chalmer
Recognize raw strings all the way to the end of the buffer if they are not closed. This is not valid rust code, but the highlighting should show the mistake. This also eliminates glitchy behavior that can occur in this situation. Emacs assumes that edits can't change syntax at positions before the edit, and raw strings without this change violated this.
2015-07-07Remove unnecessary code with call to undefined functionMicah Chalmer
2015-07-05Perform syntactic angle bracket matchingMicah Chalmer
Add angle brackets to the list of emacs matching characters. Use syntactic fontification to suppress this where it is not appropriate (in less than operators, arrows, etc.) Remove the non-syntactic version that was there previously. For electric-pair-mode, suppress the pairing for < and > characters that are not angle brackets. Because syntax is used for indentation, this fixes some problems with it, particularly when attempting to stretch type parameter lists over multiple lines.
2015-07-05Fix bugs in raw strings and character literalsMicah Chalmer
2015-07-05Factor out rust-conditional-re-search-forwardMicah Chalmer
Factor out the method of looking for a match for a regexp, but filtering out some of the matches with a filtering function. This will be used again for angle bracket filtering. This also fixes an issue with raw string handling.
2015-07-05Distinguish face for doc-commentsGeorg Brandl
Using the syntactic-face-function, we can assign the proper `font-lock-doc-face' to doc comments ("///", "//!", "/**", "/*!"). Test changes graciously copied from https://github.com/rust-lang/rust-mode/pull/64
2015-06-08Fix multi-line raw strings when editingMicah Chalmer
2015-04-30Add regression test for PR #52.Felix S. Klock II
Thanks again to @GBGamer !
2015-03-07Make fill-region work correctlyMicah Chalmer
2015-02-23Parse '\\' and '\"' as char literalsMicah Chalmer
2015-02-23Add a few more tests for indents inside stringsMicah Chalmer
2015-02-23Indent inside strings after ending backslashMicah Chalmer
2015-02-15Fix typo/missing lines in comment in testMicah Chalmer