Skip to content

Commit

Permalink
Ignore code block annotations in docstrings
Browse files Browse the repository at this point in the history
Improves #66.
  • Loading branch information
Wilfred committed Nov 5, 2016
1 parent 8edead2 commit d7e7333
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions racer.el
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ the user to choose."
((and (not in-code) (string-match-p (rx bol "[`" (+? anything) "`]: ") line)))
;; Skip repeated blank lines (caused by skipping cross references).
((and (equal line "") (equal (-first-item current-section-lines) "")))
;; Skip lines in code blocks that are rustdoc annotations, e.g. # #[allow(dead_code)]
((and in-code (s-starts-with-p "# " line)))
;; Otherwise, just keep appending the line to the current
;; section.
(t
Expand Down
21 changes: 21 additions & 0 deletions test/racer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ bar.
2
")))

(defun racer--remove-properties (text)
"Remove all the properties on TEXT.
Tests that use `equal' ignore properties, but
this makes the ert failure descriptions clearer."
(with-temp-buffer
(insert text)
(buffer-substring-no-properties (point-min) (point-max))))

(ert-deftest racer--propertize-docstring-code-annotations ()
"Ignore '# foo' lines in code sections in docstrings."
(should
(equal
(racer--remove-properties
(racer--propertize-docstring "```
# #[allow(dead_code)]
#[derive(Debug)]
struct Foo {}
```"))
" #[derive(Debug)]
struct Foo {}")))

(ert-deftest racer--propertize-docstring-newlines ()
"Ensure we still handle links that have been split over two lines."
(should
Expand Down

0 comments on commit d7e7333

Please sign in to comment.