Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 8fd29c2

Browse files
committed
Pass tab size and tabs/spaces to rustfmt
cc #3
1 parent c750c66 commit 8fd29c2

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ impl ActionHandler {
430430
}
431431
}
432432

433-
pub fn reformat(&self, id: usize, doc: TextDocumentIdentifier, out: &Output) {
434-
trace!("Reformat: {} {:?}", id, doc);
433+
pub fn reformat(&self, id: usize, doc: TextDocumentIdentifier, out: &Output, opts: &FormattingOptions) {
434+
trace!("Reformat: {} {:?} {} {}", id, doc, opts.tab_size, opts.insert_spaces);
435435

436436
let path = &parse_file_path(&doc.uri).unwrap();
437437
let input = match self.vfs.load_file(path) {
@@ -448,8 +448,16 @@ impl ActionHandler {
448448
}
449449
};
450450
let config = self.fmt_config.lock().unwrap();
451+
let mut config = config.get_rustfmt_config().clone();
452+
if !config.was_set().hard_tabs() {
453+
config.set().hard_tabs(!opts.insert_spaces);
454+
}
455+
if !config.was_set().tab_spaces() {
456+
config.set().tab_spaces(opts.tab_size as usize);
457+
}
458+
451459
let mut buf = Vec::<u8>::new();
452-
match format_input(input, config.get_rustfmt_config(), Some(&mut buf)) {
460+
match format_input(input, &config, Some(&mut buf)) {
453461
Ok((summary, ..)) => {
454462
// format_input returns Ok even if there are any errors, i.e., parsing errors.
455463
if summary.has_no_errors() {

src/server.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,11 @@ impl LsService {
442442
DocumentSymbols(params) => { action: symbols };
443443
Rename(params) => { action: rename };
444444
Formatting(params) => {
445-
// FIXME take account of options.
446-
this.handler.reformat(id, params.text_document, &*this.output)
445+
this.handler.reformat(id, params.text_document, &*this.output, &params.options)
447446
};
448447
RangeFormatting(params) => {
449448
// FIXME reformats the whole file, not just a range.
450-
// FIXME take account of options.
451-
this.handler.reformat(id, params.text_document, &*this.output)
449+
this.handler.reformat(id, params.text_document, &*this.output, &params.options)
452450
};
453451
}
454452
notifications {

0 commit comments

Comments
 (0)