mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Merge #3038
3038: Minor rename r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a4431e8302
3 changed files with 11 additions and 9 deletions
|
@ -8,19 +8,21 @@ mod generated;
|
||||||
use ra_db::FileRange;
|
use ra_db::FileRange;
|
||||||
use test_utils::{assert_eq_text, extract_range_or_offset};
|
use test_utils::{assert_eq_text, extract_range_or_offset};
|
||||||
|
|
||||||
|
use crate::resolved_assists;
|
||||||
|
|
||||||
fn check(assist_id: &str, before: &str, after: &str) {
|
fn check(assist_id: &str, before: &str, after: &str) {
|
||||||
let (selection, before) = extract_range_or_offset(before);
|
let (selection, before) = extract_range_or_offset(before);
|
||||||
let (db, file_id) = crate::helpers::with_single_file(&before);
|
let (db, file_id) = crate::helpers::with_single_file(&before);
|
||||||
let frange = FileRange { file_id, range: selection.into() };
|
let frange = FileRange { file_id, range: selection.into() };
|
||||||
|
|
||||||
let assist = crate::assists(&db, frange)
|
let assist = resolved_assists(&db, frange)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|assist| assist.label.id.0 == assist_id)
|
.find(|assist| assist.label.id.0 == assist_id)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
"\n\nAssist is not applicable: {}\nAvailable assists: {}",
|
"\n\nAssist is not applicable: {}\nAvailable assists: {}",
|
||||||
assist_id,
|
assist_id,
|
||||||
crate::assists(&db, frange)
|
resolved_assists(&db, frange)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|assist| assist.label.id.0)
|
.map(|assist| assist.label.id.0)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl ResolvedAssist {
|
||||||
///
|
///
|
||||||
/// Assists are returned in the "unresolved" state, that is only labels are
|
/// Assists are returned in the "unresolved" state, that is only labels are
|
||||||
/// returned, without actual edits.
|
/// returned, without actual edits.
|
||||||
pub fn applicable_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> {
|
pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> {
|
||||||
AssistCtx::with_ctx(db, range, false, |ctx| {
|
AssistCtx::with_ctx(db, range, false, |ctx| {
|
||||||
assists::all()
|
assists::all()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -76,7 +76,7 @@ pub fn applicable_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabe
|
||||||
///
|
///
|
||||||
/// Assists are returned in the "resolved" state, that is with edit fully
|
/// Assists are returned in the "resolved" state, that is with edit fully
|
||||||
/// computed.
|
/// computed.
|
||||||
pub fn assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
|
pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
|
||||||
AssistCtx::with_ctx(db, range, true, |ctx| {
|
AssistCtx::with_ctx(db, range, true, |ctx| {
|
||||||
let mut a = assists::all()
|
let mut a = assists::all()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -301,7 +301,7 @@ mod tests {
|
||||||
use ra_syntax::TextRange;
|
use ra_syntax::TextRange;
|
||||||
use test_utils::{extract_offset, extract_range};
|
use test_utils::{extract_offset, extract_range};
|
||||||
|
|
||||||
use crate::helpers;
|
use crate::{helpers, resolved_assists};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn assist_order_field_struct() {
|
fn assist_order_field_struct() {
|
||||||
|
@ -310,7 +310,7 @@ mod tests {
|
||||||
let (db, file_id) = helpers::with_single_file(&before);
|
let (db, file_id) = helpers::with_single_file(&before);
|
||||||
let frange =
|
let frange =
|
||||||
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
|
||||||
let assists = super::assists(&db, frange);
|
let assists = resolved_assists(&db, frange);
|
||||||
let mut assists = assists.iter();
|
let mut assists = assists.iter();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -333,7 +333,7 @@ mod tests {
|
||||||
let (range, before) = extract_range(before);
|
let (range, before) = extract_range(before);
|
||||||
let (db, file_id) = helpers::with_single_file(&before);
|
let (db, file_id) = helpers::with_single_file(&before);
|
||||||
let frange = FileRange { file_id, range };
|
let frange = FileRange { file_id, range };
|
||||||
let assists = super::assists(&db, frange);
|
let assists = resolved_assists(&db, frange);
|
||||||
let mut assists = assists.iter();
|
let mut assists = assists.iter();
|
||||||
|
|
||||||
assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable");
|
assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use ra_assists::{AssistAction, AssistLabel};
|
use ra_assists::{resolved_assists, AssistAction, AssistLabel};
|
||||||
use ra_db::{FilePosition, FileRange};
|
use ra_db::{FilePosition, FileRange};
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::RootDatabase;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ pub struct Assist {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> {
|
pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> {
|
||||||
ra_assists::assists(db, frange)
|
resolved_assists(db, frange)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|assist| {
|
.map(|assist| {
|
||||||
let file_id = frange.file_id;
|
let file_id = frange.file_id;
|
||||||
|
|
Loading…
Reference in a new issue