mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 02:06:57 +00:00
fix off-by-one error
This commit is contained in:
parent
35181e167e
commit
1db9402558
3 changed files with 77 additions and 6 deletions
|
|
@ -2284,7 +2284,8 @@ fn run_rustfmt(
|
|||
cmd.arg(
|
||||
json!([{
|
||||
"file": "stdin",
|
||||
"range": [start_line, end_line]
|
||||
// LineCol is 0-based, but rustfmt is 1-based.
|
||||
"range": [start_line + 1, end_line + 1]
|
||||
}])
|
||||
.to_string(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@ use lsp_types::{
|
|||
notification::DidOpenTextDocument,
|
||||
request::{
|
||||
CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
|
||||
InlayHintRequest, InlayHintResolveRequest, WillRenameFiles, WorkspaceSymbolRequest,
|
||||
InlayHintRequest, InlayHintResolveRequest, RangeFormatting, WillRenameFiles,
|
||||
WorkspaceSymbolRequest,
|
||||
},
|
||||
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
|
||||
DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
|
||||
InlayHint, InlayHintLabel, InlayHintParams, PartialResultParams, Position, Range,
|
||||
RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams,
|
||||
DocumentFormattingParams, DocumentRangeFormattingParams, FileRename, FormattingOptions,
|
||||
GotoDefinitionParams, HoverParams, InlayHint, InlayHintLabel, InlayHintParams,
|
||||
PartialResultParams, Position, Range, RenameFilesParams, TextDocumentItem,
|
||||
TextDocumentPositionParams, WorkDoneProgressParams,
|
||||
};
|
||||
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams};
|
||||
use serde_json::json;
|
||||
|
|
@ -660,6 +662,70 @@ fn main() {}
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_document_range() {
|
||||
if skip_slow_tests() {
|
||||
return;
|
||||
}
|
||||
|
||||
let server = Project::with_fixture(
|
||||
r#"
|
||||
//- /Cargo.toml
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.0"
|
||||
|
||||
//- /src/lib.rs
|
||||
fn main() {
|
||||
let unit_offsets_cache = collect(dwarf.units ()) ?;
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.with_config(serde_json::json!({
|
||||
"rustfmt": {
|
||||
"overrideCommand": [ "rustfmt", "+nightly", ],
|
||||
"rangeFormatting": { "enable": true }
|
||||
},
|
||||
}))
|
||||
.server()
|
||||
.wait_until_workspace_is_loaded();
|
||||
|
||||
server.request::<RangeFormatting>(
|
||||
DocumentRangeFormattingParams {
|
||||
range: Range {
|
||||
end: Position { line: 1, character: 0 },
|
||||
start: Position { line: 1, character: 0 },
|
||||
},
|
||||
text_document: server.doc_id("src/lib.rs"),
|
||||
options: FormattingOptions {
|
||||
tab_size: 4,
|
||||
insert_spaces: false,
|
||||
insert_final_newline: None,
|
||||
trim_final_newlines: None,
|
||||
trim_trailing_whitespace: None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
work_done_progress_params: WorkDoneProgressParams::default(),
|
||||
},
|
||||
json!([
|
||||
{
|
||||
"newText": "",
|
||||
"range": {
|
||||
"start": { "character": 48, "line": 1 },
|
||||
"end": { "character": 50, "line": 1 },
|
||||
},
|
||||
},
|
||||
{
|
||||
"newText": "",
|
||||
"range": {
|
||||
"start": { "character": 53, "line": 1 },
|
||||
"end": { "character": 55, "line": 1 },
|
||||
},
|
||||
}
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_missing_module_code_action() {
|
||||
if skip_slow_tests() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue