Skip to content

rustfmt should display errors #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nikomatsakis opened this issue Apr 5, 2017 · 4 comments
Open

rustfmt should display errors #204

nikomatsakis opened this issue Apr 5, 2017 · 4 comments
Labels

Comments

@nikomatsakis
Copy link
Contributor

If you run rustfmt and it errors out, it currently just "beeps" and suggests you switch over to *rustfmt*. I think this should be treated like a failed compilation; we should split the frame into two windows, show the errors, and let you use M-x next-error to view them.

Example 1, which errors because it doesn't parse:

fn main() {
    let x &'static str = "aaa";
}

Example 2, undefined module:

mod a;

fn main() {
    let x: &'static str = "aaa";
}

Example 3, long lines:

fn main() {
    let x:
    &'static str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
}
@brotzeit
Copy link
Contributor

brotzeit commented Aug 20, 2017

I've tried to solve this with shell-command-on-region, but it doesn't work for example 2 as the function returns 0 in this case. Does anybody know why ?

;; Formatting using rustfmt
(defun rust--format-call (buf)
  "Format BUF using rustfmt."
(let ((fmt-buffer (get-buffer-create "*rustfmt*")))
    (with-current-buffer fmt-buffer
      (let ((buffer-read-only nil))
        (erase-buffer)
        (insert-buffer-substring buf)
        (let ((ret (shell-command-on-region (point-min) (point-max)
                                            rust-rustfmt-bin fmt-buffer
                                            nil)))
          (cond
           ((zerop ret)
            (if (not (string= (buffer-string)
                              (with-current-buffer buf (buffer-string))))
                (copy-to-buffer buf (point-min) (point-max)))
            (kill-buffer)
            (message "Formatted buffer with rustfmt."))
           (t
            (let ((path (buffer-file-name buf)))
              (goto-char (point-min))
              (save-excursion
              (while (re-search-forward "stdin" nil t)
                (replace-match path))
              (compilation-mode)
              (pop-to-buffer fmt-buffer))
              (message "Rustfmt could not format some lines.")))))))))

@tromey
Copy link
Contributor

tromey commented Sep 17, 2017

Does anybody know why ?

All I really know is that shell-command-on-region returns the exist code of the subprocess. So it must be doing exit 0.

@brotzeit
Copy link
Contributor

brotzeit commented Jan 8, 2022

This was added some time ago and can be used with the option rust-format-show-buffer.

@brotzeit brotzeit closed this as completed Jan 8, 2022
@brotzeit
Copy link
Contributor

brotzeit commented Jan 8, 2022

Oh maybe I'm wrong, I'll better check. It just looked like it was implemented...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants