Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ rust-analyzer #100303

Merged
merged 58 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a63b5d3
feat: Only flycheck workspace that belongs to saved file
Veykril Jul 18, 2022
25391e6
Only clear diagnostics of workspaces who have been flychecked
Veykril Jul 20, 2022
d73b0d5
Don't filter flychecks by package member status
Veykril Jul 20, 2022
a969481
Add syntax fixup for while loops
palango Jul 26, 2022
c16e4f2
Add syntax fixup for `loop`
palango Jul 27, 2022
d40ab66
fix: remove whitespaces from doctest names
lowr Aug 1, 2022
5edbdd1
Auto merge of #12918 - lowr:fix/doctest-names, r=Veykril
bors Aug 1, 2022
bd7dfac
Fix r-a spelling in some places
Aug 1, 2022
9c96073
Publish extension for 32-bit ARM systems
Aug 1, 2022
caf8a64
Set linker
Aug 1, 2022
64090ee
Fix target check
Aug 1, 2022
b72ff95
Fix linker env var name
lnicola Aug 1, 2022
cfbada4
Upload arm-unknown-linux-gnueabihf build artifact
lnicola Aug 1, 2022
c71f1e7
Don't run on PRs
Aug 1, 2022
8e38833
Auto merge of #12920 - jonas-schievink:arm-release, r=jonas-schievink
bors Aug 1, 2022
c6c0ac2
Auto merge of #12919 - jonas-schievink:speling, r=jonas-schievink
bors Aug 2, 2022
113f1db
Auto merge of #12880 - palango:while-fixup, r=Veykril
bors Aug 2, 2022
405dd77
Support adding variants via structural editing
DorianListens Jul 20, 2022
bea1fec
convert generate_enum_variant to use add_variant
DorianListens Jul 20, 2022
15d8049
Support tuple fields in generate_enum_variant
DorianListens Jul 20, 2022
e4638de
Support record fields in generate_enum_variant
DorianListens Jul 20, 2022
111694d
Be more strict about supported Paths in generate_enum_variant
DorianListens Aug 2, 2022
1980c11
Support PathPat paths in generate_enum_variant
DorianListens Aug 2, 2022
1c03f45
Auto merge of #12837 - DorianListens:dscheidt/generate-enum-data, r=V…
bors Aug 2, 2022
9a447c0
Use the release branch in xtask promote
lnicola Aug 3, 2022
a02b042
Auto merge of #12930 - lnicola:subtree-branch, r=lnicola
bors Aug 3, 2022
c203ac2
Add more constructors for la-arena
oxalica Aug 3, 2022
10f870e
Impl entry-API for la_arena::ArenaMap
oxalica Aug 3, 2022
a8a6c16
Use an empty expander for ignored non-attribute proc-macros
Veykril Aug 3, 2022
2bc9a2d
Auto merge of #12933 - Veykril:proc-ignored, r=Veykril
bors Aug 3, 2022
46d6357
Add a setting to disable comment continuation in VSCode
Veykril Aug 3, 2022
4904b2b
Auto merge of #12934 - Veykril:typing, r=Veykril
bors Aug 3, 2022
49dac40
on hover fallback error, adds ast::type as possible node
jean-santos Aug 3, 2022
df9d3db
Trigger flycheck on all transitive dependencies as well
Veykril Aug 4, 2022
5698e51
tidy formatting
jean-santos Aug 4, 2022
c6a9fbf
Auto merge of #12939 - jean-santos:errors-ide-hover-wrong-place, r=Ve…
bors Aug 4, 2022
df7f755
Don't flycheck while the workspace is being loaded
Veykril Aug 4, 2022
0fe3bcf
Auto merge of #12808 - Veykril:check-workspace, r=Veykril
bors Aug 4, 2022
30c4f9f
Update bug_report.md
Veykril Aug 5, 2022
d94a42d
Update bug_report.md
Veykril Aug 5, 2022
cb52271
Auto merge of #12946 - rust-lang:issue-template, r=lnicola
bors Aug 5, 2022
6a17372
Don't switch workspace on vfs file changes from libraries
Veykril Aug 5, 2022
d6e78b0
feat: Handle operators like their trait functions in the IDE
Veykril Aug 5, 2022
352d3c6
Fix visibilities
Veykril Aug 5, 2022
8aa50e0
Simplify
Veykril Aug 5, 2022
2364788
Auto merge of #12948 - Veykril:classify-ops, r=Veykril
bors Aug 5, 2022
6bf674c
fix: Fix incorrect token pick rankings
Veykril Aug 5, 2022
97038e5
Auto merge of #12949 - Veykril:token-pick, r=Veykril
bors Aug 5, 2022
3792720
Auto merge of #12947 - Veykril:switch-workspace, r=Veykril
bors Aug 5, 2022
5170569
Auto merge of #12931 - oxalica:feat/la-arena-apis, r=lnicola
bors Aug 6, 2022
e8a9bc0
run stable fmt through rustup
stanciuadrian Aug 6, 2022
d9e462f
Auto merge of #12953 - stanciuadrian:fmt, r=lnicola
bors Aug 6, 2022
1a94193
Impl more methods and traits for la_arena::ArenaMap
oxalica Aug 6, 2022
326ffee
Returns the old value for la_arena::ArenaMap::insert
oxalica Aug 6, 2022
eca6f2e
Fix test_rainbow_highlighting gate
lnicola Aug 7, 2022
6ec9125
Auto merge of #12959 - lnicola:rainbows-again, r=lnicola
bors Aug 7, 2022
634cfe3
Auto merge of #12956 - oxalica:feat/la-arena-apis, r=lnicola
bors Aug 7, 2022
f1e801b
:arrow_up: rust-analyzer
lnicola Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Before submitting, please make sure that you're not running into one of these kn
Otherwise please try to provide information which will help us to fix the issue faster. Minimal reproducible examples with few dependencies are especially lovely <3.
-->

