2020-08-18 03:38:57 -05:00
|
|
|
//! The most high-level integrated tests for rust-analyzer.
|
|
|
|
//!
|
|
|
|
//! This tests run a full LSP event loop, spawn cargo and process stdlib from
|
|
|
|
//! sysroot. For this reason, the tests here are very slow, and should be
|
|
|
|
//! avoided unless absolutely necessary.
|
|
|
|
//!
|
|
|
|
//! In particular, it's fine *not* to test that client & server agree on
|
|
|
|
//! specific JSON shapes here -- there's little value in such tests, as we can't
|
|
|
|
//! be sure without a real client anyway.
|
|
|
|
|
2021-07-03 14:11:03 -05:00
|
|
|
mod sourcegen;
|
2021-07-04 04:42:35 -05:00
|
|
|
mod tidy;
|
2020-07-23 15:26:25 -05:00
|
|
|
mod testdir;
|
2018-09-01 12:21:11 -05:00
|
|
|
mod support;
|
|
|
|
|
2020-04-23 11:50:25 -05:00
|
|
|
use std::{collections::HashMap, path::PathBuf, time::Instant};
|
2019-01-10 15:37:10 -06:00
|
|
|
|
2021-01-06 04:54:28 -06:00
|
|
|
use expect_test::expect;
|
2019-01-14 04:55:56 -06:00
|
|
|
use lsp_types::{
|
2020-05-10 12:25:37 -05:00
|
|
|
notification::DidOpenTextDocument,
|
2021-01-12 10:30:49 -06:00
|
|
|
request::{
|
|
|
|
CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
|
2021-05-17 10:43:20 -05:00
|
|
|
WillRenameFiles,
|
2021-01-12 10:30:49 -06:00
|
|
|
},
|
2020-05-10 12:25:37 -05:00
|
|
|
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
|
2021-01-12 10:30:49 -06:00
|
|
|
DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
|
2021-05-17 10:43:20 -05:00
|
|
|
PartialResultParams, Position, Range, RenameFilesParams, TextDocumentItem,
|
|
|
|
TextDocumentPositionParams, WorkDoneProgressParams,
|
2019-01-03 07:43:47 -06:00
|
|
|
};
|
2020-05-10 12:25:37 -05:00
|
|
|
use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
|
2021-05-17 10:43:20 -05:00
|
|
|
use serde_json::json;
|
2019-12-07 05:46:36 -06:00
|
|
|
use test_utils::skip_slow_tests;
|
2018-09-01 12:21:11 -05:00
|
|
|
|
2020-07-23 15:26:25 -05:00
|
|
|
use crate::{
|
|
|
|
support::{project, Project},
|
|
|
|
testdir::TestDir,
|
|
|
|
};
|
2018-09-01 12:21:11 -05:00
|
|
|
|
2020-02-18 06:53:02 -06:00
|
|
|
const PROFILE: &str = "";
|
2019-05-29 02:33:09 -05:00
|
|
|
// const PROFILE: &'static str = "*@3>100";
|
2018-09-02 06:46:15 -05:00
|
|
|
|
2019-01-10 11:13:08 -06:00
|
|
|
#[test]
|
|
|
|
fn completes_items_from_standard_library() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-19 07:41:18 -05:00
|
|
|
let server = Project::with_fixture(
|
2019-01-10 11:13:08 -06:00
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2019-01-10 11:13:08 -06:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2019-01-10 15:37:10 -06:00
|
|
|
use std::collections::Spam;
|
2019-01-10 11:13:08 -06:00
|
|
|
"#,
|
2019-08-19 07:41:18 -05:00
|
|
|
)
|
2021-03-01 03:14:16 -06:00
|
|
|
.with_config(serde_json::json!({
|
|
|
|
"cargo": { "noSysroot": false }
|
|
|
|
}))
|
2020-08-25 12:02:28 -05:00
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
2019-01-10 15:37:10 -06:00
|
|
|
let res = server.send_request::<Completion>(CompletionParams {
|
2019-07-07 13:13:13 -05:00
|
|
|
text_document_position: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/lib.rs"),
|
|
|
|
Position::new(0, 23),
|
|
|
|
),
|
2019-01-10 15:37:10 -06:00
|
|
|
context: None,
|
2019-12-11 11:34:01 -06:00
|
|
|
partial_result_params: PartialResultParams::default(),
|
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2019-01-10 15:37:10 -06:00
|
|
|
});
|
2020-06-11 04:04:09 -05:00
|
|
|
assert!(res.to_string().contains("HashMap"));
|
2019-01-10 11:13:08 -06:00
|
|
|
}
|
|
|
|
|
2018-09-02 08:36:03 -05:00
|
|
|
#[test]
|
|
|
|
fn test_runnables_project() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-25 12:02:28 -05:00
|
|
|
let server = Project::with_fixture(
|
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /foo/Cargo.toml
|
2018-09-02 08:36:03 -05:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /foo/src/lib.rs
|
2018-09-02 08:36:03 -05:00
|
|
|
pub fn foo() {}
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /foo/tests/spam.rs
|
2018-09-02 08:36:03 -05:00
|
|
|
#[test]
|
|
|
|
fn test_eggs() {}
|
2019-04-13 13:33:49 -05:00
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /bar/Cargo.toml
|
2019-04-13 13:33:49 -05:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /bar/src/main.rs
|
2019-04-13 13:33:49 -05:00
|
|
|
fn main() {}
|
2020-08-25 12:02:28 -05:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.root("foo")
|
|
|
|
.root("bar")
|
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
2019-04-13 13:33:49 -05:00
|
|
|
|
2018-09-02 08:36:03 -05:00
|
|
|
server.request::<Runnables>(
|
2020-03-12 15:28:26 -05:00
|
|
|
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
|
2018-12-06 14:07:31 -06:00
|
|
|
json!([
|
2020-06-02 11:02:58 -05:00
|
|
|
{
|
|
|
|
"args": {
|
|
|
|
"cargoArgs": ["test", "--package", "foo", "--test", "spam"],
|
|
|
|
"executableArgs": ["test_eggs", "--exact", "--nocapture"],
|
2020-09-05 09:16:32 -05:00
|
|
|
"cargoExtraArgs": [],
|
|
|
|
"overrideCargo": null,
|
2020-06-02 11:02:58 -05:00
|
|
|
"workspaceRoot": server.path().join("foo")
|
2019-04-13 12:45:21 -05:00
|
|
|
},
|
2020-06-02 11:02:58 -05:00
|
|
|
"kind": "cargo",
|
|
|
|
"label": "test test_eggs",
|
|
|
|
"location": {
|
|
|
|
"targetRange": {
|
|
|
|
"end": { "character": 17, "line": 1 },
|
2020-04-26 03:40:13 -05:00
|
|
|
"start": { "character": 0, "line": 0 }
|
|
|
|
},
|
2020-06-02 11:02:58 -05:00
|
|
|
"targetSelectionRange": {
|
|
|
|
"end": { "character": 12, "line": 1 },
|
|
|
|
"start": { "character": 3, "line": 1 }
|
2018-10-25 05:42:53 -05:00
|
|
|
},
|
2020-06-02 11:02:58 -05:00
|
|
|
"targetUri": "file:///[..]/tests/spam.rs"
|
2018-10-25 05:42:53 -05:00
|
|
|
}
|
2020-06-02 11:02:58 -05:00
|
|
|
},
|
2021-07-13 11:55:06 -05:00
|
|
|
{
|
|
|
|
"args": {
|
|
|
|
"overrideCargo": null,
|
|
|
|
"workspaceRoot": server.path().join("foo"),
|
|
|
|
"cargoArgs": [
|
|
|
|
"test",
|
|
|
|
"--package",
|
|
|
|
"foo",
|
|
|
|
"--test",
|
|
|
|
"spam"
|
|
|
|
],
|
|
|
|
"cargoExtraArgs": [],
|
|
|
|
"executableArgs": [
|
|
|
|
"",
|
|
|
|
"--nocapture"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"kind": "cargo",
|
|
|
|
"label": "test-mod ",
|
|
|
|
"location": {
|
|
|
|
"targetUri": "file:///[..]/tests/spam.rs",
|
|
|
|
"targetRange": {
|
|
|
|
"start": {
|
|
|
|
"line": 0,
|
|
|
|
"character": 0
|
|
|
|
},
|
|
|
|
"end": {
|
|
|
|
"line": 3,
|
|
|
|
"character": 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetSelectionRange": {
|
|
|
|
"start": {
|
|
|
|
"line": 0,
|
|
|
|
"character": 0
|
|
|
|
},
|
|
|
|
"end": {
|
|
|
|
"line": 3,
|
|
|
|
"character": 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-06-02 11:02:58 -05:00
|
|
|
{
|
|
|
|
"args": {
|
2020-07-29 07:35:27 -05:00
|
|
|
"cargoArgs": ["check", "--package", "foo", "--all-targets"],
|
2020-06-02 11:02:58 -05:00
|
|
|
"executableArgs": [],
|
2020-09-05 09:16:32 -05:00
|
|
|
"cargoExtraArgs": [],
|
|
|
|
"overrideCargo": null,
|
2020-06-02 11:02:58 -05:00
|
|
|
"workspaceRoot": server.path().join("foo")
|
|
|
|
},
|
|
|
|
"kind": "cargo",
|
2020-07-29 07:35:27 -05:00
|
|
|
"label": "cargo check -p foo --all-targets"
|
2020-06-02 11:02:58 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"args": {
|
2020-07-29 07:35:27 -05:00
|
|
|
"cargoArgs": ["test", "--package", "foo", "--all-targets"],
|
2020-06-02 11:02:58 -05:00
|
|
|
"executableArgs": [],
|
2020-09-05 09:16:32 -05:00
|
|
|
"cargoExtraArgs": [],
|
|
|
|
"overrideCargo": null,
|
2020-06-02 11:02:58 -05:00
|
|
|
"workspaceRoot": server.path().join("foo")
|
|
|
|
},
|
|
|
|
"kind": "cargo",
|
2020-07-29 07:35:27 -05:00
|
|
|
"label": "cargo test -p foo --all-targets"
|
2020-06-02 11:02:58 -05:00
|
|
|
}
|
2020-03-12 15:28:26 -05:00
|
|
|
]),
|
2018-09-02 08:36:03 -05:00
|
|
|
);
|
|
|
|
}
|
2018-12-06 14:26:23 -06:00
|
|
|
|
2021-10-09 21:49:34 -05:00
|
|
|
// Each package in these workspaces should be run from its own root
|
|
|
|
#[test]
|
|
|
|
fn test_path_dependency_runnables() {
|
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let server = Project::with_fixture(
|
|
|
|
r#"
|
|
|
|
//- /consumer/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "consumer"
|
|
|
|
version = "0.1.0"
|
|
|
|
[dependencies]
|
|
|
|
dependency = { path = "../dependency" }
|
|
|
|
|
|
|
|
//- /consumer/src/lib.rs
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn consumer() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
//- /dependency/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "dependency"
|
|
|
|
version = "0.1.0"
|
|
|
|
[dev-dependencies]
|
|
|
|
devdependency = { path = "../devdependency" }
|
|
|
|
|
|
|
|
//- /dependency/src/lib.rs
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn dependency() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
//- /devdependency/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "devdependency"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
//- /devdependency/src/lib.rs
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn devdependency() {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.root("consumer")
|
|
|
|
.root("dependency")
|
|
|
|
.root("devdependency")
|
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
|
|
|
for runnable in ["consumer", "dependency", "devdependency"] {
|
|
|
|
server.request::<Runnables>(
|
|
|
|
RunnablesParams {
|
|
|
|
text_document: server.doc_id(&format!("{}/src/lib.rs", runnable)),
|
|
|
|
position: None,
|
|
|
|
},
|
|
|
|
json!([
|
|
|
|
"{...}",
|
|
|
|
{
|
|
|
|
"label": "cargo test -p [..] --all-targets",
|
|
|
|
"kind": "cargo",
|
|
|
|
"args": {
|
|
|
|
"overrideCargo": null,
|
|
|
|
"workspaceRoot": server.path().join(runnable),
|
|
|
|
"cargoArgs": [
|
|
|
|
"test",
|
|
|
|
"--package",
|
|
|
|
runnable,
|
|
|
|
"--all-targets"
|
|
|
|
],
|
|
|
|
"cargoExtraArgs": [],
|
|
|
|
"executableArgs": []
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"{...}",
|
|
|
|
"{...}"
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 13:09:42 -06:00
|
|
|
#[test]
|
|
|
|
fn test_format_document() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-29 13:09:42 -06:00
|
|
|
let server = project(
|
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2018-12-29 13:09:42 -06:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2018-12-29 13:09:42 -06:00
|
|
|
mod bar;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
2020-08-25 12:02:28 -05:00
|
|
|
)
|
|
|
|
.wait_until_workspace_is_loaded();
|
2018-12-29 13:09:42 -06:00
|
|
|
|
|
|
|
server.request::<Formatting>(
|
|
|
|
DocumentFormattingParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
|
|
|
options: FormattingOptions {
|
|
|
|
tab_size: 4,
|
|
|
|
insert_spaces: false,
|
2019-12-11 11:34:01 -06:00
|
|
|
insert_final_newline: None,
|
|
|
|
trim_final_newlines: None,
|
|
|
|
trim_trailing_whitespace: None,
|
2018-12-29 13:09:42 -06:00
|
|
|
properties: HashMap::new(),
|
|
|
|
},
|
2019-12-11 11:34:01 -06:00
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2018-12-29 13:09:42 -06:00
|
|
|
},
|
|
|
|
json!([
|
|
|
|
{
|
2020-12-31 06:05:19 -06:00
|
|
|
"newText": "",
|
2018-12-29 13:09:42 -06:00
|
|
|
"range": {
|
2020-12-31 06:05:19 -06:00
|
|
|
"end": { "character": 0, "line": 3 },
|
|
|
|
"start": { "character": 11, "line": 2 }
|
2018-12-29 13:09:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:05:01 -06:00
|
|
|
#[test]
|
|
|
|
fn test_format_document_2018() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:05:01 -06:00
|
|
|
let server = project(
|
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2019-12-04 16:05:01 -06:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
2021-10-24 06:52:42 -05:00
|
|
|
edition = "2018"
|
2019-12-04 16:05:01 -06:00
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2019-12-04 16:05:01 -06:00
|
|
|
mod bar;
|
|
|
|
|
|
|
|
async fn test() {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
2020-08-25 12:02:28 -05:00
|
|
|
)
|
|
|
|
.wait_until_workspace_is_loaded();
|
2019-12-04 16:05:01 -06:00
|
|
|
|
|
|
|
server.request::<Formatting>(
|
|
|
|
DocumentFormattingParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
|
|
|
options: FormattingOptions {
|
|
|
|
tab_size: 4,
|
|
|
|
insert_spaces: false,
|
|
|
|
properties: HashMap::new(),
|
2019-12-11 11:34:01 -06:00
|
|
|
insert_final_newline: None,
|
|
|
|
trim_final_newlines: None,
|
|
|
|
trim_trailing_whitespace: None,
|
2019-12-04 16:05:01 -06:00
|
|
|
},
|
2019-12-11 11:34:01 -06:00
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2019-12-04 16:05:01 -06:00
|
|
|
},
|
|
|
|
json!([
|
|
|
|
{
|
2020-12-31 06:05:19 -06:00
|
|
|
"newText": "",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 0, "line": 3 },
|
|
|
|
"start": { "character": 17, "line": 2 }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"newText": "",
|
2019-12-04 16:05:01 -06:00
|
|
|
"range": {
|
2020-12-31 06:05:19 -06:00
|
|
|
"end": { "character": 0, "line": 6 },
|
|
|
|
"start": { "character": 11, "line": 5 }
|
2019-12-04 16:05:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
2019-12-07 05:46:36 -06:00
|
|
|
|
2020-09-16 12:05:41 -05:00
|
|
|
#[test]
|
|
|
|
fn test_format_document_unchanged() {
|
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let server = project(
|
|
|
|
r#"
|
|
|
|
//- /Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- /src/lib.rs
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
|
|
|
server.request::<Formatting>(
|
|
|
|
DocumentFormattingParams {
|
|
|
|
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!(null),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-06 14:26:23 -06:00
|
|
|
#[test]
|
|
|
|
fn test_missing_module_code_action() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-06 14:26:23 -06:00
|
|
|
let server = project(
|
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2018-12-06 14:26:23 -06:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2018-12-06 14:26:23 -06:00
|
|
|
mod bar;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
2020-08-25 12:02:28 -05:00
|
|
|
)
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
2019-03-05 15:29:23 -06:00
|
|
|
server.request::<CodeActionRequest>(
|
|
|
|
CodeActionParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
|
|
|
range: Range::new(Position::new(0, 4), Position::new(0, 7)),
|
2020-08-25 12:02:28 -05:00
|
|
|
context: CodeActionContext::default(),
|
2019-12-11 11:34:01 -06:00
|
|
|
partial_result_params: PartialResultParams::default(),
|
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2019-03-05 15:29:23 -06:00
|
|
|
},
|
2020-05-19 13:27:14 -05:00
|
|
|
json!([{
|
|
|
|
"edit": {
|
|
|
|
"documentChanges": [
|
2019-03-05 15:29:23 -06:00
|
|
|
{
|
2020-05-19 13:27:14 -05:00
|
|
|
"kind": "create",
|
|
|
|
"uri": "file:///[..]/src/bar.rs"
|
2019-03-05 15:29:23 -06:00
|
|
|
}
|
2020-05-19 13:27:14 -05:00
|
|
|
]
|
2019-03-05 15:29:23 -06:00
|
|
|
},
|
2020-05-17 20:03:40 -05:00
|
|
|
"kind": "quickfix",
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
2020-05-19 13:27:14 -05:00
|
|
|
}]),
|
2019-03-05 15:29:23 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
server.request::<CodeActionRequest>(
|
|
|
|
CodeActionParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
|
|
|
range: Range::new(Position::new(2, 4), Position::new(2, 7)),
|
2020-08-25 12:02:28 -05:00
|
|
|
context: CodeActionContext::default(),
|
2019-12-11 11:34:01 -06:00
|
|
|
partial_result_params: PartialResultParams::default(),
|
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2019-03-05 15:29:23 -06:00
|
|
|
},
|
|
|
|
json!([]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_missing_module_code_action_in_json_project() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:26:25 -05:00
|
|
|
let tmp_dir = TestDir::new();
|
2019-03-07 10:25:35 -06:00
|
|
|
|
|
|
|
let path = tmp_dir.path();
|
|
|
|
|
|
|
|
let project = json!({
|
|
|
|
"roots": [path],
|
2019-10-05 07:55:27 -05:00
|
|
|
"crates": [ {
|
|
|
|
"root_module": path.join("src/lib.rs"),
|
|
|
|
"deps": [],
|
|
|
|
"edition": "2015",
|
2020-07-23 11:57:27 -05:00
|
|
|
"cfg": [ "cfg_atom_1", "feature=\"cfg_1\""],
|
2019-10-05 07:55:27 -05:00
|
|
|
} ]
|
2019-03-07 10:25:35 -06:00
|
|
|
});
|
|
|
|
|
2019-03-05 15:29:23 -06:00
|
|
|
let code = format!(
|
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /rust-project.json
|
2019-03-07 10:25:35 -06:00
|
|
|
{PROJECT}
|
2019-03-05 15:29:23 -06:00
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2019-03-05 15:29:23 -06:00
|
|
|
mod bar;
|
|
|
|
|
2019-03-07 10:25:35 -06:00
|
|
|
fn main() {{}}
|
2019-03-05 15:29:23 -06:00
|
|
|
"#,
|
2019-03-07 10:25:35 -06:00
|
|
|
PROJECT = project.to_string(),
|
2019-03-05 15:29:23 -06:00
|
|
|
);
|
2019-04-13 13:33:49 -05:00
|
|
|
|
2020-08-25 12:02:28 -05:00
|
|
|
let server =
|
|
|
|
Project::with_fixture(&code).tmp_dir(tmp_dir).server().wait_until_workspace_is_loaded();
|
2019-04-13 13:33:49 -05:00
|
|
|
|
2018-12-06 14:26:23 -06:00
|
|
|
server.request::<CodeActionRequest>(
|
|
|
|
CodeActionParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
2018-12-27 03:54:59 -06:00
|
|
|
range: Range::new(Position::new(0, 4), Position::new(0, 7)),
|
2020-08-25 12:02:28 -05:00
|
|
|
context: CodeActionContext::default(),
|
2019-12-11 11:34:01 -06:00
|
|
|
partial_result_params: PartialResultParams::default(),
|
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2018-12-06 14:26:23 -06:00
|
|
|
},
|
2020-05-19 13:27:14 -05:00
|
|
|
json!([{
|
|
|
|
"edit": {
|
|
|
|
"documentChanges": [
|
2018-12-06 14:26:23 -06:00
|
|
|
{
|
2020-05-19 13:27:14 -05:00
|
|
|
"kind": "create",
|
|
|
|
"uri": "file://[..]/src/bar.rs"
|
2018-12-06 14:26:23 -06:00
|
|
|
}
|
2020-05-19 13:27:14 -05:00
|
|
|
]
|
2019-02-24 04:53:35 -06:00
|
|
|
},
|
2020-05-17 20:03:40 -05:00
|
|
|
"kind": "quickfix",
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
2020-05-19 13:27:14 -05:00
|
|
|
}]),
|
2018-12-06 14:26:23 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
server.request::<CodeActionRequest>(
|
|
|
|
CodeActionParams {
|
|
|
|
text_document: server.doc_id("src/lib.rs"),
|
2018-12-27 03:54:59 -06:00
|
|
|
range: Range::new(Position::new(2, 4), Position::new(2, 7)),
|
2020-08-25 12:02:28 -05:00
|
|
|
context: CodeActionContext::default(),
|
2019-12-11 11:34:01 -06:00
|
|
|
partial_result_params: PartialResultParams::default(),
|
|
|
|
work_done_progress_params: WorkDoneProgressParams::default(),
|
2018-12-06 14:26:23 -06:00
|
|
|
},
|
|
|
|
json!([]),
|
|
|
|
);
|
|
|
|
}
|
2019-05-27 06:20:11 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn diagnostics_dont_block_typing() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-27 06:20:11 -05:00
|
|
|
let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
|
2020-06-22 10:30:23 -05:00
|
|
|
let libs: String = (0..10).map(|i| format!("//- /src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
|
2019-08-19 07:41:18 -05:00
|
|
|
let server = Project::with_fixture(&format!(
|
2019-05-27 06:20:11 -05:00
|
|
|
r#"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2019-05-27 06:20:11 -05:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/lib.rs
|
2019-05-27 06:20:11 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
fn main() {{}}
|
|
|
|
"#,
|
|
|
|
librs, libs
|
2019-08-19 07:41:18 -05:00
|
|
|
))
|
2021-03-01 03:14:16 -06:00
|
|
|
.with_config(serde_json::json!({
|
|
|
|
"cargo": { "noSysroot": false }
|
|
|
|
}))
|
2020-08-25 12:02:28 -05:00
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
2019-08-19 07:41:18 -05:00
|
|
|
|
2019-05-27 06:20:11 -05:00
|
|
|
for i in 0..10 {
|
|
|
|
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
|
|
|
|
text_document: TextDocumentItem {
|
|
|
|
uri: server.doc_id(&format!("src/m{}.rs", i)).uri,
|
|
|
|
language_id: "rust".to_string(),
|
|
|
|
version: 0,
|
|
|
|
text: "/// Docs\nfn foo() {}".to_string(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-08-25 12:02:28 -05:00
|
|
|
let start = Instant::now();
|
2019-05-27 06:20:11 -05:00
|
|
|
server.request::<OnEnter>(
|
|
|
|
TextDocumentPositionParams {
|
|
|
|
text_document: server.doc_id("src/m0.rs"),
|
|
|
|
position: Position { line: 0, character: 5 },
|
|
|
|
},
|
2020-05-25 07:12:53 -05:00
|
|
|
json!([{
|
|
|
|
"insertTextFormat": 2,
|
|
|
|
"newText": "\n/// $0",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 5, "line": 0 },
|
|
|
|
"start": { "character": 5, "line": 0 }
|
2020-05-21 07:26:44 -05:00
|
|
|
}
|
2020-05-25 07:12:53 -05:00
|
|
|
}]),
|
2019-05-27 06:20:11 -05:00
|
|
|
);
|
2019-05-27 06:41:14 -05:00
|
|
|
let elapsed = start.elapsed();
|
|
|
|
assert!(elapsed.as_millis() < 2000, "typing enter took {:?}", elapsed);
|
2019-05-27 06:20:11 -05:00
|
|
|
}
|
2019-08-20 10:26:07 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn preserves_dos_line_endings() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-20 10:26:07 -05:00
|
|
|
let server = Project::with_fixture(
|
2021-06-12 22:54:16 -05:00
|
|
|
"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2019-08-20 10:26:07 -05:00
|
|
|
[package]
|
2019-08-20 10:53:59 -05:00
|
|
|
name = \"foo\"
|
|
|
|
version = \"0.0.0\"
|
2019-08-20 10:26:07 -05:00
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/main.rs
|
2019-08-20 10:26:07 -05:00
|
|
|
/// Some Docs\r\nfn main() {}
|
2019-08-20 10:53:59 -05:00
|
|
|
",
|
2019-08-20 10:26:07 -05:00
|
|
|
)
|
2020-08-25 12:02:28 -05:00
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
2019-08-20 10:26:07 -05:00
|
|
|
|
|
|
|
server.request::<OnEnter>(
|
|
|
|
TextDocumentPositionParams {
|
|
|
|
text_document: server.doc_id("src/main.rs"),
|
|
|
|
position: Position { line: 0, character: 8 },
|
|
|
|
},
|
2020-05-25 07:12:53 -05:00
|
|
|
json!([{
|
|
|
|
"insertTextFormat": 2,
|
|
|
|
"newText": "\r\n/// $0",
|
|
|
|
"range": {
|
|
|
|
"end": { "line": 0, "character": 8 },
|
|
|
|
"start": { "line": 0, "character": 8 }
|
2020-05-21 07:26:44 -05:00
|
|
|
}
|
2020-05-25 07:12:53 -05:00
|
|
|
}]),
|
2019-08-20 10:26:07 -05:00
|
|
|
);
|
|
|
|
}
|
2020-03-31 12:16:25 -05:00
|
|
|
|
|
|
|
#[test]
|
2020-05-05 07:53:18 -05:00
|
|
|
fn out_dirs_check() {
|
2020-03-31 12:16:25 -05:00
|
|
|
if skip_slow_tests() {
|
2021-04-19 10:57:47 -05:00
|
|
|
return;
|
2020-03-31 12:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let server = Project::with_fixture(
|
|
|
|
r###"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /Cargo.toml
|
2020-03-31 12:16:25 -05:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /build.rs
|
2020-03-31 12:16:25 -05:00
|
|
|
use std::{env, fs, path::Path};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
|
|
|
let dest_path = Path::new(&out_dir).join("hello.rs");
|
|
|
|
fs::write(
|
|
|
|
&dest_path,
|
|
|
|
r#"pub fn message() -> &'static str { "Hello, World!" }"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-05-05 07:53:18 -05:00
|
|
|
println!("cargo:rustc-cfg=atom_cfg");
|
|
|
|
println!("cargo:rustc-cfg=featlike=\"set\"");
|
2020-03-31 12:16:25 -05:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
}
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /src/main.rs
|
2020-06-05 08:49:12 -05:00
|
|
|
#[rustc_builtin_macro] macro_rules! include {}
|
2020-06-27 07:31:19 -05:00
|
|
|
#[rustc_builtin_macro] macro_rules! include_str {}
|
2020-06-05 08:49:12 -05:00
|
|
|
#[rustc_builtin_macro] macro_rules! concat {}
|
|
|
|
#[rustc_builtin_macro] macro_rules! env {}
|
|
|
|
|
2020-03-31 12:16:25 -05:00
|
|
|
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
|
|
|
|
|
2020-05-05 07:53:18 -05:00
|
|
|
#[cfg(atom_cfg)]
|
|
|
|
struct A;
|
|
|
|
#[cfg(bad_atom_cfg)]
|
|
|
|
struct A;
|
|
|
|
#[cfg(featlike = "set")]
|
|
|
|
struct B;
|
|
|
|
#[cfg(featlike = "not_set")]
|
|
|
|
struct B;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let va = A;
|
|
|
|
let vb = B;
|
2020-06-05 08:49:12 -05:00
|
|
|
let should_be_str = message();
|
2020-06-27 07:31:19 -05:00
|
|
|
let another_str = include_str!("main.rs");
|
2020-05-05 07:53:18 -05:00
|
|
|
}
|
2020-03-31 12:16:25 -05:00
|
|
|
"###,
|
|
|
|
)
|
2021-01-06 04:54:28 -06:00
|
|
|
.with_config(serde_json::json!({
|
2021-03-01 03:14:16 -06:00
|
|
|
"cargo": {
|
|
|
|
"loadOutDirsFromCheck": true,
|
|
|
|
"noSysroot": true,
|
|
|
|
}
|
2021-01-06 04:54:28 -06:00
|
|
|
}))
|
2020-08-25 12:02:28 -05:00
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
2020-06-05 08:49:12 -05:00
|
|
|
let res = server.send_request::<HoverRequest>(HoverParams {
|
2020-04-26 15:05:22 -05:00
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
2020-06-27 07:31:19 -05:00
|
|
|
Position::new(19, 10),
|
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
});
|
|
|
|
assert!(res.to_string().contains("&str"));
|
2020-08-25 12:02:28 -05:00
|
|
|
|
2020-06-27 07:31:19 -05:00
|
|
|
let res = server.send_request::<HoverRequest>(HoverParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
|
|
|
Position::new(20, 10),
|
2020-04-26 15:05:22 -05:00
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
});
|
2020-06-05 08:49:12 -05:00
|
|
|
assert!(res.to_string().contains("&str"));
|
2020-08-25 12:02:28 -05:00
|
|
|
|
2020-05-05 07:53:18 -05:00
|
|
|
server.request::<GotoTypeDefinition>(
|
|
|
|
GotoDefinitionParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
2020-06-27 07:31:19 -05:00
|
|
|
Position::new(17, 9),
|
2020-05-05 07:53:18 -05:00
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
partial_result_params: Default::default(),
|
|
|
|
},
|
|
|
|
json!([{
|
|
|
|
"originSelectionRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 10, "line": 17 },
|
|
|
|
"start": { "character": 8, "line": 17 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 9, "line": 8 },
|
|
|
|
"start": { "character": 0, "line": 7 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetSelectionRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 8, "line": 8 },
|
|
|
|
"start": { "character": 7, "line": 8 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetUri": "file:///[..]src/main.rs"
|
|
|
|
}]),
|
|
|
|
);
|
2020-08-25 12:02:28 -05:00
|
|
|
|
2020-05-05 07:53:18 -05:00
|
|
|
server.request::<GotoTypeDefinition>(
|
|
|
|
GotoDefinitionParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
2020-06-27 07:31:19 -05:00
|
|
|
Position::new(18, 9),
|
2020-05-05 07:53:18 -05:00
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
partial_result_params: Default::default(),
|
|
|
|
},
|
|
|
|
json!([{
|
|
|
|
"originSelectionRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 10, "line": 18 },
|
|
|
|
"start": { "character": 8, "line": 18 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 9, "line": 12 },
|
|
|
|
"start": { "character": 0, "line":11 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetSelectionRange": {
|
2020-06-27 07:31:19 -05:00
|
|
|
"end": { "character": 8, "line": 12 },
|
|
|
|
"start": { "character": 7, "line": 12 }
|
2020-05-05 07:53:18 -05:00
|
|
|
},
|
|
|
|
"targetUri": "file:///[..]src/main.rs"
|
|
|
|
}]),
|
|
|
|
);
|
2020-03-31 12:16:25 -05:00
|
|
|
}
|
2020-04-12 11:05:45 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn resolve_proc_macro() {
|
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-25 12:02:28 -05:00
|
|
|
|
2020-04-12 11:05:45 -05:00
|
|
|
let server = Project::with_fixture(
|
|
|
|
r###"
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /foo/Cargo.toml
|
2020-04-12 11:05:45 -05:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
2021-10-21 10:49:28 -05:00
|
|
|
edition = "2021"
|
2020-04-12 11:05:45 -05:00
|
|
|
[dependencies]
|
|
|
|
bar = {path = "../bar"}
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /foo/src/main.rs
|
2020-04-12 11:05:45 -05:00
|
|
|
use bar::Bar;
|
2021-11-17 12:46:32 -06:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro derive($item:item) {}
|
2020-04-12 11:05:45 -05:00
|
|
|
trait Bar {
|
|
|
|
fn bar();
|
|
|
|
}
|
|
|
|
#[derive(Bar)]
|
|
|
|
struct Foo {}
|
|
|
|
fn main() {
|
|
|
|
Foo::bar();
|
|
|
|
}
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /bar/Cargo.toml
|
2020-04-12 11:05:45 -05:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
2021-10-21 10:49:28 -05:00
|
|
|
edition = "2021"
|
2020-04-12 11:05:45 -05:00
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
|
2020-06-22 10:30:23 -05:00
|
|
|
//- /bar/src/lib.rs
|
2020-04-12 11:05:45 -05:00
|
|
|
extern crate proc_macro;
|
|
|
|
use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
|
|
|
macro_rules! t {
|
|
|
|
($n:literal) => {
|
|
|
|
TokenTree::from(Ident::new($n, Span::call_site()))
|
|
|
|
};
|
|
|
|
({}) => {
|
|
|
|
TokenTree::from(Group::new(Delimiter::Brace, TokenStream::new()))
|
|
|
|
};
|
|
|
|
(()) => {
|
|
|
|
TokenTree::from(Group::new(Delimiter::Parenthesis, TokenStream::new()))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#[proc_macro_derive(Bar)]
|
|
|
|
pub fn foo(_input: TokenStream) -> TokenStream {
|
|
|
|
// We hard code the output here for preventing to use any deps
|
|
|
|
let mut res = TokenStream::new();
|
|
|
|
|
2021-03-22 22:22:33 -05:00
|
|
|
// ill behaved proc-macro will use the stdout
|
|
|
|
// we should ignore it
|
|
|
|
println!("I am bad guy");
|
|
|
|
|
2020-04-12 11:05:45 -05:00
|
|
|
// impl Bar for Foo { fn bar() {} }
|
|
|
|
let mut tokens = vec![t!("impl"), t!("Bar"), t!("for"), t!("Foo")];
|
|
|
|
let mut fn_stream = TokenStream::new();
|
|
|
|
fn_stream.extend(vec![t!("fn"), t!("bar"), t!(()), t!({})]);
|
|
|
|
tokens.push(Group::new(Delimiter::Brace, fn_stream).into());
|
|
|
|
res.extend(tokens);
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
"###,
|
|
|
|
)
|
2021-01-06 04:54:28 -06:00
|
|
|
.with_config(serde_json::json!({
|
2021-03-01 03:14:16 -06:00
|
|
|
"cargo": {
|
|
|
|
"loadOutDirsFromCheck": true,
|
|
|
|
"noSysroot": true,
|
|
|
|
},
|
2021-01-06 04:54:28 -06:00
|
|
|
"procMacro": {
|
|
|
|
"enable": true,
|
|
|
|
"server": PathBuf::from(env!("CARGO_BIN_EXE_rust-analyzer")),
|
|
|
|
}
|
|
|
|
}))
|
2020-04-12 11:05:45 -05:00
|
|
|
.root("foo")
|
|
|
|
.root("bar")
|
2020-08-25 12:02:28 -05:00
|
|
|
.server()
|
|
|
|
.wait_until_workspace_is_loaded();
|
|
|
|
|
2020-04-26 15:05:22 -05:00
|
|
|
let res = server.send_request::<HoverRequest>(HoverParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("foo/src/main.rs"),
|
|
|
|
Position::new(7, 9),
|
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
});
|
2021-01-06 09:36:06 -06:00
|
|
|
let value = res.get("contents").unwrap().get("value").unwrap().as_str().unwrap();
|
|
|
|
|
|
|
|
expect![[r#"
|
|
|
|
|
|
|
|
```rust
|
|
|
|
foo::Bar
|
|
|
|
```
|
|
|
|
|
|
|
|
```rust
|
|
|
|
fn bar()
|
|
|
|
```"#]]
|
2021-06-12 22:54:16 -05:00
|
|
|
.assert_eq(value);
|
2020-04-12 11:05:45 -05:00
|
|
|
}
|
2021-01-12 10:30:49 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_will_rename_files_same_level() {
|
2021-01-12 10:58:28 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-12 10:30:49 -06:00
|
|
|
let tmp_dir = TestDir::new();
|
|
|
|
let tmp_dir_path = tmp_dir.path().to_owned();
|
2021-01-12 10:53:17 -06:00
|
|
|
let tmp_dir_str = tmp_dir_path.to_str().unwrap();
|
|
|
|
let base_path = PathBuf::from(format!("file://{}", tmp_dir_str));
|
2021-01-12 10:30:49 -06:00
|
|
|
|
|
|
|
let code = r#"
|
|
|
|
//- /Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- /src/lib.rs
|
|
|
|
mod old_file;
|
|
|
|
mod from_mod;
|
|
|
|
mod to_mod;
|
|
|
|
mod old_folder;
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
//- /src/old_file.rs
|
|
|
|
|
|
|
|
//- /src/old_folder/mod.rs
|
|
|
|
|
|
|
|
//- /src/from_mod/mod.rs
|
|
|
|
|
|
|
|
//- /src/to_mod/foo.rs
|
|
|
|
|
|
|
|
"#;
|
|
|
|
let server =
|
2021-06-12 22:54:16 -05:00
|
|
|
Project::with_fixture(code).tmp_dir(tmp_dir).server().wait_until_workspace_is_loaded();
|
2021-01-12 10:30:49 -06:00
|
|
|
|
|
|
|
//rename same level file
|
|
|
|
server.request::<WillRenameFiles>(
|
|
|
|
RenameFilesParams {
|
|
|
|
files: vec![FileRename {
|
|
|
|
old_uri: base_path.join("src/old_file.rs").to_str().unwrap().to_string(),
|
|
|
|
new_uri: base_path.join("src/new_file.rs").to_str().unwrap().to_string(),
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
json!({
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"textDocument": {
|
2021-01-13 08:56:31 -06:00
|
|
|
"uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace("\\", "/")),
|
2021-01-12 10:30:49 -06:00
|
|
|
"version": null
|
|
|
|
},
|
|
|
|
"edits": [
|
|
|
|
{
|
|
|
|
"range": {
|
|
|
|
"start": {
|
|
|
|
"line": 0,
|
|
|
|
"character": 4
|
|
|
|
},
|
|
|
|
"end": {
|
|
|
|
"line": 0,
|
|
|
|
"character": 12
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"newText": "new_file"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
//rename file from mod.rs to foo.rs
|
|
|
|
server.request::<WillRenameFiles>(
|
|
|
|
RenameFilesParams {
|
|
|
|
files: vec![FileRename {
|
|
|
|
old_uri: base_path.join("src/from_mod/mod.rs").to_str().unwrap().to_string(),
|
|
|
|
new_uri: base_path.join("src/from_mod/foo.rs").to_str().unwrap().to_string(),
|
|
|
|
}],
|
|
|
|
},
|
2021-03-20 07:44:39 -05:00
|
|
|
json!(null),
|
2021-01-12 10:30:49 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
//rename file from foo.rs to mod.rs
|
|
|
|
server.request::<WillRenameFiles>(
|
|
|
|
RenameFilesParams {
|
|
|
|
files: vec![FileRename {
|
|
|
|
old_uri: base_path.join("src/to_mod/foo.rs").to_str().unwrap().to_string(),
|
|
|
|
new_uri: base_path.join("src/to_mod/mod.rs").to_str().unwrap().to_string(),
|
|
|
|
}],
|
|
|
|
},
|
2021-03-20 07:44:39 -05:00
|
|
|
json!(null),
|
2021-01-12 10:30:49 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
//rename same level file
|
|
|
|
server.request::<WillRenameFiles>(
|
|
|
|
RenameFilesParams {
|
|
|
|
files: vec![FileRename {
|
|
|
|
old_uri: base_path.join("src/old_folder").to_str().unwrap().to_string(),
|
|
|
|
new_uri: base_path.join("src/new_folder").to_str().unwrap().to_string(),
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
json!({
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"textDocument": {
|
2021-01-13 08:56:31 -06:00
|
|
|
"uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace("\\", "/")),
|
2021-01-12 10:30:49 -06:00
|
|
|
"version": null
|
|
|
|
},
|
|
|
|
"edits": [
|
|
|
|
{
|
|
|
|
"range": {
|
|
|
|
"start": {
|
|
|
|
"line": 3,
|
|
|
|
"character": 4
|
|
|
|
},
|
|
|
|
"end": {
|
|
|
|
"line": 3,
|
|
|
|
"character": 14
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"newText": "new_folder"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|