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
|
|
|
|
2019-01-14 04:55:56 -06:00
|
|
|
use lsp_types::{
|
2020-05-10 12:25:37 -05:00
|
|
|
notification::DidOpenTextDocument,
|
|
|
|
request::{
|
|
|
|
CodeActionRequest, Completion, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
|
|
|
|
},
|
|
|
|
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
|
|
|
|
DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams,
|
|
|
|
PartialResultParams, Position, Range, 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};
|
2018-12-06 14:07:31 -06:00
|
|
|
use serde_json::json;
|
2019-03-05 15:29:23 -06:00
|
|
|
use tempfile::TempDir;
|
2019-12-07 05:46:36 -06:00
|
|
|
use test_utils::skip_slow_tests;
|
2018-09-01 12:21:11 -05:00
|
|
|
|
2019-04-13 13:33:49 -05:00
|
|
|
use crate::support::{project, Project};
|
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-01-10 15:37:10 -06:00
|
|
|
let project_start = Instant::now();
|
2019-08-19 07:41:18 -05:00
|
|
|
let server = Project::with_fixture(
|
2019-01-10 11:13:08 -06:00
|
|
|
r#"
|
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- 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
|
|
|
)
|
|
|
|
.with_sysroot(true)
|
|
|
|
.server();
|
2019-03-07 08:46:17 -06:00
|
|
|
server.wait_until_workspace_is_loaded();
|
2019-01-10 15:37:10 -06:00
|
|
|
eprintln!("loading took {:?}", project_start.elapsed());
|
|
|
|
let completion_start = Instant::now();
|
|
|
|
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
|
|
|
});
|
|
|
|
assert!(format!("{}", res).contains("HashMap"));
|
|
|
|
eprintln!("completion took {:?}", completion_start.elapsed());
|
2019-01-10 11:13:08 -06:00
|
|
|
}
|
|
|
|
|
2018-09-01 12:21:11 -05:00
|
|
|
#[test]
|
2018-09-02 08:36:03 -05:00
|
|
|
fn test_runnables_no_project() {
|
2019-12-07 05:46:36 -06:00
|
|
|
if skip_slow_tests() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-15 16:44:23 -05:00
|
|
|
let server = project(
|
|
|
|
r"
|
2018-09-01 12:21:11 -05:00
|
|
|
//- lib.rs
|
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
}
|
2018-10-15 16:44:23 -05:00
|
|
|
",
|
|
|
|
);
|
2019-03-07 08:46:17 -06:00
|
|
|
server.wait_until_workspace_is_loaded();
|
2018-09-01 12:21:11 -05:00
|
|
|
server.request::<Runnables>(
|
2019-02-08 05:49:43 -06:00
|
|
|
RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
|
2018-12-06 14:07:31 -06:00
|
|
|
json!([
|
2018-09-01 12:21:11 -05:00
|
|
|
{
|
2020-03-09 16:06:45 -05:00
|
|
|
"args": [ "test" ],
|
|
|
|
"extraArgs": [ "foo", "--nocapture" ],
|
2018-09-01 12:21:11 -05:00
|
|
|
"bin": "cargo",
|
|
|
|
"env": { "RUST_BACKTRACE": "short" },
|
2019-04-13 12:45:21 -05:00
|
|
|
"cwd": null,
|
2018-09-01 12:21:11 -05:00
|
|
|
"label": "test foo",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 1, "line": 2 },
|
|
|
|
"start": { "character": 0, "line": 0 }
|
|
|
|
}
|
2018-10-25 05:42:53 -05:00
|
|
|
},
|
|
|
|
{
|
2020-04-26 03:40:13 -05:00
|
|
|
"args": ["check", "--workspace"],
|
2020-03-09 16:06:45 -05:00
|
|
|
"extraArgs": [],
|
2018-10-25 05:42:53 -05:00
|
|
|
"bin": "cargo",
|
|
|
|
"env": {},
|
2019-04-13 12:45:21 -05:00
|
|
|
"cwd": null,
|
2020-04-26 03:40:13 -05:00
|
|
|
"label": "cargo check --workspace",
|
2018-10-25 05:42:53 -05:00
|
|
|
"range": {
|
2020-04-26 03:40:13 -05:00
|
|
|
"end": { "character": 0, "line": 0 },
|
|
|
|
"start": { "character": 0, "line": 0 }
|
2018-10-25 05:42:53 -05:00
|
|
|
}
|
2018-09-01 12:21:11 -05:00
|
|
|
}
|
2018-12-06 14:07:31 -06:00
|
|
|
]),
|
2018-09-01 12:21:11 -05:00
|
|
|
);
|
|
|
|
}
|
2018-09-02 06:46:15 -05: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;
|
|
|
|
}
|
|
|
|
|
2019-04-13 13:33:49 -05:00
|
|
|
let code = r#"
|
|
|
|
//- foo/Cargo.toml
|
2018-09-02 08:36:03 -05:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
2019-04-13 13:33:49 -05:00
|
|
|
//- foo/src/lib.rs
|
2018-09-02 08:36:03 -05:00
|
|
|
pub fn foo() {}
|
|
|
|
|
2019-04-13 13:33:49 -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
|
|
|
|
|
|
|
//- bar/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- bar/src/main.rs
|
|
|
|
fn main() {}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let server = Project::with_fixture(code).root("foo").root("bar").server();
|
|
|
|
|
2019-03-07 08:46:17 -06:00
|
|
|
server.wait_until_workspace_is_loaded();
|
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-04-26 03:40:13 -05:00
|
|
|
{
|
|
|
|
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
|
|
|
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
|
|
|
"bin": "cargo",
|
|
|
|
"env": { "RUST_BACKTRACE": "short" },
|
|
|
|
"label": "test test_eggs",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 17, "line": 1 },
|
|
|
|
"start": { "character": 0, "line": 0 }
|
|
|
|
},
|
|
|
|
"cwd": server.path().join("foo")
|
2019-04-13 12:45:21 -05:00
|
|
|
},
|
2020-04-26 03:40:13 -05:00
|
|
|
{
|
2020-05-02 03:57:37 -05:00
|
|
|
"args": [ "check", "--package", "foo" ],
|
2020-04-26 03:40:13 -05:00
|
|
|
"extraArgs": [],
|
|
|
|
"bin": "cargo",
|
|
|
|
"env": {},
|
|
|
|
"label": "cargo check -p foo",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 0, "line": 0 },
|
|
|
|
"start": { "character": 0, "line": 0 }
|
|
|
|
},
|
|
|
|
"cwd": server.path().join("foo")
|
|
|
|
},
|
|
|
|
{
|
2020-05-02 03:57:37 -05:00
|
|
|
"args": [ "test", "--package", "foo" ],
|
2020-04-26 03:40:13 -05:00
|
|
|
"extraArgs": [],
|
|
|
|
"bin": "cargo",
|
|
|
|
"env": {},
|
|
|
|
"label": "cargo test -p foo",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 0, "line": 0 },
|
|
|
|
"start": { "character": 0, "line": 0 }
|
2018-10-25 05:42:53 -05:00
|
|
|
},
|
2020-04-26 03:40:13 -05:00
|
|
|
"cwd": server.path().join("foo")
|
2018-10-25 05:42:53 -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
|
|
|
|
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#"
|
2019-12-04 16:05:01 -06:00
|
|
|
//- Cargo.toml
|
2018-12-29 13:09:42 -06:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- src/lib.rs
|
|
|
|
mod bar;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
|
|
|
);
|
2019-03-07 08:46:17 -06:00
|
|
|
server.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!([
|
|
|
|
{
|
|
|
|
"newText": r#"mod bar;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
|
|
|
"range": {
|
|
|
|
"end": {
|
|
|
|
"character": 0,
|
2019-08-20 10:53:59 -05:00
|
|
|
"line": 7
|
2018-12-29 13:09:42 -06:00
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 0,
|
|
|
|
"line": 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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#"
|
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
//- src/lib.rs
|
|
|
|
mod bar;
|
|
|
|
|
|
|
|
async fn test() {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
server.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,
|
|
|
|
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!([
|
|
|
|
{
|
|
|
|
"newText": r#"mod bar;
|
|
|
|
|
|
|
|
async fn test() {}
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
pub use std::collections::HashMap;
|
|
|
|
"#,
|
|
|
|
"range": {
|
|
|
|
"end": {
|
|
|
|
"character": 0,
|
|
|
|
"line": 10
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 0,
|
|
|
|
"line": 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
2019-12-07 05:46:36 -06:00
|
|
|
|
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#"
|
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- src/lib.rs
|
|
|
|
mod bar;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
|
|
|
);
|
2019-03-07 08:46:17 -06:00
|
|
|
server.wait_until_workspace_is_loaded();
|
2019-02-08 05:49:43 -06:00
|
|
|
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
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)),
|
|
|
|
context: empty_context(),
|
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!([
|
|
|
|
{
|
|
|
|
"command": {
|
|
|
|
"arguments": [
|
|
|
|
{
|
|
|
|
"cursorPosition": null,
|
2020-05-05 13:55:12 -05:00
|
|
|
"label": "Create module",
|
2019-03-05 15:29:23 -06:00
|
|
|
"workspaceEdit": {
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"kind": "create",
|
|
|
|
"uri": "file:///[..]/src/bar.rs"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"command": "rust-analyzer.applySourceChange",
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
2019-03-05 15:29:23 -06:00
|
|
|
},
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
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)),
|
|
|
|
context: empty_context(),
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-05 15:29:23 -06:00
|
|
|
let tmp_dir = TempDir::new().unwrap();
|
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",
|
|
|
|
"atom_cfgs": [],
|
|
|
|
"key_value_cfgs": {}
|
|
|
|
} ]
|
2019-03-07 10:25:35 -06:00
|
|
|
});
|
|
|
|
|
2019-03-05 15:29:23 -06:00
|
|
|
let code = format!(
|
|
|
|
r#"
|
|
|
|
//- rust-project.json
|
2019-03-07 10:25:35 -06:00
|
|
|
{PROJECT}
|
2019-03-05 15:29:23 -06:00
|
|
|
|
|
|
|
//- src/lib.rs
|
|
|
|
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
|
|
|
|
|
|
|
let server = Project::with_fixture(&code).tmp_dir(tmp_dir).server();
|
|
|
|
|
2019-03-07 08:46:17 -06:00
|
|
|
server.wait_until_workspace_is_loaded();
|
2019-03-05 15:29:23 -06:00
|
|
|
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
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)),
|
2018-12-06 14:26:23 -06:00
|
|
|
context: empty_context(),
|
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-02-24 04:53:35 -06:00
|
|
|
{
|
|
|
|
"command": {
|
2018-12-06 14:26:23 -06:00
|
|
|
"arguments": [
|
|
|
|
{
|
|
|
|
"cursorPosition": null,
|
2020-05-05 13:55:12 -05:00
|
|
|
"label": "Create module",
|
2019-01-03 07:43:47 -06:00
|
|
|
"workspaceEdit": {
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"kind": "create",
|
2018-12-06 14:26:23 -06:00
|
|
|
"uri": "file:///[..]/src/bar.rs"
|
2019-01-03 07:43:47 -06:00
|
|
|
}
|
|
|
|
]
|
2019-02-24 04:53:35 -06:00
|
|
|
}
|
2018-12-06 14:26:23 -06:00
|
|
|
}
|
|
|
|
],
|
2019-01-28 05:43:07 -06:00
|
|
|
"command": "rust-analyzer.applySourceChange",
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
2019-02-24 04:53:35 -06:00
|
|
|
},
|
2020-05-05 13:55:12 -05:00
|
|
|
"title": "Create module"
|
2019-02-24 04:53:35 -06: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)),
|
2018-12-06 14:26:23 -06:00
|
|
|
context: empty_context(),
|
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();
|
|
|
|
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#"
|
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- src/lib.rs
|
|
|
|
{}
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
fn main() {{}}
|
|
|
|
"#,
|
|
|
|
librs, libs
|
2019-08-19 07:41:18 -05:00
|
|
|
))
|
|
|
|
.with_sysroot(true)
|
|
|
|
.server();
|
|
|
|
|
2019-05-27 06:20:11 -05:00
|
|
|
server.wait_until_workspace_is_loaded();
|
|
|
|
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(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let start = std::time::Instant::now();
|
|
|
|
server.request::<OnEnter>(
|
|
|
|
TextDocumentPositionParams {
|
|
|
|
text_document: server.doc_id("src/m0.rs"),
|
|
|
|
position: Position { line: 0, character: 5 },
|
|
|
|
},
|
|
|
|
json!({
|
|
|
|
"cursorPosition": {
|
|
|
|
"position": { "character": 4, "line": 1 },
|
|
|
|
"textDocument": { "uri": "file:///[..]src/m0.rs" }
|
|
|
|
},
|
2020-05-05 13:55:12 -05:00
|
|
|
"label": "On enter",
|
2019-05-27 06:20:11 -05:00
|
|
|
"workspaceEdit": {
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"edits": [
|
|
|
|
{
|
|
|
|
"newText": "\n/// ",
|
|
|
|
"range": {
|
|
|
|
"end": { "character": 5, "line": 0 },
|
|
|
|
"start": { "character": 5, "line": 0 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"textDocument": { "uri": "file:///[..]src/m0.rs", "version": null }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
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(
|
2019-08-20 10:53:59 -05:00
|
|
|
&"
|
2019-08-20 10:26:07 -05:00
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
2019-08-20 10:53:59 -05:00
|
|
|
name = \"foo\"
|
|
|
|
version = \"0.0.0\"
|
2019-08-20 10:26:07 -05:00
|
|
|
|
|
|
|
//- src/main.rs
|
|
|
|
/// Some Docs\r\nfn main() {}
|
2019-08-20 10:53:59 -05:00
|
|
|
",
|
2019-08-20 10:26:07 -05:00
|
|
|
)
|
|
|
|
.server();
|
|
|
|
|
|
|
|
server.request::<OnEnter>(
|
|
|
|
TextDocumentPositionParams {
|
|
|
|
text_document: server.doc_id("src/main.rs"),
|
|
|
|
position: Position { line: 0, character: 8 },
|
|
|
|
},
|
|
|
|
json!({
|
|
|
|
"cursorPosition": {
|
|
|
|
"position": { "line": 1, "character": 4 },
|
|
|
|
"textDocument": { "uri": "file:///[..]src/main.rs" }
|
|
|
|
},
|
2020-05-05 13:55:12 -05:00
|
|
|
"label": "On enter",
|
2019-08-20 10:26:07 -05:00
|
|
|
"workspaceEdit": {
|
|
|
|
"documentChanges": [
|
|
|
|
{
|
|
|
|
"edits": [
|
|
|
|
{
|
|
|
|
"newText": "\r\n/// ",
|
|
|
|
"range": {
|
|
|
|
"end": { "line": 0, "character": 8 },
|
|
|
|
"start": { "line": 0, "character": 8 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"textDocument": { "uri": "file:///[..]src/main.rs", "version": null }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
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() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let server = Project::with_fixture(
|
|
|
|
r###"
|
|
|
|
//- Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
//- build.rs
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
//- src/main.rs
|
|
|
|
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;
|
|
|
|
message();
|
|
|
|
}
|
|
|
|
|
2020-03-31 12:16:25 -05:00
|
|
|
fn main() { message(); }
|
|
|
|
"###,
|
|
|
|
)
|
|
|
|
.with_config(|config| {
|
2020-04-01 11:41:43 -05:00
|
|
|
config.cargo.load_out_dirs_from_check = true;
|
2020-03-31 12:16:25 -05:00
|
|
|
})
|
|
|
|
.server();
|
|
|
|
server.wait_until_workspace_is_loaded();
|
2020-04-26 15:05:22 -05:00
|
|
|
let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
2020-05-05 07:53:18 -05:00
|
|
|
Position::new(14, 8),
|
2020-04-26 15:05:22 -05:00
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
partial_result_params: Default::default(),
|
|
|
|
});
|
2020-03-31 12:16:25 -05:00
|
|
|
assert!(format!("{}", res).contains("hello.rs"));
|
2020-05-05 07:53:18 -05:00
|
|
|
server.request::<GotoTypeDefinition>(
|
|
|
|
GotoDefinitionParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
|
|
|
Position::new(12, 9),
|
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
partial_result_params: Default::default(),
|
|
|
|
},
|
|
|
|
json!([{
|
|
|
|
"originSelectionRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 10,
|
|
|
|
"line": 12
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 8,
|
|
|
|
"line": 12
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 9,
|
|
|
|
"line": 3
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 0,
|
|
|
|
"line": 2
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetSelectionRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 8,
|
|
|
|
"line": 3
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 7,
|
|
|
|
"line": 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetUri": "file:///[..]src/main.rs"
|
|
|
|
}]),
|
|
|
|
);
|
|
|
|
server.request::<GotoTypeDefinition>(
|
|
|
|
GotoDefinitionParams {
|
|
|
|
text_document_position_params: TextDocumentPositionParams::new(
|
|
|
|
server.doc_id("src/main.rs"),
|
|
|
|
Position::new(13, 9),
|
|
|
|
),
|
|
|
|
work_done_progress_params: Default::default(),
|
|
|
|
partial_result_params: Default::default(),
|
|
|
|
},
|
|
|
|
json!([{
|
|
|
|
"originSelectionRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 10,
|
|
|
|
"line": 13
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 8,
|
|
|
|
"line":13
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 9,
|
|
|
|
"line": 7
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 0,
|
|
|
|
"line":6
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"targetSelectionRange": {
|
|
|
|
"end": {
|
|
|
|
"character": 8,
|
|
|
|
"line": 7
|
|
|
|
},
|
|
|
|
"start": {
|
|
|
|
"character": 7,
|
|
|
|
"line": 7
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
let server = Project::with_fixture(
|
|
|
|
r###"
|
|
|
|
//- foo/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
edition = "2018"
|
|
|
|
[dependencies]
|
|
|
|
bar = {path = "../bar"}
|
|
|
|
|
|
|
|
//- foo/src/main.rs
|
|
|
|
use bar::Bar;
|
|
|
|
trait Bar {
|
|
|
|
fn bar();
|
|
|
|
}
|
|
|
|
#[derive(Bar)]
|
|
|
|
struct Foo {}
|
|
|
|
fn main() {
|
|
|
|
Foo::bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
//- bar/Cargo.toml
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
|
|
|
|
//- bar/src/lib.rs
|
|
|
|
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();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
"###,
|
|
|
|
)
|
|
|
|
.with_config(|config| {
|
2020-04-23 11:50:25 -05:00
|
|
|
let macro_srv_path = PathBuf::from(env!("CARGO_BIN_EXE_rust-analyzer"));
|
2020-04-12 11:05:45 -05:00
|
|
|
|
|
|
|
config.cargo.load_out_dirs_from_check = true;
|
2020-04-23 11:50:25 -05:00
|
|
|
config.proc_macro_srv = Some((macro_srv_path, vec!["proc-macro".into()]));
|
2020-04-12 11:05:45 -05:00
|
|
|
})
|
|
|
|
.root("foo")
|
|
|
|
.root("bar")
|
|
|
|
.server();
|
|
|
|
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(),
|
|
|
|
});
|
2020-04-12 11:05:45 -05:00
|
|
|
|
|
|
|
let value = res.get("contents").unwrap().get("value").unwrap().to_string();
|
|
|
|
assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#)
|
|
|
|
}
|