**rust-analyzer version**: (eg. output of "Rust Analyzer: Show RA Version" command)
**rust-analyzer version**: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via <kbd>Ctrl/⌘</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>)

**rustc version**: (eg. output of `rustc -V`)

Expand Down
16 changes: 14 additions & 2 deletions src/tools/rust-analyzer/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
FETCH_DEPTH: 0 # pull in the tags for the version string
MACOSX_DEPLOYMENT_TARGET: 10.15
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc

jobs:
dist:
Expand All @@ -36,6 +37,9 @@ jobs:
- os: ubuntu-18.04
target: aarch64-unknown-linux-gnu
code-target: linux-arm64
- os: ubuntu-18.04
target: arm-unknown-linux-gnueabihf
code-target: linux-armhf
- os: macos-11
target: x86_64-apple-darwin
code-target: darwin-x64
Expand Down Expand Up @@ -67,13 +71,17 @@ jobs:
node-version: 14.x

- name: Update apt repositories
if: matrix.target == 'aarch64-unknown-linux-gnu'
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'arm-unknown-linux-gnueabihf'
run: sudo apt-get update

- name: Install target toolchain
- name: Install AArch64 target toolchain
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get install gcc-aarch64-linux-gnu

- name: Install ARM target toolchain
if: matrix.target == 'arm-unknown-linux-gnueabihf'
run: sudo apt-get install gcc-arm-linux-gnueabihf

- name: Dist
run: cargo xtask dist --client-patch-version ${{ github.run_number }}

Expand Down Expand Up @@ -204,6 +212,10 @@ jobs:
with:
name: dist-aarch64-unknown-linux-gnu
path: dist
- uses: actions/download-artifact@v1
with:
name: dist-arm-unknown-linux-gnueabihf
path: dist
- uses: actions/download-artifact@v1
with:
name: dist-x86_64-pc-windows-msvc
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer

## License

Rust analyzer is primarily distributed under the terms of both the MIT
rust-analyzer is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.
15 changes: 11 additions & 4 deletions src/tools/rust-analyzer/crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct FlycheckHandle {
// XXX: drop order is significant
sender: Sender<Restart>,
_thread: jod_thread::JoinHandle,
id: usize,
}

impl FlycheckHandle {
Expand All @@ -72,18 +73,22 @@ impl FlycheckHandle {
.name("Flycheck".to_owned())
.spawn(move || actor.run(receiver))
.expect("failed to spawn thread");
FlycheckHandle { sender, _thread: thread }
FlycheckHandle { id, sender, _thread: thread }
}

/// Schedule a re-start of the cargo check worker.
pub fn update(&self) {
self.sender.send(Restart).unwrap();
}

pub fn id(&self) -> usize {
self.id
}
}

pub enum Message {
/// Request adding a diagnostic with fixes included to a file
AddDiagnostic { workspace_root: AbsPathBuf, diagnostic: Diagnostic },
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },

