use lsp_types::{
notification::DidOpenTextDocument,
- request::{
- CodeActionRequest, Completion, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
- },
+ request::{CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest},
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams,
PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
let project_start = Instant::now();
let server = Project::with_fixture(
r#"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- src/lib.rs
+//- /src/lib.rs
use std::collections::Spam;
"#,
)
eprintln!("completion took {:?}", completion_start.elapsed());
}
-#[test]
-fn test_runnables_no_project() {
- if skip_slow_tests() {
- return;
- }
-
- let server = project(
- r"
-//- lib.rs
-#[test]
-fn foo() {
-}
-",
- );
- server.wait_until_workspace_is_loaded();
- server.request::<Runnables>(
- RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
- json!([
- {
- "args": {
- "cargoArgs": ["test"],
- "executableArgs": ["foo", "--nocapture"],
- },
- "kind": "cargo",
- "label": "test foo",
- "location": {
- "targetRange": {
- "end": { "character": 1, "line": 2 },
- "start": { "character": 0, "line": 0 }
- },
- "targetSelectionRange": {
- "end": { "character": 6, "line": 1 },
- "start": { "character": 3, "line": 1 }
- },
- "targetUri": "file:///[..]/lib.rs"
- }
- },
- {
- "args": {
- "cargoArgs": ["check", "--workspace"],
- "executableArgs": [],
- },
- "kind": "cargo",
- "label": "cargo check --workspace"
- }
- ]),
- );
-}
-
#[test]
fn test_runnables_project() {
if skip_slow_tests() {
}
let code = r#"
-//- foo/Cargo.toml
+//- /foo/Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- foo/src/lib.rs
+//- /foo/src/lib.rs
pub fn foo() {}
-//- foo/tests/spam.rs
+//- /foo/tests/spam.rs
#[test]
fn test_eggs() {}
-//- bar/Cargo.toml
+//- /bar/Cargo.toml
[package]
name = "bar"
version = "0.0.0"
-//- bar/src/main.rs
+//- /bar/src/main.rs
fn main() {}
"#;
let server = project(
r#"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- src/lib.rs
+//- /src/lib.rs
mod bar;
fn main() {
let server = project(
r#"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
edition = "2018"
-//- src/lib.rs
+//- /src/lib.rs
mod bar;
async fn test() {
let server = project(
r#"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- src/lib.rs
+//- /src/lib.rs
mod bar;
fn main() {}
}
]
},
+ "kind": "quickfix",
"title": "Create module"
}]),
);
"deps": [],
"edition": "2015",
"cfg": [ "cfg_atom_1", "feature=cfg_1"],
- "atom_cfgs": ["atom_2"],
- "key_value_cfgs": { "feature": "key_value_feature", "other": "value"}
} ]
});
let code = format!(
r#"
-//- rust-project.json
+//- /rust-project.json
{PROJECT}
-//- src/lib.rs
+//- /src/lib.rs
mod bar;
fn main() {{}}
}
]
},
+ "kind": "quickfix",
"title": "Create module"
}]),
);
}
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();
+ let libs: String = (0..10).map(|i| format!("//- /src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
let server = Project::with_fixture(&format!(
r#"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- src/lib.rs
+//- /src/lib.rs
{}
{}
let server = Project::with_fixture(
&"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = \"foo\"
version = \"0.0.0\"
-//- src/main.rs
+//- /src/main.rs
/// Some Docs\r\nfn main() {}
",
)
let server = Project::with_fixture(
r###"
-//- Cargo.toml
+//- /Cargo.toml
[package]
name = "foo"
version = "0.0.0"
-//- build.rs
+//- /build.rs
use std::{env, fs, path::Path};
fn main() {
println!("cargo:rustc-cfg=featlike=\"set\"");
println!("cargo:rerun-if-changed=build.rs");
}
-//- src/main.rs
+//- /src/main.rs
+#[rustc_builtin_macro] macro_rules! include {}
+#[rustc_builtin_macro] macro_rules! concat {}
+#[rustc_builtin_macro] macro_rules! env {}
+
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
#[cfg(atom_cfg)]
fn main() {
let va = A;
let vb = B;
- message();
+ let should_be_str = message();
}
-
-fn main() { message(); }
"###,
)
.with_config(|config| {
})
.server();
server.wait_until_workspace_is_loaded();
- let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
+ let res = server.send_request::<HoverRequest>(HoverParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
- Position::new(14, 8),
+ Position::new(18, 10),
),
work_done_progress_params: Default::default(),
- partial_result_params: Default::default(),
});
- assert!(format!("{}", res).contains("hello.rs"));
+ assert!(res.to_string().contains("&str"));
server.request::<GotoTypeDefinition>(
GotoDefinitionParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
- Position::new(12, 9),
+ Position::new(16, 9),
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
json!([{
"originSelectionRange": {
- "end": {
- "character": 10,
- "line": 12
- },
- "start": {
- "character": 8,
- "line": 12
- }
+ "end": { "character": 10, "line": 16 },
+ "start": { "character": 8, "line": 16 }
},
"targetRange": {
- "end": {
- "character": 9,
- "line": 3
- },
- "start": {
- "character": 0,
- "line": 2
- }
+ "end": { "character": 9, "line": 7 },
+ "start": { "character": 0, "line": 6 }
},
"targetSelectionRange": {
- "end": {
- "character": 8,
- "line": 3
- },
- "start": {
- "character": 7,
- "line": 3
- }
+ "end": { "character": 8, "line": 7 },
+ "start": { "character": 7, "line": 7 }
},
"targetUri": "file:///[..]src/main.rs"
}]),
GotoDefinitionParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
- Position::new(13, 9),
+ Position::new(17, 9),
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
json!([{
"originSelectionRange": {
- "end": {
- "character": 10,
- "line": 13
- },
- "start": {
- "character": 8,
- "line":13
- }
+ "end": { "character": 10, "line": 17 },
+ "start": { "character": 8, "line": 17 }
},
"targetRange": {
- "end": {
- "character": 9,
- "line": 7
- },
- "start": {
- "character": 0,
- "line":6
- }
+ "end": { "character": 9, "line": 11 },
+ "start": { "character": 0, "line":10 }
},
"targetSelectionRange": {
- "end": {
- "character": 8,
- "line": 7
- },
- "start": {
- "character": 7,
- "line": 7
- }
+ "end": { "character": 8, "line": 11 },
+ "start": { "character": 7, "line": 11 }
},
"targetUri": "file:///[..]src/main.rs"
}]),
}
let server = Project::with_fixture(
r###"
-//- foo/Cargo.toml
+//- /foo/Cargo.toml
[package]
name = "foo"
version = "0.0.0"
[dependencies]
bar = {path = "../bar"}
-//- foo/src/main.rs
+//- /foo/src/main.rs
use bar::Bar;
trait Bar {
fn bar();
Foo::bar();
}
-//- bar/Cargo.toml
+//- /bar/Cargo.toml
[package]
name = "bar"
version = "0.0.0"
[lib]
proc-macro = true
-//- bar/src/lib.rs
+//- /bar/src/lib.rs
extern crate proc_macro;
use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
macro_rules! t {