Add LSP request and VSCode command
This commit is contained in:
@@ -607,6 +607,24 @@ pub(crate) fn handle_runnables(
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_related_tests(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::RelatedTestsParams,
|
||||
) -> Result<Vec<lsp_ext::TestInfo>> {
|
||||
let _p = profile::span("handle_related_tests");
|
||||
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
||||
|
||||
let tests = snap.analysis.related_tests(position, None)?;
|
||||
let mut res = Vec::new();
|
||||
for it in tests {
|
||||
if let Ok(runnable) = to_proto::runnable(&snap, it) {
|
||||
res.push(lsp_ext::TestInfo { runnable })
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_completion(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::CompletionParams,
|
||||
|
||||
@@ -177,6 +177,26 @@ pub struct CargoRunnable {
|
||||
pub expect_test: Option<bool>,
|
||||
}
|
||||
|
||||
pub enum RelatedTests {}
|
||||
|
||||
impl Request for RelatedTests {
|
||||
type Params = RelatedTestsParams;
|
||||
type Result = Vec<TestInfo>;
|
||||
const METHOD: &'static str = "rust-analyzer/relatedTests";
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RelatedTestsParams {
|
||||
#[serde(flatten)]
|
||||
pub text_document_position: lsp_types::TextDocumentPositionParams,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TestInfo {
|
||||
pub runnable: Runnable,
|
||||
}
|
||||
|
||||
pub enum InlayHints {}
|
||||
|
||||
impl Request for InlayHints {
|
||||
|
||||
@@ -500,6 +500,7 @@ impl GlobalState {
|
||||
.on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)
|
||||
.on::<lsp_ext::ParentModule>(handlers::handle_parent_module)
|
||||
.on::<lsp_ext::Runnables>(handlers::handle_runnables)
|
||||
.on::<lsp_ext::RelatedTests>(handlers::handle_related_tests)
|
||||
.on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)
|
||||
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)
|
||||
.on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)
|
||||
|
||||
Reference in New Issue
Block a user