/// Request check progress notification to client
Progress {
Expand All @@ -96,8 +101,9 @@ pub enum Message {
impl fmt::Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Message::AddDiagnostic { workspace_root, diagnostic } => f
Message::AddDiagnostic { id, workspace_root, diagnostic } => f
.debug_struct("AddDiagnostic")
.field("id", id)
.field("workspace_root", workspace_root)
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
.finish(),
Expand Down Expand Up @@ -183,7 +189,7 @@ impl FlycheckActor {
}
}
Event::CheckEvent(None) => {
tracing::debug!("flycheck finished");
tracing::debug!(flycheck_id = self.id, "flycheck finished");

// Watcher finished
let cargo_handle = self.cargo_handle.take().unwrap();
Expand All @@ -203,6 +209,7 @@ impl FlycheckActor {

CargoMessage::Diagnostic(msg) => {
self.send(Message::AddDiagnostic {
id: self.id,
workspace_root: self.workspace_root.clone(),
diagnostic: msg,
});
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
if let GenericDefId::TraitId(id) = *self {
let trait_ref = id.lookup(db).source(db).value;
let idx = idx_iter.next().unwrap();
params.insert(idx, Either::Right(trait_ref))
params.insert(idx, Either::Right(trait_ref));
}

if let Some(generic_params_list) = generic_params_list {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! unaffected, so we don't have to recompute name resolution results or item data (see `data.rs`).
//!
//! The `ItemTree` for the currently open file can be displayed by using the VS Code command
//! "Rust Analyzer: Debug ItemTree".
//! "rust-analyzer: Debug ItemTree".
//!
//! Compared to rustc's architecture, `ItemTree` has properties from both rustc's AST and HIR: many
//! syntax-level Rust features are already desugared to simpler forms in the `ItemTree`, but name
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub(crate) fn field_visibilities_query(
let resolver = variant_id.module(db).resolver(db);
let mut res = ArenaMap::default();
for (field_id, field_data) in var_data.fields().iter() {
res.insert(field_id, field_data.visibility.resolve(db, &resolver))
res.insert(field_id, field_data.visibility.resolve(db, &resolver));
}
Arc::new(res)
}
Expand Down
110 changes: 108 additions & 2 deletions src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::mem;
use mbe::{SyntheticToken, SyntheticTokenId, TokenMap};
use rustc_hash::FxHashMap;
use syntax::{
ast::{self, AstNode},
ast::{self, AstNode, HasLoopBody},
match_ast, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
};
use tt::Subtree;
Expand Down Expand Up @@ -142,8 +142,59 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
]);
}
},
ast::WhileExpr(it) => {
if it.condition().is_none() {
// insert placeholder token after the while token
let while_token = match it.while_token() {
Some(t) => t,
None => continue,
};
append.insert(while_token.into(), vec![
SyntheticToken {
kind: SyntaxKind::IDENT,
text: "__ra_fixup".into(),
range: end_range,
id: EMPTY_ID,
},
]);
}
if it.loop_body().is_none() {
append.insert(node.clone().into(), vec![
SyntheticToken {
kind: SyntaxKind::L_CURLY,
text: "{".into(),
range: end_range,
id: EMPTY_ID,
},
SyntheticToken {
kind: SyntaxKind::R_CURLY,
text: "}".into(),
range: end_range,
id: EMPTY_ID,
},
]);
}
},
ast::LoopExpr(it) => {
if it.loop_body().is_none() {
append.insert(node.clone().into(), vec![
SyntheticToken {
kind: SyntaxKind::L_CURLY,
text: "{".into(),
range: end_range,
id: EMPTY_ID,
},
SyntheticToken {
kind: SyntaxKind::R_CURLY,
text: "}".into(),
range: end_range,
id: EMPTY_ID,
},
]);
}
},
// FIXME: foo::
// FIXME: for, loop, match etc.
// FIXME: for, match etc.
_ => (),
}
}
Expand Down Expand Up @@ -376,6 +427,61 @@ fn foo() {
// the {} gets parsed as the condition, I think?
expect![[r#"
fn foo () {if {} {}}
"#]],
)
}

#[test]
fn fixup_while_1() {
check(
r#"
fn foo() {
while
}
"#,
expect![[r#"
fn foo () {while __ra_fixup {}}
"#]],
)
}

#[test]
fn fixup_while_2() {
check(
r#"
fn foo() {
while foo
}
"#,
expect![[r#"
fn foo () {while foo {}}
"#]],
)
}
#[test]
fn fixup_while_3() {
check(
r#"
fn foo() {
while {}
}
"#,
expect![[r#"
fn foo () {while __ra_fixup {}}
"#]],
)
}

#[test]
fn fixup_loop() {
check(
r#"
fn foo() {
loop
}
"#,
expect![[r#"
fn foo () {loop {}}
"#]],
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ pub mod known {
bitor,
bitxor_assign,
bitxor,
branch,
deref_mut,
deref,
div_assign,
Expand All @@ -396,6 +397,7 @@ pub mod known {
not,
owned_box,
partial_ord,
poll,
r#fn,
rem_assign,
rem,
Expand Down
63 changes: 7 additions & 56 deletions src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use chalk_ir::{
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyVariableKind,
};
use hir_def::{
expr::{ArithOp, Array, BinaryOp, CmpOp, Expr, ExprId, Literal, Ordering, Statement, UnaryOp},
expr::{ArithOp, Array, BinaryOp, CmpOp, Expr, ExprId, Literal, Statement, UnaryOp},
generics::TypeOrConstParamData,
path::{GenericArg, GenericArgs},
resolver::resolver_for_expr,
ConstParamId, FieldId, FunctionId, ItemContainerId, Lookup,
ConstParamId, FieldId, ItemContainerId, Lookup,
};
use hir_expand::name::{name, Name};
use hir_expand::name::Name;
use stdx::always;
use syntax::ast::RangeOp;

Expand All @@ -28,7 +28,7 @@ use crate::{
const_or_path_to_chalk, generic_arg_to_chalk, lower_to_chalk_mutability, ParamLoweringMode,
},
mapping::{from_chalk, ToChalk},
method_resolution::{self, VisibleFromModule},
method_resolution::{self, lang_names_for_bin_op, VisibleFromModule},
primitive::{self, UintTy},
static_lifetime, to_chalk_trait_id,
utils::{generics, Generics},
Expand Down Expand Up @@ -947,7 +947,9 @@ impl<'a> InferenceContext<'a> {
let lhs_ty = self.infer_expr(lhs, &lhs_expectation);
let rhs_ty = self.table.new_type_var();

let func = self.resolve_binop_method(op);
let func = lang_names_for_bin_op(op).and_then(|(name, lang_item)| {
self.db.trait_data(self.resolve_lang_item(lang_item)?.as_trait()?).method_by_name(&name)
});
let func = match func {
Some(func) => func,
None => {
Expand Down Expand Up @@ -1473,55 +1475,4 @@ impl<'a> InferenceContext<'a> {
},
})
}

fn resolve_binop_method(&self, op: BinaryOp) -> Option<FunctionId> {
let (name, lang_item) = match op {
BinaryOp::LogicOp(_) => return None,
BinaryOp::ArithOp(aop) => match aop {
ArithOp::Add => (name!(add), name!(add)),
ArithOp::Mul => (name!(mul), name!(mul)),
ArithOp::Sub => (name!(sub), name!(sub)),
ArithOp::Div => (name!(div), name!(div)),
ArithOp::Rem => (name!(rem), name!(rem)),
ArithOp::Shl => (name!(shl), name!(shl)),
ArithOp::Shr => (name!(shr), name!(shr)),
ArithOp::BitXor => (name!(bitxor), name!(bitxor)),
ArithOp::BitOr => (name!(bitor), name!(bitor)),
ArithOp::BitAnd => (name!(bitand), name!(bitand)),
},
BinaryOp::Assignment { op: Some(aop) } => match aop {
ArithOp::Add => (name!(add_assign), name!(add_assign)),
ArithOp::Mul => (name!(mul_assign), name!(mul_assign)),
ArithOp::Sub => (name!(sub_assign), name!(sub_assign)),
ArithOp::Div => (name!(div_assign), name!(div_assign)),
ArithOp::Rem => (name!(rem_assign), name!(rem_assign)),
ArithOp::Shl => (name!(shl_assign), name!(shl_assign)),
ArithOp::Shr => (name!(shr_assign), name!(shr_assign)),
ArithOp::BitXor => (name!(bitxor_assign), name!(bitxor_assign)),
ArithOp::BitOr => (name!(bitor_assign), name!(bitor_assign)),
ArithOp::BitAnd => (name!(bitand_assign), name!(bitand_assign)),
},
BinaryOp::CmpOp(cop) => match cop {
CmpOp::Eq { negated: false } => (name!(eq), name!(eq)),
CmpOp::Eq { negated: true } => (name!(ne), name!(eq)),
CmpOp::Ord { ordering: Ordering::Less, strict: false } => {
(name!(le), name!(partial_ord))
}
CmpOp::Ord { ordering: Ordering::Less, strict: true } => {
(name!(lt), name!(partial_ord))
}
CmpOp::Ord { ordering: Ordering::Greater, strict: false } => {
(name!(ge), name!(partial_ord))
}
CmpOp::Ord { ordering: Ordering::Greater, strict: true } => {
(name!(gt), name!(partial_ord))
}
},
BinaryOp::Assignment { op: None } => return None,
};

let trait_ = self.resolve_lang_item(lang_item)?.as_trait()?;

self.db.trait_data(trait_).method_by_name(&name)
}
}
Loading