Skip to content

Commit

Permalink
adding commands to run and debug selected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adstep committed Nov 29, 2023
1 parent cccc7ca commit 3e343e7
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 228 deletions.
276 changes: 98 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ text-size = "1.1.1"
rayon = "1.8.0"
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
triomphe = { version = "0.1.10", default-features = false, features = ["std"] }
# can't upgrade due to dashmap depending on 0.12.3 currently
hashbrown = { version = "0.12.3", features = [
"inline-more",
Expand Down
2 changes: 1 addition & 1 deletion crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust-version.workspace = true
doctest = false

[dependencies]
salsa = "0.17.0-pre.2"
rust-analyzer-salsa = "0.17.0-pre.3"
rustc-hash = "1.1.0"

triomphe.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ oorandom = "11.1.3"
tracing.workspace = true
rustc-hash = "1.1.0"
scoped-tls = "1.0.0"
chalk-solve = { version = "0.94.0", default-features = false }
chalk-ir = "0.94.0"
chalk-recursive = { version = "0.94.0", default-features = false }
chalk-derive = "0.94.0"
chalk-solve = { version = "0.95.0", default-features = false }
chalk-ir = "0.95.0"
chalk-recursive = { version = "0.95.0", default-features = false }
chalk-derive = "0.95.0"
la-arena.workspace = true
once_cell = "1.17.0"
triomphe.workspace = true
Expand Down
21 changes: 8 additions & 13 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,20 +1152,15 @@ impl<'a> InferenceContext<'a> {
(ty, variant)
}
TypeNs::TypeAliasId(it) => {
let container = it.lookup(self.db.upcast()).container;
let parent_subst = match container {
ItemContainerId::TraitId(id) => {
let subst = TyBuilder::subst_for_def(self.db, id, None)
.fill_with_inference_vars(&mut self.table)
.build();
Some(subst)
}
// Type aliases do not exist in impls.
_ => None,
let resolved_seg = match unresolved {
None => path.segments().last().unwrap(),
Some(n) => path.segments().get(path.segments().len() - n - 1).unwrap(),
};
let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
.fill_with_inference_vars(&mut self.table)
.build();
let substs =
ctx.substs_from_path_segment(resolved_seg, Some(it.into()), true, None);
let ty = self.db.ty(it.into());
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));

self.resolve_variant_on_alias(ty, unresolved, mod_path)
}
TypeNs::AdtSelfType(_) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'a> TyLoweringContext<'a> {
}
}

fn substs_from_path_segment(
pub(super) fn substs_from_path_segment(
&self,
segment: PathSegment<'_>,
def: Option<GenericDefId>,
Expand Down
24 changes: 24 additions & 0 deletions crates/hir-ty/src/tests/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,27 @@ fn foo() {
"#,
);
}

#[test]
fn generic_alias() {
check_types(
r#"
type Wrap<T> = T;
enum X {
A { cool: u32, stuff: u32 },
B,
}
fn main() {
let wrapped = Wrap::<X>::A {
cool: 100,
stuff: 100,
};
if let Wrap::<X>::A { cool, ..} = &wrapped {}
//^^^^ &u32
}
"#,
);
}
33 changes: 27 additions & 6 deletions crates/ide-assists/src/handlers/remove_parentheses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syntax::{ast, AstNode};
use syntax::{ast, AstNode, SyntaxKind, T};

use crate::{AssistContext, AssistId, AssistKind, Assists};

Expand Down Expand Up @@ -39,7 +39,19 @@ pub(crate) fn remove_parentheses(acc: &mut Assists, ctx: &AssistContext<'_>) ->
AssistId("remove_parentheses", AssistKind::Refactor),
"Remove redundant parentheses",
target,
|builder| builder.replace_ast(parens.into(), expr),
|builder| {
let prev_token = parens.syntax().first_token().and_then(|it| it.prev_token());
let need_to_add_ws = match prev_token {
Some(it) => {
let tokens = vec![T![&], T![!], T!['('], T!['['], T!['{']];
it.kind() != SyntaxKind::WHITESPACE && !tokens.contains(&it.kind())
}
None => false,
};
let expr = if need_to_add_ws { format!(" {}", expr) } else { expr.to_string() };

builder.replace(parens.syntax().text_range(), expr)
},
)
}

