Apply review suggestions

This commit is contained in:
vsrs 2021-03-11 17:39:41 +03:00
parent f234b80520
commit daa2637486
5 changed files with 11 additions and 18 deletions

View file

@ -5,7 +5,10 @@ use cfg::CfgExpr;
use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
use ide_assists::utils::test_related_attribute;
use ide_db::{
base_db::FilePosition, defs::Definition, search::SearchScope, RootDatabase, SymbolKind,
base_db::{FilePosition, FileRange},
defs::Definition,
search::SearchScope,
RootDatabase, SymbolKind,
};
use itertools::Itertools;
use rustc_hash::FxHashSet;
@ -168,7 +171,7 @@ fn find_related_tests_in_module(
};
let file_id = mod_source.file_id.original_file(sema.db);
let mod_scope = SearchScope::file_part(file_id, range);
let mod_scope = SearchScope::file_range(FileRange { file_id, range });
let fn_pos = FilePosition { file_id, offset: fn_name.syntax().text_range().start() };
find_related_tests(sema, fn_pos, Some(mod_scope), tests)
}

View file

@ -86,8 +86,8 @@ impl SearchScope {
SearchScope::new(std::iter::once((file, None)).collect())
}
pub fn file_part(file: FileId, range: TextRange) -> SearchScope {
SearchScope::new(std::iter::once((file, Some(range))).collect())
pub fn file_range(range: FileRange) -> SearchScope {
SearchScope::new(std::iter::once((range.file_id, Some(range.range))).collect())
}
pub fn files(files: &[FileId]) -> SearchScope {

View file

@ -609,10 +609,10 @@ pub(crate) fn handle_runnables(
pub(crate) fn handle_related_tests(
snap: GlobalStateSnapshot,
params: lsp_ext::RelatedTestsParams,
params: lsp_types::TextDocumentPositionParams,
) -> Result<Vec<lsp_ext::TestInfo>> {
let _p = profile::span("handle_related_tests");
let position = from_proto::file_position(&snap, params.text_document_position)?;
let position = from_proto::file_position(&snap, params)?;
let tests = snap.analysis.related_tests(position, None)?;
let mut res = Vec::new();

View file

@ -180,18 +180,11 @@ pub struct CargoRunnable {
pub enum RelatedTests {}
impl Request for RelatedTests {
type Params = RelatedTestsParams;
type Params = lsp_types::TextDocumentPositionParams;
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,

View file

@ -72,14 +72,11 @@ export interface Runnable {
}
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables");
export interface RelatedTestsParams extends lc.TextDocumentPositionParams {
}
export interface TestInfo {
runnable: Runnable;
}
export const relatedTests = new lc.RequestType<RelatedTestsParams, TestInfo[], void>("rust-analyzer/relatedTests");
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests");
export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;