Expand All @@ -49,6 +61,15 @@ mod tests {

use super::*;

#[test]
fn remove_parens_space() {
check_assist(
remove_parentheses,
r#"fn f() { match$0(true) {} }"#,
r#"fn f() { match true {} }"#,
);
}

#[test]
fn remove_parens_simple() {
check_assist(remove_parentheses, r#"fn f() { $0(2) + 2; }"#, r#"fn f() { 2 + 2; }"#);
Expand Down Expand Up @@ -94,8 +115,8 @@ mod tests {
check_assist(remove_parentheses, r#"fn f() { f(($02 + 2)); }"#, r#"fn f() { f(2 + 2); }"#);
check_assist(
remove_parentheses,
r#"fn f() { (1<2)&&$0(3>4); }"#,
r#"fn f() { (1<2)&&3>4; }"#,
r#"fn f() { (1<2) &&$0(3>4); }"#,
r#"fn f() { (1<2) && 3>4; }"#,
);
}

Expand Down Expand Up @@ -164,8 +185,8 @@ mod tests {
fn remove_parens_weird_places() {
check_assist(
remove_parentheses,
r#"fn f() { match () { _=>$0(()) } }"#,
r#"fn f() { match () { _=>() } }"#,
r#"fn f() { match () { _ =>$0(()) } }"#,
r#"fn f() { match () { _ => () } }"#,
);

check_assist(
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/toggle_ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
}

fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
fn_def.attrs().find(|attr| attr.path().is_some_and(|it| it.syntax().text() == "ignore"))
}

#[cfg(test)]
Expand Down
21 changes: 17 additions & 4 deletions crates/ide-completion/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ use crate::{
pub struct CompletionItem {
/// Label in the completion pop up which identifies completion.
pub label: SmolStr,
/// Additional label details in the completion pop up that are
/// displayed and aligned on the right side after the label.
pub label_detail: Option<SmolStr>,

/// Range of identifier that is being completed.
///
/// It should be used primarily for UI, but we also use this to convert
Expand Down Expand Up @@ -425,13 +429,14 @@ impl Builder {
pub(crate) fn build(self, db: &RootDatabase) -> CompletionItem {
let _p = profile::span("item::Builder::build");

let mut label = self.label;
let label = self.label;
let mut label_detail = None;
let mut lookup = self.lookup.unwrap_or_else(|| label.clone());
let insert_text = self.insert_text.unwrap_or_else(|| label.to_string());

if !self.doc_aliases.is_empty() {
let doc_aliases = self.doc_aliases.iter().join(", ");
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
label_detail.replace(SmolStr::from(format!(" (alias {doc_aliases})")));
let lookup_doc_aliases = self
.doc_aliases
.iter()
Expand All @@ -454,10 +459,17 @@ impl Builder {
if let [import_edit] = &*self.imports_to_add {
// snippets can have multiple imports, but normal completions only have up to one
if let Some(original_path) = import_edit.original_path.as_ref() {
label = SmolStr::from(format!("{label} (use {})", original_path.display(db)));
label_detail.replace(SmolStr::from(format!(
"{} (use {})",
label_detail.as_deref().unwrap_or_default(),
original_path.display(db)
)));
}
} else if let Some(trait_name) = self.trait_name {
label = SmolStr::from(format!("{label} (as {trait_name})"));
label_detail.replace(SmolStr::from(format!(
"{} (as {trait_name})",
label_detail.as_deref().unwrap_or_default(),
)));
}

let text_edit = match self.text_edit {
Expand All @@ -479,6 +491,7 @@ impl Builder {
CompletionItem {
source_range: self.source_range,
label,
label_detail,
text_edit,
is_snippet: self.is_snippet,
detail: self.detail,
Expand Down
6 changes: 5 additions & 1 deletion crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ mod tests {

let tag = it.kind.tag();
let relevance = display_relevance(it.relevance);
items.push(format!("{tag} {} {relevance}\n", it.label));
items.push(format!(
"{tag} {}{} {relevance}\n",
it.label,
it.label_detail.clone().unwrap_or_default(),
));

if let Some((label, _indel, relevance)) = it.ref_match() {
let relevance = display_relevance(relevance);
Expand Down
19 changes: 16 additions & 3 deletions crates/ide-completion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,29 @@ fn render_completion_list(completions: Vec<CompletionItem>) -> String {
fn monospace_width(s: &str) -> usize {
s.chars().count()
}
let label_width =
completions.iter().map(|it| monospace_width(&it.label)).max().unwrap_or_default().min(22);
let label_width = completions
.iter()
.map(|it| {
monospace_width(&it.label)
+ monospace_width(it.label_detail.as_deref().unwrap_or_default())
})
.max()
.unwrap_or_default()
.min(22);
completions
.into_iter()
.map(|it| {
let tag = it.kind.tag();
let var_name = format!("{tag} {}", it.label);
let mut buf = var_name;
if let Some(ref label_detail) = it.label_detail {
format_to!(buf, "{label_detail}");
}
if let Some(detail) = it.detail {
let width = label_width.saturating_sub(monospace_width(&it.label));
let width = label_width.saturating_sub(
monospace_width(&it.label)
+ monospace_width(&it.label_detail.unwrap_or_default()),
);
format_to!(buf, "{:width$} {}", "", detail, width = width);
}
if it.deprecated {
Expand Down
29 changes: 29 additions & 0 deletions crates/ide-completion/src/tests/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,35 @@ fn outer(Foo { bar$0 }: Foo) {}
)
}

#[test]
fn completes_in_record_field_pat_with_generic_type_alias() {
check_empty(
r#"
type Wrap<T> = T;
enum X {
A { cool: u32, stuff: u32 },
B,
}
fn main() {
let wrapped = Wrap::<X>::A {
cool: 100,
stuff: 100,
};
if let Wrap::<X>::A { $0 } = &wrapped {};
}
"#,
expect![[r#"
fd cool u32
fd stuff u32
kw mut
kw ref
"#]],
)
}

#[test]
fn completes_in_fn_param() {
check_empty(
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/extend_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn try_extend_selection(

let node = shallowest_node(&node);

if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
if node.parent().is_some_and(|n| list_kinds.contains(&n.kind())) {
if let Some(range) = extend_list_item(&node) {
return Some(range);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ fn completion_item(

if config.completion_label_details_support() {
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
detail: None,
detail: item.label_detail.as_ref().map(ToString::to_string),
description: lsp_item.detail.clone(),
});
} else if let Some(label_detail) = item.label_detail {
lsp_item.label.push_str(label_detail.as_str());
}

set_score(&mut lsp_item, max_relevance, item.relevance);
Expand Down
11 changes: 4 additions & 7 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use ide_db::{
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, ProcMacros},
FxHashMap,
};
use itertools::Itertools;
use load_cargo::{load_proc_macro, ProjectFolders};
use proc_macro_api::ProcMacroServer;
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
Expand Down Expand Up @@ -227,16 +228,12 @@ impl GlobalState {
let mut i = 0;
while i < workspaces.len() {
if let Ok(w) = &workspaces[i] {
let dupes: Vec<_> = workspaces
let dupes: Vec<_> = workspaces[i + 1..]
.iter()
.enumerate()
.skip(i + 1)
.filter_map(|(i, it)| {
it.as_ref().ok().filter(|ws| ws.eq_ignore_build_data(w)).map(|_| i)
})
.positions(|it| it.as_ref().is_ok_and(|ws| ws.eq_ignore_build_data(w)))
.collect();
dupes.into_iter().rev().for_each(|d| {
_ = workspaces.remove(d);
_ = workspaces.remove(d + i + 1);
});
}
i += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/tests/slow-tests/tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn check_trailing_ws(path: &Path, text: &str) {
return;
}
for (line_number, line) in text.lines().enumerate() {
if line.chars().last().map(char::is_whitespace) == Some(true) {
if line.chars().last().is_some_and(char::is_whitespace) {
panic!("Trailing whitespace in {} at line {}", path.display(), line_number + 1)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc-dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ authors.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ra-ap-rustc_lexer = { version = "0.19.0" }
ra-ap-rustc_parse_format = { version = "0.14.0", default-features = false }
ra-ap-rustc_index = { version = "0.19.0", default-features = false }
ra-ap-rustc_abi = { version = "0.19.0", default-features = false }
ra-ap-rustc_lexer = { version = "0.20.0" }
ra-ap-rustc_parse_format = { version = "0.20.0", default-features = false }
ra-ap-rustc_index = { version = "0.20.0", default-features = false }
ra-ap-rustc_abi = { version = "0.20.0", default-features = false }

[features]
in-rust-tree = []
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.showRequestFailedErrorNotification": {
"markdownDescription": "Whether to show error notifications for failing requests.",
"default": true,
"type": "boolean"
},
"rust-analyzer.showDependenciesExplorer": {
"markdownDescription": "Whether to show the dependencies view.",
"default": true,
Expand Down
Loading

0 comments on commit 3e343e7

Please sign in to comment.