mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
178c3e135a
1185 changed files with 4251 additions and 3672 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1,5 +1,5 @@
|
||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
crates/ra_syntax/test_data/** -text eof=LF
|
crates/syntax/test_data/** -text eof=LF
|
||||||
# Older git versions try to fix line endings on images, this prevents it.
|
# Older git versions try to fix line endings on images, this prevents it.
|
||||||
*.png binary
|
*.png binary
|
||||||
*.jpg binary
|
*.jpg binary
|
||||||
|
|
36
.github/workflows/ci.yaml
vendored
36
.github/workflows/ci.yaml
vendored
|
@ -16,20 +16,6 @@ env:
|
||||||
RUSTUP_MAX_RETRIES: 10
|
RUSTUP_MAX_RETRIES: 10
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# rust-audit:
|
|
||||||
# name: Audit Rust vulnerabilities
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - name: Checkout repository
|
|
||||||
# uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# - uses: actions-rs/install@v0.1
|
|
||||||
# with:
|
|
||||||
# crate: cargo-audit
|
|
||||||
# use-tool-cache: true
|
|
||||||
|
|
||||||
# - run: cargo audit
|
|
||||||
|
|
||||||
rust:
|
rust:
|
||||||
name: Rust
|
name: Rust
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -39,7 +25,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest] #, macos-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
|
@ -88,11 +74,14 @@ jobs:
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
run: Remove-Item ./target/debug/xtask.exe, ./target/debug/deps/xtask.exe
|
run: Remove-Item ./target/debug/xtask.exe, ./target/debug/deps/xtask.exe
|
||||||
|
|
||||||
# Weird target to catch non-portable code
|
# Weird targets to catch non-portable code
|
||||||
rust-power:
|
rust-cross:
|
||||||
name: Rust Power
|
name: Rust Cross
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
targets: "powerpc-unknown-linux-gnu x86_64-unknown-linux-musl"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -103,7 +92,9 @@ jobs:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
target: 'powerpc-unknown-linux-gnu'
|
|
||||||
|
- name: Install Rust targets
|
||||||
|
run: rustup target add ${{ env.targets }}
|
||||||
|
|
||||||
- name: Cache cargo directories
|
- name: Cache cargo directories
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
|
@ -114,14 +105,17 @@ jobs:
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Check
|
- name: Check
|
||||||
run: cargo check --target=powerpc-unknown-linux-gnu --all-targets
|
run: |
|
||||||
|
for target in ${{ env.targets }}; do
|
||||||
|
cargo check --target=$target --all-targets
|
||||||
|
done
|
||||||
|
|
||||||
typescript:
|
typescript:
|
||||||
name: TypeScript
|
name: TypeScript
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
|
763
Cargo.lock
generated
763
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -39,7 +39,7 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0
|
||||||
|
|
||||||
* Website: https://rust-analyzer.github.io/
|
* Website: https://rust-analyzer.github.io/
|
||||||
* Metrics: https://rust-analyzer.github.io/metrics/
|
* Metrics: https://rust-analyzer.github.io/metrics/
|
||||||
* API docs: https://rust-analyzer.github.io/rust-analyzer/ra_ide/
|
* API docs: https://rust-analyzer.github.io/rust-analyzer/ide/
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
status = [
|
status = [
|
||||||
"Rust (ubuntu-latest)",
|
"Rust (ubuntu-latest)",
|
||||||
"Rust (windows-latest)",
|
"Rust (windows-latest)",
|
||||||
"Rust (macos-latest)",
|
# "Rust (macos-latest)",
|
||||||
"TypeScript (ubuntu-latest)",
|
"TypeScript (ubuntu-latest)",
|
||||||
"TypeScript (windows-latest)",
|
"TypeScript (windows-latest)",
|
||||||
"TypeScript (macos-latest)",
|
|
||||||
]
|
]
|
||||||
delete_merged_branches = true
|
delete_merged_branches = true
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
name = "arena"
|
||||||
name = "ra_arena"
|
version = "0.0.0"
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["rust-analyzer developers"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
23
crates/assists/Cargo.toml
Normal file
23
crates/assists/Cargo.toml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
[package]
|
||||||
|
name = "assists"
|
||||||
|
version = "0.0.0"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
doctest = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rustc-hash = "1.1.0"
|
||||||
|
itertools = "0.9.0"
|
||||||
|
either = "1.5.3"
|
||||||
|
|
||||||
|
stdx = { path = "../stdx" }
|
||||||
|
syntax = { path = "../syntax" }
|
||||||
|
text_edit = { path = "../text_edit" }
|
||||||
|
profile = { path = "../profile" }
|
||||||
|
base_db = { path = "../base_db" }
|
||||||
|
ide_db = { path = "../ide_db" }
|
||||||
|
hir = { path = "../hir" }
|
||||||
|
test_utils = { path = "../test_utils" }
|
|
@ -3,19 +3,18 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use algo::find_covering_element;
|
use algo::find_covering_element;
|
||||||
|
use base_db::{FileId, FileRange};
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ra_db::{FileId, FileRange};
|
use ide_db::{
|
||||||
use ra_fmt::{leading_indent, reindent};
|
|
||||||
use ra_ide_db::{
|
|
||||||
source_change::{SourceChange, SourceFileEdit},
|
source_change::{SourceChange, SourceFileEdit},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::{self, find_node_at_offset, SyntaxRewriter},
|
algo::{self, find_node_at_offset, SyntaxRewriter},
|
||||||
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxToken, TextRange, TextSize,
|
||||||
TokenAtOffset,
|
TokenAtOffset,
|
||||||
};
|
};
|
||||||
use ra_text_edit::TextEditBuilder;
|
use text_edit::{TextEdit, TextEditBuilder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_config::{AssistConfig, SnippetCap},
|
assist_config::{AssistConfig, SnippetCap},
|
||||||
|
@ -214,7 +213,7 @@ pub(crate) struct AssistBuilder {
|
||||||
impl AssistBuilder {
|
impl AssistBuilder {
|
||||||
pub(crate) fn new(file_id: FileId) -> AssistBuilder {
|
pub(crate) fn new(file_id: FileId) -> AssistBuilder {
|
||||||
AssistBuilder {
|
AssistBuilder {
|
||||||
edit: TextEditBuilder::default(),
|
edit: TextEdit::builder(),
|
||||||
file_id,
|
file_id,
|
||||||
is_snippet: false,
|
is_snippet: false,
|
||||||
change: SourceChange::default(),
|
change: SourceChange::default(),
|
||||||
|
@ -269,20 +268,6 @@ impl AssistBuilder {
|
||||||
pub(crate) fn replace_ast<N: AstNode>(&mut self, old: N, new: N) {
|
pub(crate) fn replace_ast<N: AstNode>(&mut self, old: N, new: N) {
|
||||||
algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit)
|
algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit)
|
||||||
}
|
}
|
||||||
/// Replaces specified `node` of text with a given string, reindenting the
|
|
||||||
/// string to maintain `node`'s existing indent.
|
|
||||||
// FIXME: remove in favor of ra_syntax::edit::IndentLevel::increase_indent
|
|
||||||
pub(crate) fn replace_node_and_indent(
|
|
||||||
&mut self,
|
|
||||||
node: &SyntaxNode,
|
|
||||||
replace_with: impl Into<String>,
|
|
||||||
) {
|
|
||||||
let mut replace_with = replace_with.into();
|
|
||||||
if let Some(indent) = leading_indent(node) {
|
|
||||||
replace_with = reindent(&replace_with, &indent)
|
|
||||||
}
|
|
||||||
self.replace(node.text_range(), replace_with)
|
|
||||||
}
|
|
||||||
pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) {
|
pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) {
|
||||||
let node = rewriter.rewrite_root().unwrap();
|
let node = rewriter.rewrite_root().unwrap();
|
||||||
let new = rewriter.rewrite(&node);
|
let new = rewriter.rewrite(&node);
|
|
@ -2,13 +2,13 @@
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use hir::{HirDisplay, PathResolution, SemanticsScope};
|
use hir::{HirDisplay, PathResolution, SemanticsScope};
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::SyntaxRewriter,
|
algo::SyntaxRewriter,
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait AstTransform<'a> {
|
pub trait AstTransform<'a> {
|
||||||
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode>;
|
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode>;
|
||||||
|
|
||||||
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a>;
|
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a>;
|
||||||
fn or<T: AstTransform<'a> + 'a>(self, other: T) -> Box<dyn AstTransform<'a> + 'a>
|
fn or<T: AstTransform<'a> + 'a>(self, other: T) -> Box<dyn AstTransform<'a> + 'a>
|
||||||
|
@ -22,7 +22,7 @@ pub trait AstTransform<'a> {
|
||||||
struct NullTransformer;
|
struct NullTransformer;
|
||||||
|
|
||||||
impl<'a> AstTransform<'a> for NullTransformer {
|
impl<'a> AstTransform<'a> for NullTransformer {
|
||||||
fn get_substitution(&self, _node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
|
fn get_substitution(&self, _node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
||||||
|
@ -51,7 +51,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
||||||
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
|
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
|
||||||
.skip(1)
|
.skip(1)
|
||||||
// The actual list of trait type parameters may be longer than the one
|
// The actual list of trait type parameters may be longer than the one
|
||||||
// used in the `impl` block due to trailing default type parametrs.
|
// used in the `impl` block due to trailing default type parameters.
|
||||||
// For that case we extend the `substs` with an empty iterator so we
|
// For that case we extend the `substs` with an empty iterator so we
|
||||||
// can still hit those trailing values and check if they actually have
|
// can still hit those trailing values and check if they actually have
|
||||||
// a default type. If they do, go for that type from `hir` to `ast` so
|
// a default type. If they do, go for that type from `hir` to `ast` so
|
||||||
|
@ -101,10 +101,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_substitution_inner(
|
fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
&self,
|
|
||||||
node: &ra_syntax::SyntaxNode,
|
|
||||||
) -> Option<ra_syntax::SyntaxNode> {
|
|
||||||
let type_ref = ast::Type::cast(node.clone())?;
|
let type_ref = ast::Type::cast(node.clone())?;
|
||||||
let path = match &type_ref {
|
let path = match &type_ref {
|
||||||
ast::Type::PathType(path_type) => path_type.path()?,
|
ast::Type::PathType(path_type) => path_type.path()?,
|
||||||
|
@ -122,7 +119,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
|
impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
|
||||||
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
|
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
||||||
}
|
}
|
||||||
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
||||||
|
@ -141,10 +138,7 @@ impl<'a> QualifyPaths<'a> {
|
||||||
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
|
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_substitution_inner(
|
fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
&self,
|
|
||||||
node: &ra_syntax::SyntaxNode,
|
|
||||||
) -> Option<ra_syntax::SyntaxNode> {
|
|
||||||
// FIXME handle value ns?
|
// FIXME handle value ns?
|
||||||
let from = self.target_scope.module()?;
|
let from = self.target_scope.module()?;
|
||||||
let p = ast::Path::cast(node.clone())?;
|
let p = ast::Path::cast(node.clone())?;
|
||||||
|
@ -183,7 +177,7 @@ impl<'a> QualifyPaths<'a> {
|
||||||
|
|
||||||
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
|
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
|
||||||
SyntaxRewriter::from_fn(|element| match element {
|
SyntaxRewriter::from_fn(|element| match element {
|
||||||
ra_syntax::SyntaxElement::Node(n) => {
|
syntax::SyntaxElement::Node(n) => {
|
||||||
let replacement = transformer.get_substitution(&n)?;
|
let replacement = transformer.get_substitution(&n)?;
|
||||||
Some(replacement.into())
|
Some(replacement.into())
|
||||||
}
|
}
|
||||||
|
@ -193,7 +187,7 @@ pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
|
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
|
||||||
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
|
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
||||||
}
|
}
|
||||||
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
|
|
@ -1,10 +1,10 @@
|
||||||
use ra_syntax::{
|
use itertools::Itertools;
|
||||||
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
Direction, SmolStr,
|
Direction, SmolStr,
|
||||||
SyntaxKind::{IDENT, WHITESPACE},
|
SyntaxKind::{IDENT, WHITESPACE},
|
||||||
TextRange, TextSize,
|
TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use stdx::SepBy;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::{AssistContext, Assists},
|
assist_context::{AssistContext, Assists},
|
||||||
|
@ -61,9 +61,9 @@ pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
||||||
.filter(|t| t != trait_token.text())
|
.filter(|t| t != trait_token.text())
|
||||||
.collect::<Vec<SmolStr>>();
|
.collect::<Vec<SmolStr>>();
|
||||||
let has_more_derives = !new_attr_input.is_empty();
|
let has_more_derives = !new_attr_input.is_empty();
|
||||||
let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();
|
|
||||||
|
|
||||||
if has_more_derives {
|
if has_more_derives {
|
||||||
|
let new_attr_input = format!("({})", new_attr_input.iter().format(", "));
|
||||||
builder.replace(input.syntax().text_range(), new_attr_input);
|
builder.replace(input.syntax().text_range(), new_attr_input);
|
||||||
} else {
|
} else {
|
||||||
let attr_range = attr.syntax().text_range();
|
let attr_range = attr.syntax().text_range();
|
|
@ -1,5 +1,5 @@
|
||||||
use hir::HirDisplay;
|
use hir::HirDisplay;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, LetStmt, NameOwner},
|
ast::{self, AstNode, LetStmt, NameOwner},
|
||||||
TextRange,
|
TextRange,
|
||||||
};
|
};
|
|
@ -1,5 +1,5 @@
|
||||||
use hir::HasSource;
|
use hir::HasSource;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{self, AstNodeEdit, IndentLevel},
|
edit::{self, AstNodeEdit, IndentLevel},
|
||||||
|
@ -110,7 +110,7 @@ fn add_missing_impl_members_inner(
|
||||||
assist_id: &'static str,
|
assist_id: &'static str,
|
||||||
label: &'static str,
|
label: &'static str,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let _p = ra_prof::profile("add_missing_impl_members_inner");
|
let _p = profile::span("add_missing_impl_members_inner");
|
||||||
let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
|
let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
|
||||||
let impl_item_list = impl_def.assoc_item_list()?;
|
let impl_item_list = impl_def.assoc_item_list()?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ra_ide_db::defs::{classify_name_ref, Definition, NameRefClass};
|
use ide_db::defs::{classify_name_ref, Definition, NameRefClass};
|
||||||
use ra_syntax::{ast, AstNode, SyntaxKind, T};
|
use syntax::{ast, AstNode, SyntaxKind, T};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -41,7 +41,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
||||||
let name_ref = ast::NameRef::cast(ident.parent())?;
|
let name_ref = ast::NameRef::cast(ident.parent())?;
|
||||||
let def = match classify_name_ref(&ctx.sema, &name_ref)? {
|
let def = match classify_name_ref(&ctx.sema, &name_ref)? {
|
||||||
NameRefClass::Definition(def) => def,
|
NameRefClass::Definition(def) => def,
|
||||||
NameRefClass::FieldShorthand { .. } => return None,
|
NameRefClass::ExternCrate(_) | NameRefClass::FieldShorthand { .. } => return None,
|
||||||
};
|
};
|
||||||
let fun = match def {
|
let fun = match def {
|
||||||
Definition::ModuleDef(hir::ModuleDef::Function(it)) => it,
|
Definition::ModuleDef(hir::ModuleDef::Function(it)) => it,
|
|
@ -1,10 +1,10 @@
|
||||||
use ra_syntax::ast::{self, AstNode};
|
use syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists};
|
use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
// Assist: apply_demorgan
|
// Assist: apply_demorgan
|
||||||
//
|
//
|
||||||
// Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
|
// Apply https://en.wikipedia.org/wiki/De_Morgan%27s_laws[De Morgan's law].
|
||||||
// This transforms expressions of the form `!l || !r` into `!(l && r)`.
|
// This transforms expressions of the form `!l || !r` into `!(l && r)`.
|
||||||
// This also works with `&&`. This assist can only be applied with the cursor
|
// This also works with `&&`. This assist can only be applied with the cursor
|
||||||
// on either `||` or `&&`, with both operands being a negation of some kind.
|
// on either `||` or `&&`, with both operands being a negation of some kind.
|
|
@ -5,13 +5,12 @@ use hir::{
|
||||||
AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait,
|
AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait,
|
||||||
Type,
|
Type,
|
||||||
};
|
};
|
||||||
use ra_ide_db::{imports_locator, RootDatabase};
|
use ide_db::{imports_locator, RootDatabase};
|
||||||
use ra_prof::profile;
|
use rustc_hash::FxHashSet;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
SyntaxNode,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::insert_use_statement, AssistContext, AssistId, AssistKind, Assists, GroupLabel,
|
utils::insert_use_statement, AssistContext, AssistId, AssistKind, Assists, GroupLabel,
|
||||||
|
@ -130,7 +129,7 @@ impl AutoImportAssets {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_for_imports(&self, ctx: &AssistContext) -> BTreeSet<ModPath> {
|
fn search_for_imports(&self, ctx: &AssistContext) -> BTreeSet<ModPath> {
|
||||||
let _p = profile("auto_import::search_for_imports");
|
let _p = profile::span("auto_import::search_for_imports");
|
||||||
let db = ctx.db();
|
let db = ctx.db();
|
||||||
let current_crate = self.module_with_name_to_import.krate();
|
let current_crate = self.module_with_name_to_import.krate();
|
||||||
imports_locator::find_imports(&ctx.sema, current_crate, &self.get_search_query())
|
imports_locator::find_imports(&ctx.sema, current_crate, &self.get_search_query())
|
|
@ -1,10 +1,12 @@
|
||||||
use ra_syntax::{
|
use std::iter;
|
||||||
ast::{self, BlockExpr, Expr, LoopBodyOwner},
|
|
||||||
|
use syntax::{
|
||||||
|
ast::{self, make, BlockExpr, Expr, LoopBodyOwner},
|
||||||
AstNode, SyntaxNode,
|
AstNode, SyntaxNode,
|
||||||
};
|
};
|
||||||
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
use test_utils::mark;
|
|
||||||
|
|
||||||
// Assist: change_return_type_to_result
|
// Assist: change_return_type_to_result
|
||||||
//
|
//
|
||||||
|
@ -44,7 +46,13 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
|
||||||
tail_return_expr_collector.collect_tail_exprs(block_expr);
|
tail_return_expr_collector.collect_tail_exprs(block_expr);
|
||||||
|
|
||||||
for ret_expr_arg in tail_return_expr_collector.exprs_to_wrap {
|
for ret_expr_arg in tail_return_expr_collector.exprs_to_wrap {
|
||||||
builder.replace_node_and_indent(&ret_expr_arg, format!("Ok({})", ret_expr_arg));
|
let ok_wrapped = make::expr_call(
|
||||||
|
make::expr_path(make::path_unqualified(make::path_segment(make::name_ref(
|
||||||
|
"Ok",
|
||||||
|
)))),
|
||||||
|
make::arg_list(iter::once(ret_expr_arg.clone())),
|
||||||
|
);
|
||||||
|
builder.replace_ast(ret_expr_arg, ok_wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
match ctx.config.snippet_cap {
|
match ctx.config.snippet_cap {
|
||||||
|
@ -60,7 +68,7 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TailReturnCollector {
|
struct TailReturnCollector {
|
||||||
exprs_to_wrap: Vec<SyntaxNode>,
|
exprs_to_wrap: Vec<ast::Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TailReturnCollector {
|
impl TailReturnCollector {
|
||||||
|
@ -86,7 +94,8 @@ impl TailReturnCollector {
|
||||||
if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
|
if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
|
||||||
for last_expr in last_exprs {
|
for last_expr in last_exprs {
|
||||||
let last_expr = match last_expr {
|
let last_expr = match last_expr {
|
||||||
NodeType::Node(expr) | NodeType::Leaf(expr) => expr,
|
NodeType::Node(expr) => expr,
|
||||||
|
NodeType::Leaf(expr) => expr.syntax().clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(last_expr) = Expr::cast(last_expr.clone()) {
|
if let Some(last_expr) = Expr::cast(last_expr.clone()) {
|
||||||
|
@ -113,12 +122,12 @@ impl TailReturnCollector {
|
||||||
}
|
}
|
||||||
Expr::ReturnExpr(ret_expr) => {
|
Expr::ReturnExpr(ret_expr) => {
|
||||||
if let Some(ret_expr_arg) = &ret_expr.expr() {
|
if let Some(ret_expr_arg) = &ret_expr.expr() {
|
||||||
self.exprs_to_wrap.push(ret_expr_arg.syntax().clone());
|
self.exprs_to_wrap.push(ret_expr_arg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::BreakExpr(break_expr) if collect_break => {
|
Expr::BreakExpr(break_expr) if collect_break => {
|
||||||
if let Some(break_expr_arg) = &break_expr.expr() {
|
if let Some(break_expr_arg) = &break_expr.expr() {
|
||||||
self.exprs_to_wrap.push(break_expr_arg.syntax().clone());
|
self.exprs_to_wrap.push(break_expr_arg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::IfExpr(if_expr) => {
|
Expr::IfExpr(if_expr) => {
|
||||||
|
@ -166,14 +175,11 @@ impl TailReturnCollector {
|
||||||
NodeType::Leaf(expr) => {
|
NodeType::Leaf(expr) => {
|
||||||
self.exprs_to_wrap.push(expr.clone());
|
self.exprs_to_wrap.push(expr.clone());
|
||||||
}
|
}
|
||||||
NodeType::Node(expr) => match &Expr::cast(expr.clone()) {
|
NodeType::Node(expr) => {
|
||||||
Some(last_expr) => {
|
if let Some(last_expr) = Expr::cast(expr.clone()) {
|
||||||
self.fetch_tail_exprs(last_expr);
|
self.fetch_tail_exprs(&last_expr);
|
||||||
}
|
}
|
||||||
None => {
|
}
|
||||||
self.exprs_to_wrap.push(expr.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +188,7 @@ impl TailReturnCollector {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum NodeType {
|
enum NodeType {
|
||||||
Leaf(SyntaxNode),
|
Leaf(ast::Expr),
|
||||||
Node(SyntaxNode),
|
Node(SyntaxNode),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,25 +239,26 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
|
||||||
|
|
||||||
Some(arms)
|
Some(arms)
|
||||||
}
|
}
|
||||||
Expr::BreakExpr(expr) => expr.expr().map(|e| vec![NodeType::Leaf(e.syntax().clone())]),
|
Expr::BreakExpr(expr) => expr.expr().map(|e| vec![NodeType::Leaf(e)]),
|
||||||
Expr::ReturnExpr(ret_expr) => Some(vec![NodeType::Node(ret_expr.syntax().clone())]),
|
Expr::ReturnExpr(ret_expr) => Some(vec![NodeType::Node(ret_expr.syntax().clone())]),
|
||||||
Expr::CallExpr(call_expr) => Some(vec![NodeType::Leaf(call_expr.syntax().clone())]),
|
|
||||||
Expr::Literal(lit_expr) => Some(vec![NodeType::Leaf(lit_expr.syntax().clone())]),
|
Expr::CallExpr(_)
|
||||||
Expr::TupleExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::Literal(_)
|
||||||
Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::TupleExpr(_)
|
||||||
Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::ArrayExpr(_)
|
||||||
Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::ParenExpr(_)
|
||||||
Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::PathExpr(_)
|
||||||
Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::RecordExpr(_)
|
||||||
Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::IndexExpr(_)
|
||||||
Expr::AwaitExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::MethodCallExpr(_)
|
||||||
Expr::CastExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::AwaitExpr(_)
|
||||||
Expr::RefExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::CastExpr(_)
|
||||||
Expr::PrefixExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::RefExpr(_)
|
||||||
Expr::RangeExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::PrefixExpr(_)
|
||||||
Expr::BinExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::RangeExpr(_)
|
||||||
Expr::MacroCall(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::BinExpr(_)
|
||||||
Expr::BoxExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
|
| Expr::MacroCall(_)
|
||||||
|
| Expr::BoxExpr(_) => Some(vec![NodeType::Leaf(expr.clone())]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, NameOwner, VisibilityOwner},
|
ast::{self, NameOwner, VisibilityOwner},
|
||||||
AstNode,
|
AstNode,
|
||||||
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
|
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{iter::once, ops::RangeInclusive};
|
use std::{iter::once, ops::RangeInclusive};
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::replace_children,
|
algo::replace_children,
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
|
@ -1,9 +1,9 @@
|
||||||
use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope};
|
use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope};
|
||||||
use ra_ide_db::{
|
use ide_db::{
|
||||||
defs::{classify_name_ref, Definition, NameRefClass},
|
defs::{classify_name_ref, Definition, NameRefClass},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T};
|
use syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::{AssistBuilder, AssistContext, Assists},
|
assist_context::{AssistBuilder, AssistContext, Assists},
|
|
@ -1,13 +1,12 @@
|
||||||
|
use base_db::FileId;
|
||||||
use hir::{EnumVariant, Module, ModuleDef, Name};
|
use hir::{EnumVariant, Module, ModuleDef, Name};
|
||||||
use ra_db::FileId;
|
use ide_db::{defs::Definition, search::Reference, RootDatabase};
|
||||||
use ra_fmt::leading_indent;
|
|
||||||
use ra_ide_db::{defs::Definition, search::Reference, RootDatabase};
|
|
||||||
use ra_syntax::{
|
|
||||||
algo::find_node_at_offset,
|
|
||||||
ast::{self, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
|
|
||||||
SourceFile, SyntaxNode, TextRange, TextSize,
|
|
||||||
};
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use syntax::{
|
||||||
|
algo::find_node_at_offset,
|
||||||
|
ast::{self, edit::IndentLevel, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
|
||||||
|
SourceFile, TextRange, TextSize,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::AssistBuilder, utils::insert_use_statement, AssistContext, AssistId,
|
assist_context::AssistBuilder, utils::insert_use_statement, AssistContext, AssistId,
|
||||||
|
@ -72,7 +71,7 @@ pub(crate) fn extract_struct_from_enum_variant(
|
||||||
}
|
}
|
||||||
extract_struct_def(
|
extract_struct_def(
|
||||||
builder,
|
builder,
|
||||||
enum_ast.syntax(),
|
&enum_ast,
|
||||||
&variant_name,
|
&variant_name,
|
||||||
&field_list.to_string(),
|
&field_list.to_string(),
|
||||||
start_offset,
|
start_offset,
|
||||||
|
@ -112,9 +111,10 @@ fn insert_import(
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this should use strongly-typed `make`, rather than string manipulation.
|
||||||
fn extract_struct_def(
|
fn extract_struct_def(
|
||||||
builder: &mut AssistBuilder,
|
builder: &mut AssistBuilder,
|
||||||
enum_ast: &SyntaxNode,
|
enum_: &ast::Enum,
|
||||||
variant_name: &str,
|
variant_name: &str,
|
||||||
variant_list: &str,
|
variant_list: &str,
|
||||||
start_offset: TextSize,
|
start_offset: TextSize,
|
||||||
|
@ -126,11 +126,7 @@ fn extract_struct_def(
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
let indent = if let Some(indent) = leading_indent(enum_ast) {
|
let indent = IndentLevel::from_node(enum_.syntax());
|
||||||
indent.to_string()
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
};
|
|
||||||
let struct_def = format!(
|
let struct_def = format!(
|
||||||
r#"{}struct {}{};
|
r#"{}struct {}{};
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use ra_syntax::{
|
use stdx::format_to;
|
||||||
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
SyntaxKind::{
|
SyntaxKind::{
|
||||||
BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
|
BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
|
||||||
},
|
},
|
||||||
SyntaxNode,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
use stdx::format_to;
|
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
|
@ -1,9 +1,9 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::{Adt, HasSource, ModuleDef, Semantics};
|
use hir::{Adt, HasSource, ModuleDef, Semantics};
|
||||||
|
use ide_db::RootDatabase;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ra_ide_db::RootDatabase;
|
use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
|
||||||
use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
|
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
|
@ -1,6 +1,6 @@
|
||||||
|
use base_db::FileId;
|
||||||
use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
|
use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
|
||||||
use ra_db::FileId;
|
use syntax::{ast, AstNode, TextRange, TextSize};
|
||||||
use ra_syntax::{ast, AstNode, TextRange, TextSize};
|
|
||||||
|
|
||||||
use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
|
use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
|
||||||
use ast::VisibilityOwner;
|
use ast::VisibilityOwner;
|
||||||
|
@ -121,7 +121,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) ->
|
||||||
Some(cap) => match current_visibility {
|
Some(cap) => match current_visibility {
|
||||||
Some(current_visibility) => builder.replace_snippet(
|
Some(current_visibility) => builder.replace_snippet(
|
||||||
cap,
|
cap,
|
||||||
dbg!(current_visibility.syntax()).text_range(),
|
current_visibility.syntax().text_range(),
|
||||||
format!("$0{}", missing_visibility),
|
format!("$0{}", missing_visibility),
|
||||||
),
|
),
|
||||||
None => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),
|
None => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::ast::{AstNode, BinExpr, BinOp};
|
use syntax::ast::{AstNode, BinExpr, BinOp};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{algo::non_trivia_sibling, Direction, T};
|
use syntax::{algo::non_trivia_sibling, Direction, T};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::non_trivia_sibling,
|
algo::non_trivia_sibling,
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
Direction, T,
|
Direction, T,
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AttrsOwner},
|
ast::{self, AstNode, AttrsOwner},
|
||||||
SyntaxKind::{COMMENT, WHITESPACE},
|
SyntaxKind::{COMMENT, WHITESPACE},
|
||||||
TextSize,
|
TextSize,
|
|
@ -1,5 +1,5 @@
|
||||||
use ra_ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use ra_syntax::ast::{self, AstNode, NameOwner};
|
use syntax::ast::{self, AstNode, NameOwner};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{utils::FamousDefs, AssistContext, AssistId, AssistKind, Assists};
|
use crate::{utils::FamousDefs, AssistContext, AssistId, AssistKind, Assists};
|
|
@ -1,6 +1,7 @@
|
||||||
|
use base_db::FileId;
|
||||||
use hir::HirDisplay;
|
use hir::HirDisplay;
|
||||||
use ra_db::FileId;
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
||||||
|
@ -8,7 +9,6 @@ use ra_syntax::{
|
||||||
},
|
},
|
||||||
SyntaxKind, SyntaxNode, TextSize,
|
SyntaxKind, SyntaxNode, TextSize,
|
||||||
};
|
};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_config::SnippetCap,
|
assist_config::SnippetCap,
|
|
@ -1,5 +1,6 @@
|
||||||
use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
|
use itertools::Itertools;
|
||||||
use stdx::{format_to, SepBy};
|
use stdx::format_to;
|
||||||
|
use syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()
|
||||||
.filter_map(|it| it.name())
|
.filter_map(|it| it.name())
|
||||||
.map(|it| it.text().clone());
|
.map(|it| it.text().clone());
|
||||||
|
|
||||||
let generic_params = lifetime_params.chain(type_params).sep_by(", ");
|
let generic_params = lifetime_params.chain(type_params).format(", ");
|
||||||
format_to!(buf, "<{}>", generic_params)
|
format_to!(buf, "<{}>", generic_params)
|
||||||
}
|
}
|
||||||
match ctx.config.snippet_cap {
|
match ctx.config.snippet_cap {
|
|
@ -1,9 +1,10 @@
|
||||||
use hir::Adt;
|
use hir::Adt;
|
||||||
use ra_syntax::{
|
use itertools::Itertools;
|
||||||
|
use stdx::format_to;
|
||||||
|
use syntax::{
|
||||||
ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
|
ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
|
||||||
T,
|
T,
|
||||||
};
|
};
|
||||||
use stdx::{format_to, SepBy};
|
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
|
@ -52,8 +53,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
||||||
let params = field_list
|
let params = field_list
|
||||||
.fields()
|
.fields()
|
||||||
.filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
|
.filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
|
||||||
.sep_by(", ");
|
.format(", ");
|
||||||
let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", ");
|
let fields = field_list.fields().filter_map(|f| f.name()).format(", ");
|
||||||
|
|
||||||
format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields);
|
format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields);
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String {
|
||||||
.map(|it| it.text().clone());
|
.map(|it| it.text().clone());
|
||||||
let type_params =
|
let type_params =
|
||||||
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());
|
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());
|
||||||
format_to!(buf, "<{}>", lifetime_params.chain(type_params).sep_by(", "))
|
format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
format_to!(buf, " {{\n{}\n}}\n", code);
|
format_to!(buf, " {{\n{}\n}}\n", code);
|
|
@ -1,5 +1,5 @@
|
||||||
use ra_ide_db::defs::Definition;
|
use ide_db::defs::Definition;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AstToken},
|
ast::{self, AstNode, AstToken},
|
||||||
TextRange,
|
TextRange,
|
||||||
};
|
};
|
|
@ -1,8 +1,8 @@
|
||||||
use ra_syntax::{
|
use rustc_hash::FxHashSet;
|
||||||
|
use syntax::{
|
||||||
ast::{self, GenericParamsOwner, NameOwner},
|
ast::{self, GenericParamsOwner, NameOwner},
|
||||||
AstNode, SyntaxKind, TextRange, TextSize,
|
AstNode, SyntaxKind, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
|
|
||||||
use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, Assists};
|
use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
T,
|
T,
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter::successors;
|
use std::iter::successors;
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::{neighbor, skip_trivia_token, SyntaxRewriter},
|
algo::{neighbor, skip_trivia_token, SyntaxRewriter},
|
||||||
ast::{self, edit::AstNodeEdit, make},
|
ast::{self, edit::AstNodeEdit, make},
|
||||||
AstNode, Direction, InsertPosition, SyntaxElement, T,
|
AstNode, Direction, InsertPosition, SyntaxElement, T,
|
||||||
|
@ -164,6 +164,33 @@ use std::fmt::{Display, Debug};
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_self1() {
|
||||||
|
check_assist(
|
||||||
|
merge_imports,
|
||||||
|
r"
|
||||||
|
use std::fmt<|>;
|
||||||
|
use std::fmt::Display;
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use std::fmt::{self, Display};
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_self2() {
|
||||||
|
check_assist(
|
||||||
|
merge_imports,
|
||||||
|
r"
|
||||||
|
use std::{fmt, <|>fmt::Display};
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use std::{fmt::{Display, self}};
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_merge_nested() {
|
fn test_merge_nested() {
|
||||||
check_assist(
|
check_assist(
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter::successors;
|
use std::iter::successors;
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
algo::neighbor,
|
algo::neighbor,
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
Direction,
|
Direction,
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
|
ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
|
||||||
match_ast,
|
match_ast,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
|
@ -1,5 +1,5 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{AstNode, IfExpr, MatchArm},
|
ast::{edit::AstNodeEdit, make, AstNode, IfExpr, MatchArm},
|
||||||
SyntaxKind::WHITESPACE,
|
SyntaxKind::WHITESPACE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,9 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
//
|
//
|
||||||
// fn handle(action: Action) {
|
// fn handle(action: Action) {
|
||||||
// match action {
|
// match action {
|
||||||
// Action::Move { distance } => if distance > 10 { foo() },
|
// Action::Move { distance } => if distance > 10 {
|
||||||
|
// foo()
|
||||||
|
// },
|
||||||
// _ => (),
|
// _ => (),
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -35,9 +37,13 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
|
||||||
let guard = match_arm.guard()?;
|
let guard = match_arm.guard()?;
|
||||||
let space_before_guard = guard.syntax().prev_sibling_or_token();
|
let space_before_guard = guard.syntax().prev_sibling_or_token();
|
||||||
|
|
||||||
let guard_conditions = guard.expr()?;
|
let guard_condition = guard.expr()?;
|
||||||
let arm_expr = match_arm.expr()?;
|
let arm_expr = match_arm.expr()?;
|
||||||
let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text());
|
let if_expr = make::expr_if(
|
||||||
|
make::condition(guard_condition, None),
|
||||||
|
make::block_expr(None, Some(arm_expr.clone())),
|
||||||
|
)
|
||||||
|
.indent(arm_expr.indent_level());
|
||||||
|
|
||||||
let target = guard.syntax().text_range();
|
let target = guard.syntax().text_range();
|
||||||
acc.add(
|
acc.add(
|
||||||
|
@ -53,7 +59,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
|
||||||
};
|
};
|
||||||
|
|
||||||
edit.delete(guard.syntax().text_range());
|
edit.delete(guard.syntax().text_range());
|
||||||
edit.replace_node_and_indent(arm_expr.syntax(), buf);
|
edit.replace_ast(arm_expr, if_expr);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -134,16 +140,14 @@ mod tests {
|
||||||
check_assist_target(
|
check_assist_target(
|
||||||
move_guard_to_arm_body,
|
move_guard_to_arm_body,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x <|>if x > 10 => false,
|
||||||
match t {
|
_ => true
|
||||||
'\r' <|>if chars.clone().next() == Some('\n') => false,
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
r#"if x > 10"#,
|
||||||
"#,
|
|
||||||
r#"if chars.clone().next() == Some('\n')"#,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,25 +156,23 @@ mod tests {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_guard_to_arm_body,
|
move_guard_to_arm_body,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x <|>if x > 10 => false,
|
||||||
match t {
|
_ => true
|
||||||
'\r' <|>if chars.clone().next() == Some('\n') => false,
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x => if x > 10 {
|
||||||
match t {
|
false
|
||||||
'\r' => if chars.clone().next() == Some('\n') { false },
|
},
|
||||||
_ => true
|
_ => true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,21 +181,23 @@ mod tests {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_guard_to_arm_body,
|
move_guard_to_arm_body,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
match x {
|
match 92 {
|
||||||
<|>y @ 4 | y @ 5 if y > 5 => true,
|
<|>x @ 4 | x @ 5 if x > 5 => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
match x {
|
match 92 {
|
||||||
y @ 4 | y @ 5 => if y > 5 { true },
|
x @ 4 | x @ 5 => if x > 5 {
|
||||||
_ => false
|
true
|
||||||
}
|
},
|
||||||
}
|
_ => false
|
||||||
"#,
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,25 +206,21 @@ mod tests {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_arm_cond_to_match_guard,
|
move_arm_cond_to_match_guard,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x => if x > 10 { <|>false },
|
||||||
match t {
|
_ => true
|
||||||
'\r' => if chars.clone().next() == Some('\n') { <|>false },
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x if x > 10 => false,
|
||||||
match t {
|
_ => true
|
||||||
'\r' if chars.clone().next() == Some('\n') => false,
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,15 +229,13 @@ mod tests {
|
||||||
check_assist_not_applicable(
|
check_assist_not_applicable(
|
||||||
move_arm_cond_to_match_guard,
|
move_arm_cond_to_match_guard,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x => if let 62 = x { <|>false },
|
||||||
match t {
|
_ => true
|
||||||
'\r' => if let Some(_) = chars.clone().next() { <|>false },
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,25 +244,21 @@ mod tests {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_arm_cond_to_match_guard,
|
move_arm_cond_to_match_guard,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x => if x > 10 { <|> },
|
||||||
match t {
|
_ => true
|
||||||
'\r' => if chars.clone().next().is_some() { <|> },
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x if x > 10 => { },
|
||||||
match t {
|
_ => true
|
||||||
'\r' if chars.clone().next().is_some() => { },
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,31 +267,27 @@ mod tests {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_arm_cond_to_match_guard,
|
move_arm_cond_to_match_guard,
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let mut t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x => if x > 10 {
|
||||||
match t {
|
92;<|>
|
||||||
'\r' => if chars.clone().next().is_some() {
|
false
|
||||||
t = 'e';<|>
|
},
|
||||||
false
|
_ => true
|
||||||
},
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn main() {
|
||||||
let mut t = 'a';
|
match 92 {
|
||||||
let chars = "abcd";
|
x if x > 10 => {
|
||||||
match t {
|
92;
|
||||||
'\r' if chars.clone().next().is_some() => {
|
false
|
||||||
t = 'e';
|
},
|
||||||
false
|
_ => true
|
||||||
},
|
}
|
||||||
_ => true
|
}
|
||||||
}
|
"#,
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, HasQuotes, HasStringValue},
|
ast::{self, HasQuotes, HasStringValue},
|
||||||
AstToken,
|
AstToken,
|
||||||
SyntaxKind::{RAW_STRING, STRING},
|
SyntaxKind::{RAW_STRING, STRING},
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
TextRange, TextSize, T,
|
TextRange, TextSize, T,
|
||||||
};
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{SyntaxKind, TextRange, T};
|
use syntax::{SyntaxKind, TextRange, T};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -2,8 +2,8 @@ use itertools::Itertools;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct};
|
use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct};
|
||||||
use ra_ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
|
use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use ra_fmt::unwrap_trivial_block;
|
use syntax::{
|
||||||
use ra_syntax::{
|
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
||||||
|
@ -8,7 +7,10 @@ use ra_syntax::{
|
||||||
AstNode,
|
AstNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{utils::TryEnum, AssistContext, AssistId, AssistKind, Assists};
|
use crate::{
|
||||||
|
utils::{unwrap_trivial_block, TryEnum},
|
||||||
|
AssistContext, AssistId, AssistKind, Assists,
|
||||||
|
};
|
||||||
|
|
||||||
// Assist: replace_if_let_with_match
|
// Assist: replace_if_let_with_match
|
||||||
//
|
//
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
|
@ -1,5 +1,5 @@
|
||||||
use hir;
|
use hir;
|
||||||
use ra_syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SmolStr, SyntaxNode};
|
use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SmolStr, SyntaxNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::{find_insert_use_container, insert_use_statement},
|
utils::{find_insert_use_container, insert_use_statement},
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
|
@ -1,6 +1,6 @@
|
||||||
use std::iter::successors;
|
use std::iter::successors;
|
||||||
|
|
||||||
use ra_syntax::{ast, AstNode, T};
|
use syntax::{ast, AstNode, T};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use ra_fmt::unwrap_trivial_block;
|
use syntax::{
|
||||||
use ra_syntax::{
|
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
||||||
|
@ -7,7 +6,7 @@ use ra_syntax::{
|
||||||
AstNode, TextRange, T,
|
AstNode, TextRange, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
// Assist: unwrap_block
|
// Assist: unwrap_block
|
||||||
//
|
//
|
|
@ -1,4 +1,4 @@
|
||||||
//! `ra_assists` crate provides a bunch of code assists, also known as code
|
//! `assists` crate provides a bunch of code assists, also known as code
|
||||||
//! actions (in LSP) or intentions (in IntelliJ).
|
//! actions (in LSP) or intentions (in IntelliJ).
|
||||||
//!
|
//!
|
||||||
//! An assist is a micro-refactoring, which is automatically activated in
|
//! An assist is a micro-refactoring, which is automatically activated in
|
||||||
|
@ -17,10 +17,10 @@ mod tests;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod ast_transform;
|
pub mod ast_transform;
|
||||||
|
|
||||||
|
use base_db::FileRange;
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ra_db::FileRange;
|
use ide_db::{source_change::SourceChange, RootDatabase};
|
||||||
use ra_ide_db::{source_change::SourceChange, RootDatabase};
|
use syntax::TextRange;
|
||||||
use ra_syntax::TextRange;
|
|
||||||
|
|
||||||
pub(crate) use crate::assist_context::{AssistContext, Assists};
|
pub(crate) use crate::assist_context::{AssistContext, Assists};
|
||||||
|
|
||||||
|
@ -66,13 +66,13 @@ pub struct GroupLabel(pub String);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Assist {
|
pub struct Assist {
|
||||||
pub id: AssistId,
|
id: AssistId,
|
||||||
/// Short description of the assist, as shown in the UI.
|
/// Short description of the assist, as shown in the UI.
|
||||||
pub label: String,
|
label: String,
|
||||||
pub group: Option<GroupLabel>,
|
group: Option<GroupLabel>,
|
||||||
/// Target ranges are used to sort assists: the smaller the target range,
|
/// Target ranges are used to sort assists: the smaller the target range,
|
||||||
/// the more specific assist is, and so it should be sorted first.
|
/// the more specific assist is, and so it should be sorted first.
|
||||||
pub target: TextRange,
|
target: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -120,10 +120,25 @@ impl Assist {
|
||||||
group: Option<GroupLabel>,
|
group: Option<GroupLabel>,
|
||||||
target: TextRange,
|
target: TextRange,
|
||||||
) -> Assist {
|
) -> Assist {
|
||||||
// FIXME: make fields private, so that this invariant can't be broken
|
|
||||||
assert!(label.starts_with(|c: char| c.is_uppercase()));
|
assert!(label.starts_with(|c: char| c.is_uppercase()));
|
||||||
Assist { id, label, group, target }
|
Assist { id, label, group, target }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> AssistId {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn label(&self) -> String {
|
||||||
|
self.label.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn group(&self) -> Option<GroupLabel> {
|
||||||
|
self.group.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn target(&self) -> TextRange {
|
||||||
|
self.target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod handlers {
|
mod handlers {
|
|
@ -1,9 +1,9 @@
|
||||||
mod generated;
|
mod generated;
|
||||||
|
|
||||||
|
use base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
|
use ide_db::RootDatabase;
|
||||||
use ra_ide_db::RootDatabase;
|
use syntax::TextRange;
|
||||||
use ra_syntax::TextRange;
|
|
||||||
use test_utils::{assert_eq_text, extract_offset, extract_range};
|
use test_utils::{assert_eq_text, extract_offset, extract_range};
|
||||||
|
|
||||||
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
|
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
|
||||||
|
@ -20,7 +20,7 @@ pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_
|
||||||
|
|
||||||
// FIXME: instead of having a separate function here, maybe use
|
// FIXME: instead of having a separate function here, maybe use
|
||||||
// `extract_ranges` and mark the target as `<target> </target>` in the
|
// `extract_ranges` and mark the target as `<target> </target>` in the
|
||||||
// fixuture?
|
// fixture?
|
||||||
pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) {
|
pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) {
|
||||||
check(assist, ra_fixture, ExpectedResult::Target(target));
|
check(assist, ra_fixture, ExpectedResult::Target(target));
|
||||||
}
|
}
|
|
@ -690,7 +690,9 @@ enum Action { Move { distance: u32 }, Stop }
|
||||||
|
|
||||||
fn handle(action: Action) {
|
fn handle(action: Action) {
|
||||||
match action {
|
match action {
|
||||||
Action::Move { distance } => if distance > 10 { foo() },
|
Action::Move { distance } => if distance > 10 {
|
||||||
|
foo()
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,19 +4,57 @@ pub(crate) mod insert_use;
|
||||||
use std::{iter, ops};
|
use std::{iter, ops};
|
||||||
|
|
||||||
use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
|
use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
|
||||||
use ra_ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use ra_syntax::{
|
use itertools::Itertools;
|
||||||
|
use rustc_hash::FxHashSet;
|
||||||
|
use syntax::{
|
||||||
ast::{self, make, NameOwner},
|
ast::{self, make, NameOwner},
|
||||||
AstNode,
|
AstNode,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
SyntaxNode, TextSize, T,
|
SyntaxNode, TextSize, T,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
|
|
||||||
use crate::assist_config::SnippetCap;
|
use crate::assist_config::SnippetCap;
|
||||||
|
|
||||||
pub(crate) use insert_use::{find_insert_use_container, insert_use_statement};
|
pub(crate) use insert_use::{find_insert_use_container, insert_use_statement};
|
||||||
|
|
||||||
|
pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
|
||||||
|
extract_trivial_expression(&block)
|
||||||
|
.filter(|expr| !expr.syntax().text().contains_char('\n'))
|
||||||
|
.unwrap_or_else(|| block.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
|
||||||
|
let has_anything_else = |thing: &SyntaxNode| -> bool {
|
||||||
|
let mut non_trivial_children =
|
||||||
|
block.syntax().children_with_tokens().filter(|it| match it.kind() {
|
||||||
|
WHITESPACE | T!['{'] | T!['}'] => false,
|
||||||
|
_ => it.as_node() != Some(thing),
|
||||||
|
});
|
||||||
|
non_trivial_children.next().is_some()
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(expr) = block.expr() {
|
||||||
|
if has_anything_else(expr.syntax()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
return Some(expr);
|
||||||
|
}
|
||||||
|
// Unwrap `{ continue; }`
|
||||||
|
let (stmt,) = block.statements().next_tuple()?;
|
||||||
|
if let ast::Stmt::ExprStmt(expr_stmt) = stmt {
|
||||||
|
if has_anything_else(expr_stmt.syntax()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let expr = expr_stmt.expr()?;
|
||||||
|
match expr.syntax().kind() {
|
||||||
|
CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub(crate) enum Cursor<'a> {
|
pub(crate) enum Cursor<'a> {
|
||||||
Replace(&'a SyntaxNode),
|
Replace(&'a SyntaxNode),
|
||||||
|
@ -257,7 +295,7 @@ pub use prelude::*;
|
||||||
.find(|dep| &dep.name.to_string() == std_crate)?
|
.find(|dep| &dep.name.to_string() == std_crate)?
|
||||||
.krate;
|
.krate;
|
||||||
|
|
||||||
let mut module = std_crate.root_module(db)?;
|
let mut module = std_crate.root_module(db);
|
||||||
for segment in path {
|
for segment in path {
|
||||||
module = module.children(db).find_map(|child| {
|
module = module.children(db).find_map(|child| {
|
||||||
let name = child.name(db)?;
|
let name = child.name(db)?;
|
|
@ -2,17 +2,19 @@
|
||||||
// FIXME: rewrite according to the plan, outlined in
|
// FIXME: rewrite according to the plan, outlined in
|
||||||
// https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553
|
// https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553
|
||||||
|
|
||||||
|
use std::iter::successors;
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir::{self, ModPath};
|
use hir::{self, ModPath};
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, NameOwner, VisibilityOwner},
|
ast::{self, NameOwner, VisibilityOwner},
|
||||||
AstNode, Direction, SmolStr,
|
AstNode, AstToken, Direction, SmolStr,
|
||||||
SyntaxKind::{PATH, PATH_SEGMENT},
|
SyntaxKind::{PATH, PATH_SEGMENT},
|
||||||
SyntaxNode, T,
|
SyntaxNode, SyntaxToken, T,
|
||||||
};
|
};
|
||||||
use ra_text_edit::TextEditBuilder;
|
use text_edit::TextEditBuilder;
|
||||||
|
|
||||||
use crate::assist_context::AssistContext;
|
use crate::assist_context::AssistContext;
|
||||||
use either::Either;
|
|
||||||
|
|
||||||
/// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
|
/// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
|
||||||
pub(crate) fn find_insert_use_container(
|
pub(crate) fn find_insert_use_container(
|
||||||
|
@ -442,7 +444,7 @@ fn make_assist_add_new_use(
|
||||||
edit: &mut TextEditBuilder,
|
edit: &mut TextEditBuilder,
|
||||||
) {
|
) {
|
||||||
if let Some(anchor) = anchor {
|
if let Some(anchor) = anchor {
|
||||||
let indent = ra_fmt::leading_indent(anchor);
|
let indent = leading_indent(anchor);
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if after {
|
if after {
|
||||||
buf.push_str("\n");
|
buf.push_str("\n");
|
||||||
|
@ -524,3 +526,22 @@ fn make_assist_add_nested_import(
|
||||||
edit.insert(end, "}".to_string());
|
edit.insert(end, "}".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If the node is on the beginning of the line, calculate indent.
|
||||||
|
fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
|
||||||
|
for token in prev_tokens(node.first_token()?) {
|
||||||
|
if let Some(ws) = ast::Whitespace::cast(token.clone()) {
|
||||||
|
let ws_text = ws.text();
|
||||||
|
if let Some(pos) = ws_text.rfind('\n') {
|
||||||
|
return Some(ws_text[pos + 1..].into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if token.text().contains('\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
|
||||||
|
successors(token.prev_token(), |token| token.prev_token())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
name = "base_db"
|
||||||
name = "ra_db"
|
version = "0.0.0"
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["rust-analyzer developers"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -12,10 +12,10 @@ doctest = false
|
||||||
salsa = "0.15.2"
|
salsa = "0.15.2"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
syntax = { path = "../syntax" }
|
||||||
ra_cfg = { path = "../ra_cfg" }
|
cfg = { path = "../cfg" }
|
||||||
ra_prof = { path = "../ra_prof" }
|
profile = { path = "../profile" }
|
||||||
ra_tt = { path = "../ra_tt" }
|
tt = { path = "../tt" }
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
vfs = { path = "../vfs" }
|
vfs = { path = "../vfs" }
|
||||||
stdx = { path = "../stdx" }
|
stdx = { path = "../stdx" }
|
|
@ -59,7 +59,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
use std::{str::FromStr, sync::Arc};
|
use std::{str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use ra_cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER};
|
use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER};
|
||||||
use vfs::{file_set::FileSet, VfsPath};
|
use vfs::{file_set::FileSet, VfsPath};
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
|
use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use ra_cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use ra_syntax::SmolStr;
|
|
||||||
use ra_tt::TokenExpander;
|
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use syntax::SmolStr;
|
||||||
|
use tt::TokenExpander;
|
||||||
use vfs::file_set::FileSet;
|
use vfs::file_set::FileSet;
|
||||||
|
|
||||||
pub use vfs::FileId;
|
pub use vfs::FileId;
|
||||||
|
@ -156,7 +156,7 @@ impl CrateGraph {
|
||||||
display_name: Option<String>,
|
display_name: Option<String>,
|
||||||
cfg_options: CfgOptions,
|
cfg_options: CfgOptions,
|
||||||
env: Env,
|
env: Env,
|
||||||
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
|
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
|
||||||
) -> CrateId {
|
) -> CrateId {
|
||||||
let proc_macro =
|
let proc_macro =
|
||||||
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
|
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
|
|
@ -1,13 +1,12 @@
|
||||||
//! ra_db defines basic database traits. The concrete DB is defined by ra_ide.
|
//! base_db defines basic database traits. The concrete DB is defined by ide.
|
||||||
mod cancellation;
|
mod cancellation;
|
||||||
mod input;
|
mod input;
|
||||||
pub mod fixture;
|
pub mod fixture;
|
||||||
|
|
||||||
use std::{panic, sync::Arc};
|
use std::{panic, sync::Arc};
|
||||||
|
|
||||||
use ra_prof::profile;
|
|
||||||
use ra_syntax::{ast, Parse, SourceFile, TextRange, TextSize};
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
cancellation::Canceled,
|
cancellation::Canceled,
|
||||||
|
@ -113,7 +112,7 @@ pub trait SourceDatabase: CheckCanceled + FileLoader + std::fmt::Debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
|
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
|
||||||
let _p = profile("parse_query").detail(|| format!("{:?}", file_id));
|
let _p = profile::span("parse_query").detail(|| format!("{:?}", file_id));
|
||||||
let text = db.file_text(file_id);
|
let text = db.file_text(file_id);
|
||||||
SourceFile::parse(&*text)
|
SourceFile::parse(&*text)
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
name = "cfg"
|
||||||
name = "ra_cfg"
|
version = "0.0.0"
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["rust-analyzer developers"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -11,8 +11,8 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
tt = { path = "../tt" }
|
||||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
mbe = { path = "../mbe" }
|
||||||
|
syntax = { path = "../syntax" }
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use std::slice::Iter as SliceIter;
|
use std::slice::Iter as SliceIter;
|
||||||
|
|
||||||
use ra_syntax::SmolStr;
|
use tt::SmolStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum CfgExpr {
|
pub enum CfgExpr {
|
||||||
|
@ -86,17 +86,15 @@ fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use mbe::{ast_to_token_tree, TokenMap};
|
use mbe::ast_to_token_tree;
|
||||||
use ra_syntax::ast::{self, AstNode};
|
use syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
fn get_token_tree_generated(input: &str) -> (tt::Subtree, TokenMap) {
|
|
||||||
let source_file = ast::SourceFile::parse(input).ok().unwrap();
|
|
||||||
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
|
|
||||||
ast_to_token_tree(&tt).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_parse_result(input: &str, expected: CfgExpr) {
|
fn assert_parse_result(input: &str, expected: CfgExpr) {
|
||||||
let (tt, _) = get_token_tree_generated(input);
|
let (tt, _) = {
|
||||||
|
let source_file = ast::SourceFile::parse(input).ok().unwrap();
|
||||||
|
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
|
||||||
|
ast_to_token_tree(&tt).unwrap()
|
||||||
|
};
|
||||||
let cfg = CfgExpr::parse(&tt);
|
let cfg = CfgExpr::parse(&tt);
|
||||||
assert_eq!(cfg, expected);
|
assert_eq!(cfg, expected);
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
//! ra_cfg defines conditional compiling options, `cfg` attibute parser and evaluator
|
//! cfg defines conditional compiling options, `cfg` attibute parser and evaluator
|
||||||
|
|
||||||
mod cfg_expr;
|
mod cfg_expr;
|
||||||
|
|
||||||
use ra_syntax::SmolStr;
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use tt::SmolStr;
|
||||||
|
|
||||||
pub use cfg_expr::CfgExpr;
|
pub use cfg_expr::CfgExpr;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "expect"
|
name = "expect"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
authors = ["rust-analyzer developers"]
|
authors = ["rust-analyzer developers"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -11,4 +11,5 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
difference = "2"
|
difference = "2"
|
||||||
|
|
||||||
stdx = { path = "../stdx" }
|
stdx = { path = "../stdx" }
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl fmt::Display for Position {
|
||||||
impl Expect {
|
impl Expect {
|
||||||
pub fn assert_eq(&self, actual: &str) {
|
pub fn assert_eq(&self, actual: &str) {
|
||||||
let trimmed = self.trimmed();
|
let trimmed = self.trimmed();
|
||||||
if &trimmed == actual {
|
if trimmed == actual {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Runtime::fail_expect(self, &trimmed, actual);
|
Runtime::fail_expect(self, &trimmed, actual);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
|
||||||
name = "flycheck"
|
name = "flycheck"
|
||||||
version = "0.1.0"
|
version = "0.0.0"
|
||||||
authors = ["rust-analyzer developers"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -14,4 +14,5 @@ log = "0.4.8"
|
||||||
cargo_metadata = "0.11.1"
|
cargo_metadata = "0.11.1"
|
||||||
serde_json = "1.0.48"
|
serde_json = "1.0.48"
|
||||||
jod-thread = "0.1.1"
|
jod-thread = "0.1.1"
|
||||||
ra_toolchain = { path = "../ra_toolchain" }
|
|
||||||
|
toolchain = { path = "../toolchain" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! cargo_check provides the functionality needed to run `cargo check` or
|
//! Flycheck provides the functionality needed to run `cargo check` or
|
||||||
//! another compatible command (f.x. clippy) in a background thread and provide
|
//! another compatible command (f.x. clippy) in a background thread and provide
|
||||||
//! LSP diagnostics based on the output of the command.
|
//! LSP diagnostics based on the output of the command.
|
||||||
|
|
||||||
|
@ -147,6 +147,12 @@ impl FlycheckActor {
|
||||||
// avoid busy-waiting.
|
// avoid busy-waiting.
|
||||||
let cargo_handle = self.cargo_handle.take().unwrap();
|
let cargo_handle = self.cargo_handle.take().unwrap();
|
||||||
let res = cargo_handle.join();
|
let res = cargo_handle.join();
|
||||||
|
if res.is_err() {
|
||||||
|
log::error!(
|
||||||
|
"Flycheck failed to run the following command: {:?}",
|
||||||
|
self.check_command()
|
||||||
|
)
|
||||||
|
}
|
||||||
self.send(Message::Progress(Progress::DidFinish(res)));
|
self.send(Message::Progress(Progress::DidFinish(res)));
|
||||||
}
|
}
|
||||||
Event::CheckEvent(Some(message)) => match message {
|
Event::CheckEvent(Some(message)) => match message {
|
||||||
|
@ -187,7 +193,7 @@ impl FlycheckActor {
|
||||||
extra_args,
|
extra_args,
|
||||||
features,
|
features,
|
||||||
} => {
|
} => {
|
||||||
let mut cmd = Command::new(ra_toolchain::cargo());
|
let mut cmd = Command::new(toolchain::cargo());
|
||||||
cmd.arg(command);
|
cmd.arg(command);
|
||||||
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
|
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
|
||||||
.arg(self.workspace_root.join("Cargo.toml"));
|
.arg(self.workspace_root.join("Cargo.toml"));
|
||||||
|
@ -253,7 +259,7 @@ impl CargoHandle {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
format!(
|
format!(
|
||||||
"Cargo watcher failed,the command produced no valid metadata (exit code: {:?})",
|
"Cargo watcher failed, the command produced no valid metadata (exit code: {:?})",
|
||||||
exit_status
|
exit_status
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
24
crates/hir/Cargo.toml
Normal file
24
crates/hir/Cargo.toml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[package]
|
||||||
|
name = "hir"
|
||||||
|
version = "0.0.0"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
doctest = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4.8"
|
||||||
|
rustc-hash = "1.1.0"
|
||||||
|
either = "1.5.3"
|
||||||
|
arrayvec = "0.5.1"
|
||||||
|
itertools = "0.9.0"
|
||||||
|
|
||||||
|
stdx = { path = "../stdx" }
|
||||||
|
syntax = { path = "../syntax" }
|
||||||
|
base_db = { path = "../base_db" }
|
||||||
|
profile = { path = "../profile" }
|
||||||
|
hir_expand = { path = "../hir_expand" }
|
||||||
|
hir_def = { path = "../hir_def" }
|
||||||
|
hir_ty = { path = "../hir_ty" }
|
|
@ -2,8 +2,10 @@
|
||||||
use std::{iter, sync::Arc};
|
use std::{iter, sync::Arc};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
use base_db::{CrateId, Edition, FileId};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
adt::ReprKind,
|
||||||
adt::StructKind,
|
adt::StructKind,
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
@ -29,14 +31,12 @@ use hir_ty::{
|
||||||
method_resolution, ApplicationTy, CallableDefId, Canonical, FnSig, GenericPredicate,
|
method_resolution, ApplicationTy, CallableDefId, Canonical, FnSig, GenericPredicate,
|
||||||
InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor,
|
InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor,
|
||||||
};
|
};
|
||||||
use ra_db::{CrateId, Edition, FileId};
|
use rustc_hash::FxHashSet;
|
||||||
use ra_prof::profile;
|
use stdx::impl_from;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AttrsOwner, NameOwner},
|
ast::{self, AttrsOwner, NameOwner},
|
||||||
AstNode,
|
AstNode,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
use stdx::impl_from;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
|
@ -83,9 +83,9 @@ impl Crate {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_module(self, db: &dyn HirDatabase) -> Option<Module> {
|
pub fn root_module(self, db: &dyn HirDatabase) -> Module {
|
||||||
let module_id = db.crate_def_map(self.id).root;
|
let module_id = db.crate_def_map(self.id).root;
|
||||||
Some(Module::new(self, module_id))
|
Module::new(self, module_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_file(self, db: &dyn HirDatabase) -> FileId {
|
pub fn root_file(self, db: &dyn HirDatabase) -> FileId {
|
||||||
|
@ -303,7 +303,7 @@ impl Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
||||||
let _p = profile("Module::diagnostics");
|
let _p = profile::span("Module::diagnostics");
|
||||||
let crate_def_map = db.crate_def_map(self.id.krate);
|
let crate_def_map = db.crate_def_map(self.id.krate);
|
||||||
crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink);
|
crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink);
|
||||||
for decl in self.declarations(db) {
|
for decl in self.declarations(db) {
|
||||||
|
@ -431,6 +431,10 @@ impl Struct {
|
||||||
Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id)
|
Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
|
||||||
|
db.struct_data(self.id).repr.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
|
fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
|
||||||
db.struct_data(self.id).variant_data.clone()
|
db.struct_data(self.id).variant_data.clone()
|
||||||
}
|
}
|
||||||
|
@ -811,7 +815,7 @@ pub struct MacroDef {
|
||||||
impl MacroDef {
|
impl MacroDef {
|
||||||
/// FIXME: right now, this just returns the root module of the crate that
|
/// FIXME: right now, this just returns the root module of the crate that
|
||||||
/// defines this macro. The reasons for this is that macros are expanded
|
/// defines this macro. The reasons for this is that macros are expanded
|
||||||
/// early, in `ra_hir_expand`, where modules simply do not exist yet.
|
/// early, in `hir_expand`, where modules simply do not exist yet.
|
||||||
pub fn module(self, db: &dyn HirDatabase) -> Option<Module> {
|
pub fn module(self, db: &dyn HirDatabase) -> Option<Module> {
|
||||||
let krate = self.id.krate?;
|
let krate = self.id.krate?;
|
||||||
let module_id = db.crate_def_map(krate).root;
|
let module_id = db.crate_def_map(krate).root;
|
||||||
|
@ -879,6 +883,13 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssocItem {
|
impl AssocItem {
|
||||||
|
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||||
|
match self {
|
||||||
|
AssocItem::Function(it) => Some(it.name(db)),
|
||||||
|
AssocItem::Const(it) => it.name(db),
|
||||||
|
AssocItem::TypeAlias(it) => Some(it.name(db)),
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||||
match self {
|
match self {
|
||||||
AssocItem::Function(f) => f.module(db),
|
AssocItem::Function(f) => f.module(db),
|
||||||
|
@ -1253,6 +1264,19 @@ impl Type {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
|
||||||
|
let adt_id = match self.ty.value {
|
||||||
|
Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_id), .. }) => adt_id,
|
||||||
|
_ => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let adt = adt_id.into();
|
||||||
|
match adt {
|
||||||
|
Adt::Struct(s) => matches!(s.repr(db), Some(ReprKind::Packed)),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_raw_ptr(&self) -> bool {
|
pub fn is_raw_ptr(&self) -> bool {
|
||||||
matches!(&self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::RawPtr(..), .. }))
|
matches!(&self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::RawPtr(..), .. }))
|
||||||
}
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
pub use hir_def::diagnostics::UnresolvedModule;
|
pub use hir_def::diagnostics::UnresolvedModule;
|
||||||
pub use hir_expand::diagnostics::{
|
pub use hir_expand::diagnostics::{Diagnostic, DiagnosticSink, DiagnosticSinkBuilder};
|
||||||
AstDiagnostic, Diagnostic, DiagnosticSink, DiagnosticSinkBuilder,
|
|
||||||
};
|
|
||||||
pub use hir_ty::diagnostics::{
|
pub use hir_ty::diagnostics::{
|
||||||
MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField,
|
MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField,
|
||||||
};
|
};
|
|
@ -29,7 +29,7 @@ macro_rules! from_id {
|
||||||
}
|
}
|
||||||
|
|
||||||
from_id![
|
from_id![
|
||||||
(ra_db::CrateId, crate::Crate),
|
(base_db::CrateId, crate::Crate),
|
||||||
(hir_def::ModuleId, crate::Module),
|
(hir_def::ModuleId, crate::Module),
|
||||||
(hir_def::StructId, crate::Struct),
|
(hir_def::StructId, crate::Struct),
|
||||||
(hir_def::UnionId, crate::Union),
|
(hir_def::UnionId, crate::Union),
|
|
@ -1,4 +1,4 @@
|
||||||
//! Provides set of implementation for hir's objects that allows get back location in file.
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
@ -6,7 +6,7 @@ use hir_def::{
|
||||||
src::{HasChildSource, HasSource as _},
|
src::{HasChildSource, HasSource as _},
|
||||||
Lookup, VariantId,
|
Lookup, VariantId,
|
||||||
};
|
};
|
||||||
use ra_syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef,
|
db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef,
|
|
@ -9,11 +9,11 @@
|
||||||
//! It is written in "OO" style. Each type is self contained (as in, it knows it's
|
//! It is written in "OO" style. Each type is self contained (as in, it knows it's
|
||||||
//! parents and full context). It should be "clean code".
|
//! parents and full context). It should be "clean code".
|
||||||
//!
|
//!
|
||||||
//! `ra_hir_*` crates are the implementation of the compiler logic.
|
//! `hir_*` crates are the implementation of the compiler logic.
|
||||||
//! They are written in "ECS" style, with relatively little abstractions.
|
//! They are written in "ECS" style, with relatively little abstractions.
|
||||||
//! Many types are not self-contained, and explicitly use local indexes, arenas, etc.
|
//! Many types are not self-contained, and explicitly use local indexes, arenas, etc.
|
||||||
//!
|
//!
|
||||||
//! `ra_hir` is what insulates the "we don't know how to actually write an incremental compiler"
|
//! `hir` is what insulates the "we don't know how to actually write an incremental compiler"
|
||||||
//! from the ide with completions, hovers, etc. It is a (soft, internal) boundary:
|
//! from the ide with completions, hovers, etc. It is a (soft, internal) boundary:
|
||||||
//! https://www.tedinski.com/2018/02/06/system-boundaries.html.
|
//! https://www.tedinski.com/2018/02/06/system-boundaries.html.
|
||||||
|
|
||||||
|
@ -49,11 +49,15 @@ pub use hir_def::{
|
||||||
docs::Documentation,
|
docs::Documentation,
|
||||||
nameres::ModuleSource,
|
nameres::ModuleSource,
|
||||||
path::{ModPath, Path, PathKind},
|
path::{ModPath, Path, PathKind},
|
||||||
type_ref::Mutability,
|
type_ref::{Mutability, TypeRef},
|
||||||
};
|
};
|
||||||
pub use hir_expand::{
|
pub use hir_expand::{
|
||||||
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
|
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, /* FIXME */ MacroDefId,
|
||||||
MacroDefId, /* FIXME */
|
|
||||||
MacroFile, Origin,
|
MacroFile, Origin,
|
||||||
};
|
};
|
||||||
pub use hir_ty::display::HirDisplay;
|
pub use hir_ty::display::HirDisplay;
|
||||||
|
|
||||||
|
// These are negative re-exports: pub using these names is forbidden, they
|
||||||
|
// should remain private to hir internals.
|
||||||
|
#[allow(unused)]
|
||||||
|
use hir_expand::hygiene::Hygiene;
|
|
@ -4,28 +4,28 @@ mod source_to_def;
|
||||||
|
|
||||||
use std::{cell::RefCell, fmt, iter::successors};
|
use std::{cell::RefCell, fmt, iter::successors};
|
||||||
|
|
||||||
|
use base_db::{FileId, FileRange};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
resolver::{self, HasResolver, Resolver},
|
resolver::{self, HasResolver, Resolver},
|
||||||
AsMacroCall, FunctionId, TraitId, VariantId,
|
AsMacroCall, FunctionId, TraitId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{diagnostics::AstDiagnostic, hygiene::Hygiene, ExpansionInfo};
|
use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo};
|
||||||
use hir_ty::associated_type_shorthand_candidates;
|
use hir_ty::associated_type_shorthand_candidates;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ra_db::{FileId, FileRange};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use ra_prof::profile;
|
use syntax::{
|
||||||
use ra_syntax::{
|
|
||||||
algo::{find_node_at_offset, skip_trivia_token},
|
algo::{find_node_at_offset, skip_trivia_token},
|
||||||
ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
diagnostics::Diagnostic,
|
diagnostics::Diagnostic,
|
||||||
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
|
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
|
||||||
source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer},
|
source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer},
|
||||||
AssocItem, Callable, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module,
|
AssocItem, Callable, Crate, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef,
|
||||||
ModuleDef, Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, VariantDef,
|
Module, ModuleDef, Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, TypeRef,
|
||||||
|
VariantDef,
|
||||||
};
|
};
|
||||||
use resolver::TypeNs;
|
use resolver::TypeNs;
|
||||||
|
|
||||||
|
@ -109,24 +109,16 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
self.imp.parse(file_id)
|
self.imp.parse(file_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ast<T: AstDiagnostic + Diagnostic>(&self, d: &T) -> <T as AstDiagnostic>::AST {
|
|
||||||
let file_id = d.source().file_id;
|
|
||||||
let root = self.db.parse_or_expand(file_id).unwrap();
|
|
||||||
self.imp.cache(root, file_id);
|
|
||||||
d.ast(self.db.upcast())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
|
pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
|
||||||
self.imp.expand(macro_call)
|
self.imp.expand(macro_call)
|
||||||
}
|
}
|
||||||
|
pub fn speculative_expand(
|
||||||
pub fn expand_hypothetical(
|
|
||||||
&self,
|
&self,
|
||||||
actual_macro_call: &ast::MacroCall,
|
actual_macro_call: &ast::MacroCall,
|
||||||
hypothetical_args: &ast::TokenTree,
|
hypothetical_args: &ast::TokenTree,
|
||||||
token_to_map: SyntaxToken,
|
token_to_map: SyntaxToken,
|
||||||
) -> Option<(SyntaxNode, SyntaxToken)> {
|
) -> Option<(SyntaxNode, SyntaxToken)> {
|
||||||
self.imp.expand_hypothetical(actual_macro_call, hypothetical_args, token_to_map)
|
self.imp.speculative_expand(actual_macro_call, hypothetical_args, token_to_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
|
pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
|
||||||
|
@ -145,8 +137,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
self.imp.original_range(node)
|
self.imp.original_range(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
|
pub fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
|
||||||
self.imp.diagnostics_range(diagnostics)
|
self.imp.diagnostics_display_range(diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
|
pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
|
||||||
|
@ -228,6 +220,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
self.imp.resolve_path(path)
|
self.imp.resolve_path(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_extern_crate(&self, extern_crate: &ast::ExternCrate) -> Option<Crate> {
|
||||||
|
self.imp.resolve_extern_crate(extern_crate)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef> {
|
pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef> {
|
||||||
self.imp.resolve_variant(record_lit).map(VariantDef::from)
|
self.imp.resolve_variant(record_lit).map(VariantDef::from)
|
||||||
}
|
}
|
||||||
|
@ -275,6 +271,18 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
pub fn assert_contains_node(&self, node: &SyntaxNode) {
|
pub fn assert_contains_node(&self, node: &SyntaxNode) {
|
||||||
self.imp.assert_contains_node(node)
|
self.imp.assert_contains_node(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> bool {
|
||||||
|
self.imp.is_unsafe_method_call(method_call_expr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool {
|
||||||
|
self.imp.is_unsafe_ref_expr(ref_expr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_ident_pat(&self, ident_pat: &ast::IdentPat) -> bool {
|
||||||
|
self.imp.is_unsafe_ident_pat(ident_pat)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> SemanticsImpl<'db> {
|
impl<'db> SemanticsImpl<'db> {
|
||||||
|
@ -302,7 +310,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_hypothetical(
|
fn speculative_expand(
|
||||||
&self,
|
&self,
|
||||||
actual_macro_call: &ast::MacroCall,
|
actual_macro_call: &ast::MacroCall,
|
||||||
hypothetical_args: &ast::TokenTree,
|
hypothetical_args: &ast::TokenTree,
|
||||||
|
@ -324,7 +332,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
|
fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
|
||||||
let _p = profile("descend_into_macros");
|
let _p = profile::span("descend_into_macros");
|
||||||
let parent = token.parent();
|
let parent = token.parent();
|
||||||
let parent = self.find_file(parent);
|
let parent = self.find_file(parent);
|
||||||
let sa = self.analyze2(parent.as_ref(), None);
|
let sa = self.analyze2(parent.as_ref(), None);
|
||||||
|
@ -372,10 +380,11 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
original_range(self.db, node.as_ref())
|
original_range(self.db, node.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
|
fn diagnostics_display_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
|
||||||
let src = diagnostics.source();
|
let src = diagnostics.display_source();
|
||||||
let root = self.db.parse_or_expand(src.file_id).unwrap();
|
let root = self.db.parse_or_expand(src.file_id).unwrap();
|
||||||
let node = src.value.to_node(&root);
|
let node = src.value.to_node(&root);
|
||||||
|
self.cache(root, src.file_id);
|
||||||
original_range(self.db, src.with_value(&node))
|
original_range(self.db, src.with_value(&node))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +452,17 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
self.analyze(path.syntax()).resolve_path(self.db, path)
|
self.analyze(path.syntax()).resolve_path(self.db, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_extern_crate(&self, extern_crate: &ast::ExternCrate) -> Option<Crate> {
|
||||||
|
let krate = self.scope(extern_crate.syntax()).krate()?;
|
||||||
|
krate.dependencies(self.db).into_iter().find_map(|dep| {
|
||||||
|
if dep.name == extern_crate.name_ref()?.as_name() {
|
||||||
|
Some(dep.krate)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {
|
fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {
|
||||||
self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
|
self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
|
||||||
}
|
}
|
||||||
|
@ -481,18 +501,19 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
|
fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
|
||||||
let node = self.find_file(node.clone());
|
let node = self.find_file(node.clone());
|
||||||
let resolver = self.analyze2(node.as_ref(), None).resolver;
|
let resolver = self.analyze2(node.as_ref(), None).resolver;
|
||||||
SemanticsScope { db: self.db, resolver }
|
SemanticsScope { db: self.db, file_id: node.file_id, resolver }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
|
fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
|
||||||
let node = self.find_file(node.clone());
|
let node = self.find_file(node.clone());
|
||||||
let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
|
let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
|
||||||
SemanticsScope { db: self.db, resolver }
|
SemanticsScope { db: self.db, file_id: node.file_id, resolver }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
|
fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
|
||||||
|
let file_id = self.db.lookup_intern_trait(def.id).id.file_id;
|
||||||
let resolver = def.id.resolver(self.db.upcast());
|
let resolver = def.id.resolver(self.db.upcast());
|
||||||
SemanticsScope { db: self.db, resolver }
|
SemanticsScope { db: self.db, file_id, resolver }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer {
|
fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer {
|
||||||
|
@ -501,7 +522,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextSize>) -> SourceAnalyzer {
|
fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextSize>) -> SourceAnalyzer {
|
||||||
let _p = profile("Semantics::analyze2");
|
let _p = profile::span("Semantics::analyze2");
|
||||||
|
|
||||||
let container = match self.with_ctx(|ctx| ctx.find_container(src)) {
|
let container = match self.with_ctx(|ctx| ctx.find_container(src)) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
|
@ -559,6 +580,90 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
});
|
});
|
||||||
InFile::new(file_id, node)
|
InFile::new(file_id, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> bool {
|
||||||
|
method_call_expr
|
||||||
|
.expr()
|
||||||
|
.and_then(|expr| {
|
||||||
|
let field_expr = if let ast::Expr::FieldExpr(field_expr) = expr {
|
||||||
|
field_expr
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
let ty = self.type_of_expr(&field_expr.expr()?)?;
|
||||||
|
if !ty.is_packed(self.db) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let func = self.resolve_method_call(&method_call_expr).map(Function::from)?;
|
||||||
|
let is_unsafe = func.has_self_param(self.db)
|
||||||
|
&& matches!(func.params(self.db).first(), Some(TypeRef::Reference(..)));
|
||||||
|
Some(is_unsafe)
|
||||||
|
})
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool {
|
||||||
|
ref_expr
|
||||||
|
.expr()
|
||||||
|
.and_then(|expr| {
|
||||||
|
let field_expr = match expr {
|
||||||
|
ast::Expr::FieldExpr(field_expr) => field_expr,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
let expr = field_expr.expr()?;
|
||||||
|
self.type_of_expr(&expr)
|
||||||
|
})
|
||||||
|
// Binding a reference to a packed type is possibly unsafe.
|
||||||
|
.map(|ty| ty.is_packed(self.db))
|
||||||
|
.unwrap_or(false)
|
||||||
|
|
||||||
|
// FIXME This needs layout computation to be correct. It will highlight
|
||||||
|
// more than it should with the current implementation.
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_unsafe_ident_pat(&self, ident_pat: &ast::IdentPat) -> bool {
|
||||||
|
if !ident_pat.ref_token().is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ident_pat
|
||||||
|
.syntax()
|
||||||
|
.parent()
|
||||||
|
.and_then(|parent| {
|
||||||
|
// `IdentPat` can live under `RecordPat` directly under `RecordPatField` or
|
||||||
|
// `RecordPatFieldList`. `RecordPatField` also lives under `RecordPatFieldList`,
|
||||||
|
// so this tries to lookup the `IdentPat` anywhere along that structure to the
|
||||||
|
// `RecordPat` so we can get the containing type.
|
||||||
|
let record_pat = ast::RecordPatField::cast(parent.clone())
|
||||||
|
.and_then(|record_pat| record_pat.syntax().parent())
|
||||||
|
.or_else(|| Some(parent.clone()))
|
||||||
|
.and_then(|parent| {
|
||||||
|
ast::RecordPatFieldList::cast(parent)?
|
||||||
|
.syntax()
|
||||||
|
.parent()
|
||||||
|
.and_then(ast::RecordPat::cast)
|
||||||
|
});
|
||||||
|
|
||||||
|
// If this doesn't match a `RecordPat`, fallback to a `LetStmt` to see if
|
||||||
|
// this is initialized from a `FieldExpr`.
|
||||||
|
if let Some(record_pat) = record_pat {
|
||||||
|
self.type_of_pat(&ast::Pat::RecordPat(record_pat))
|
||||||
|
} else if let Some(let_stmt) = ast::LetStmt::cast(parent) {
|
||||||
|
let field_expr = match let_stmt.initializer()? {
|
||||||
|
ast::Expr::FieldExpr(field_expr) => field_expr,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.type_of_expr(&field_expr.expr()?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// Binding a reference to a packed type is possibly unsafe.
|
||||||
|
.map(|ty| ty.is_packed(self.db))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToDef: AstNode + Clone {
|
pub trait ToDef: AstNode + Clone {
|
||||||
|
@ -604,6 +709,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SemanticsScope<'a> {
|
pub struct SemanticsScope<'a> {
|
||||||
pub db: &'a dyn HirDatabase,
|
pub db: &'a dyn HirDatabase,
|
||||||
|
file_id: HirFileId,
|
||||||
resolver: Resolver,
|
resolver: Resolver,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,6 +718,10 @@ impl<'a> SemanticsScope<'a> {
|
||||||
Some(Module { id: self.resolver.module()? })
|
Some(Module { id: self.resolver.module()? })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn krate(&self) -> Option<Crate> {
|
||||||
|
Some(Crate { id: self.resolver.krate()? })
|
||||||
|
}
|
||||||
|
|
||||||
/// Note: `FxHashSet<TraitId>` should be treated as an opaque type, passed into `Type
|
/// Note: `FxHashSet<TraitId>` should be treated as an opaque type, passed into `Type
|
||||||
// FIXME: rename to visible_traits to not repeat scope?
|
// FIXME: rename to visible_traits to not repeat scope?
|
||||||
pub fn traits_in_scope(&self) -> FxHashSet<TraitId> {
|
pub fn traits_in_scope(&self) -> FxHashSet<TraitId> {
|
||||||
|
@ -643,6 +753,14 @@ impl<'a> SemanticsScope<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve a path as-if it was written at the given scope. This is
|
||||||
|
/// necessary a heuristic, as it doesn't take hygiene into account.
|
||||||
|
pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> {
|
||||||
|
let hygiene = Hygiene::new(self.db.upcast(), self.file_id);
|
||||||
|
let path = Path::from_src(path.clone(), &hygiene)?;
|
||||||
|
self.resolve_hir_path(&path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> {
|
pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> {
|
||||||
resolve_hir_path(self.db, &self.resolver, path)
|
resolve_hir_path(self.db, &self.resolver, path)
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
//! Maps *syntax* of various definitions to their semantic ids.
|
//! Maps *syntax* of various definitions to their semantic ids.
|
||||||
|
|
||||||
|
use base_db::FileId;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
child_by_source::ChildBySource,
|
child_by_source::ChildBySource,
|
||||||
dyn_map::DynMap,
|
dyn_map::DynMap,
|
||||||
|
@ -9,14 +10,12 @@ use hir_def::{
|
||||||
ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{name::AsName, AstId, MacroDefKind};
|
use hir_expand::{name::AsName, AstId, MacroDefKind};
|
||||||
use ra_db::FileId;
|
use rustc_hash::FxHashMap;
|
||||||
use ra_prof::profile;
|
use stdx::impl_from;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
match_ast, AstNode, SyntaxNode,
|
match_ast, AstNode, SyntaxNode,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use stdx::impl_from;
|
|
||||||
|
|
||||||
use crate::{db::HirDatabase, InFile, MacroDefId};
|
use crate::{db::HirDatabase, InFile, MacroDefId};
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> {
|
||||||
|
|
||||||
impl SourceToDefCtx<'_, '_> {
|
impl SourceToDefCtx<'_, '_> {
|
||||||
pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> {
|
pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> {
|
||||||
let _p = profile("SourceBinder::to_module_def");
|
let _p = profile::span("SourceBinder::to_module_def");
|
||||||
let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| {
|
let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| {
|
||||||
let crate_def_map = self.db.crate_def_map(crate_id);
|
let crate_def_map = self.db.crate_def_map(crate_id);
|
||||||
let local_id = crate_def_map.modules_for_file(file).next()?;
|
let local_id = crate_def_map.modules_for_file(file).next()?;
|
||||||
|
@ -39,7 +38,7 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
|
pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
|
||||||
let _p = profile("module_to_def");
|
let _p = profile::span("module_to_def");
|
||||||
let parent_declaration = src
|
let parent_declaration = src
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|it| it.syntax())
|
.map(|it| it.syntax())
|
|
@ -21,7 +21,7 @@ use hir_ty::{
|
||||||
diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
|
diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
|
||||||
InferenceResult, Substs, Ty,
|
InferenceResult, Substs, Ty,
|
||||||
};
|
};
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
SyntaxNode, TextRange, TextSize,
|
SyntaxNode, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ use crate::{
|
||||||
MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias,
|
MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias,
|
||||||
TypeParam,
|
TypeParam,
|
||||||
};
|
};
|
||||||
use ra_db::CrateId;
|
use base_db::CrateId;
|
||||||
|
|
||||||
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
||||||
/// original source files. It should not be used inside the HIR itself.
|
/// original source files. It should not be used inside the HIR itself.
|
||||||
|
@ -265,8 +265,7 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be a normal source file rather than macro file.
|
// This must be a normal source file rather than macro file.
|
||||||
let hir_path =
|
let hir_path = Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?;
|
||||||
crate::Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?;
|
|
||||||
|
|
||||||
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
|
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
|
||||||
// trying to resolve foo::bar.
|
// trying to resolve foo::bar.
|
||||||
|
@ -451,7 +450,7 @@ fn adjust(
|
||||||
pub(crate) fn resolve_hir_path(
|
pub(crate) fn resolve_hir_path(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver,
|
||||||
path: &crate::Path,
|
path: &Path,
|
||||||
) -> Option<PathResolution> {
|
) -> Option<PathResolution> {
|
||||||
let types =
|
let types =
|
||||||
resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
|
resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
|
||||||
|
@ -512,7 +511,7 @@ pub(crate) fn resolve_hir_path(
|
||||||
pub(crate) fn resolve_hir_path_qualifier(
|
pub(crate) fn resolve_hir_path_qualifier(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver,
|
||||||
path: &crate::Path,
|
path: &Path,
|
||||||
) -> Option<PathResolution> {
|
) -> Option<PathResolution> {
|
||||||
let items = resolver
|
let items = resolver
|
||||||
.resolve_module_path_in_items(db.upcast(), path.mod_path())
|
.resolve_module_path_in_items(db.upcast(), path.mod_path())
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
name = "hir_def"
|
||||||
name = "ra_hir_def"
|
version = "0.0.0"
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["rust-analyzer developers"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["rust-analyzer developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -21,16 +21,15 @@ indexmap = "1.4.0"
|
||||||
smallvec = "1.4.0"
|
smallvec = "1.4.0"
|
||||||
|
|
||||||
stdx = { path = "../stdx" }
|
stdx = { path = "../stdx" }
|
||||||
|
arena = { path = "../arena" }
|
||||||
ra_arena = { path = "../ra_arena" }
|
base_db = { path = "../base_db" }
|
||||||
ra_db = { path = "../ra_db" }
|
syntax = { path = "../syntax" }
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
profile = { path = "../profile" }
|
||||||
ra_prof = { path = "../ra_prof" }
|
hir_expand = { path = "../hir_expand" }
|
||||||
hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
|
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
mbe = { path = "../mbe" }
|
||||||
ra_cfg = { path = "../ra_cfg" }
|
cfg = { path = "../cfg" }
|
||||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
tt = { path = "../tt" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect = { path = "../expect" }
|
expect = { path = "../expect" }
|
|
@ -2,18 +2,19 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arena::{map::ArenaMap, Arena};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
InFile,
|
InFile,
|
||||||
};
|
};
|
||||||
use ra_arena::{map::ArenaMap, Arena};
|
use syntax::ast::{self, NameOwner, VisibilityOwner};
|
||||||
use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
|
use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{CfgExpander, LowerCtx},
|
body::{CfgExpander, LowerCtx},
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_tree::{Field, Fields, ItemTree},
|
item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem},
|
||||||
src::HasChildSource,
|
src::HasChildSource,
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
trace::Trace,
|
trace::Trace,
|
||||||
|
@ -22,13 +23,14 @@ use crate::{
|
||||||
EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId,
|
EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId,
|
||||||
VariantId,
|
VariantId,
|
||||||
};
|
};
|
||||||
use ra_cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
|
|
||||||
/// Note that we use `StructData` for unions as well!
|
/// Note that we use `StructData` for unions as well!
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct StructData {
|
pub struct StructData {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub variant_data: Arc<VariantData>,
|
pub variant_data: Arc<VariantData>,
|
||||||
|
pub repr: Option<ReprKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -58,26 +60,58 @@ pub struct FieldData {
|
||||||
pub visibility: RawVisibility,
|
pub visibility: RawVisibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum ReprKind {
|
||||||
|
Packed,
|
||||||
|
Other,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> {
|
||||||
|
item_tree.attrs(of).by_key("repr").tt_values().find_map(parse_repr_tt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> {
|
||||||
|
match tt.delimiter {
|
||||||
|
Some(Delimiter { kind: DelimiterKind::Parenthesis, .. }) => {}
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut it = tt.token_trees.iter();
|
||||||
|
match it.next()? {
|
||||||
|
TokenTree::Leaf(Leaf::Ident(ident)) if ident.text == "packed" => Some(ReprKind::Packed),
|
||||||
|
_ => Some(ReprKind::Other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl StructData {
|
impl StructData {
|
||||||
pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
|
pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
|
||||||
let loc = id.lookup(db);
|
let loc = id.lookup(db);
|
||||||
let item_tree = db.item_tree(loc.id.file_id);
|
let item_tree = db.item_tree(loc.id.file_id);
|
||||||
|
let repr = repr_from_value(&item_tree, ModItem::from(loc.id.value).into());
|
||||||
let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone();
|
let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone();
|
||||||
|
|
||||||
let strukt = &item_tree[loc.id.value];
|
let strukt = &item_tree[loc.id.value];
|
||||||
let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields);
|
let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields);
|
||||||
|
Arc::new(StructData {
|
||||||
Arc::new(StructData { name: strukt.name.clone(), variant_data: Arc::new(variant_data) })
|
name: strukt.name.clone(),
|
||||||
|
variant_data: Arc::new(variant_data),
|
||||||
|
repr,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
|
pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
|
||||||
let loc = id.lookup(db);
|
let loc = id.lookup(db);
|
||||||
let item_tree = db.item_tree(loc.id.file_id);
|
let item_tree = db.item_tree(loc.id.file_id);
|
||||||
|
let repr = repr_from_value(&item_tree, ModItem::from(loc.id.value).into());
|
||||||
let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone();
|
let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone();
|
||||||
|
|
||||||
let union = &item_tree[loc.id.value];
|
let union = &item_tree[loc.id.value];
|
||||||
let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields);
|
let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields);
|
||||||
|
|
||||||
Arc::new(StructData { name: union.name.clone(), variant_data: Arc::new(variant_data) })
|
Arc::new(StructData {
|
||||||
|
name: union.name.clone(),
|
||||||
|
variant_data: Arc::new(variant_data),
|
||||||
|
repr,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
use std::{ops, sync::Arc};
|
use std::{ops, sync::Arc};
|
||||||
|
|
||||||
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{hygiene::Hygiene, AstId, InFile};
|
use hir_expand::{hygiene::Hygiene, AstId, InFile};
|
||||||
use mbe::ast_to_token_tree;
|
use mbe::ast_to_token_tree;
|
||||||
use ra_cfg::{CfgExpr, CfgOptions};
|
use syntax::{
|
||||||
use ra_syntax::{
|
|
||||||
ast::{self, AstNode, AttrsOwner},
|
ast::{self, AstNode, AttrsOwner},
|
||||||
SmolStr,
|
SmolStr,
|
||||||
};
|
};
|
|
@ -5,15 +5,14 @@ pub mod scope;
|
||||||
|
|
||||||
use std::{mem, ops::Index, sync::Arc};
|
use std::{mem, ops::Index, sync::Arc};
|
||||||
|
|
||||||
|
use arena::{map::ArenaMap, Arena};
|
||||||
|
use base_db::CrateId;
|
||||||
|
use cfg::CfgOptions;
|
||||||
use drop_bomb::DropBomb;
|
use drop_bomb::DropBomb;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
|
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
|
||||||
use ra_arena::{map::ArenaMap, Arena};
|
|
||||||
use ra_cfg::CfgOptions;
|
|
||||||
use ra_db::CrateId;
|
|
||||||
use ra_prof::profile;
|
|
||||||
use ra_syntax::{ast, AstNode, AstPtr};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use syntax::{ast, AstNode, AstPtr};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
pub(crate) use lower::LowerCtx;
|
pub(crate) use lower::LowerCtx;
|
||||||
|
@ -228,7 +227,7 @@ impl Body {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
||||||
let _p = profile("body_with_source_map_query");
|
let _p = profile::span("body_with_source_map_query");
|
||||||
let mut params = None;
|
let mut params = None;
|
||||||
|
|
||||||
let (file_id, module, body) = match def {
|
let (file_id, module, body) = match def {
|
||||||
|
@ -321,7 +320,7 @@ impl BodySourceMap {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ra_db::{fixture::WithFixture, SourceDatabase};
|
use base_db::{fixture::WithFixture, SourceDatabase};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::ModuleDefId;
|
use crate::ModuleDefId;
|
|
@ -3,21 +3,21 @@
|
||||||
|
|
||||||
use std::{any::type_name, sync::Arc};
|
use std::{any::type_name, sync::Arc};
|
||||||
|
|
||||||
|
use arena::Arena;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
name::{name, AsName, Name},
|
name::{name, AsName, Name},
|
||||||
HirFileId, MacroDefId, MacroDefKind,
|
HirFileId, MacroDefId, MacroDefKind,
|
||||||
};
|
};
|
||||||
use ra_arena::Arena;
|
use rustc_hash::FxHashMap;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
|
self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
|
||||||
SlicePatComponents,
|
SlicePatComponents,
|
||||||
},
|
},
|
||||||
AstNode, AstPtr,
|
AstNode, AstPtr,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
|
@ -1,8 +1,8 @@
|
||||||
//! Name resolution for expressions.
|
//! Name resolution for expressions.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arena::{Arena, Idx};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use ra_arena::{Arena, Idx};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -169,9 +169,9 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use base_db::{fixture::WithFixture, FileId, SourceDatabase};
|
||||||
use hir_expand::{name::AsName, InFile};
|
use hir_expand::{name::AsName, InFile};
|
||||||
use ra_db::{fixture::WithFixture, FileId, SourceDatabase};
|
use syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||||
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
|
||||||
use test_utils::{assert_eq_text, extract_offset, mark};
|
use test_utils::{assert_eq_text, extract_offset, mark};
|
||||||
|
|
||||||
use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId};
|
use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId};
|
|
@ -3,8 +3,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_expand::{name::Name, InFile};
|
use hir_expand::{name::Name, InFile};
|
||||||
use ra_prof::profile;
|
use syntax::ast;
|
||||||
use ra_syntax::ast;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
|
@ -133,7 +132,7 @@ pub struct ImplData {
|
||||||
|
|
||||||
impl ImplData {
|
impl ImplData {
|
||||||
pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> {
|
pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> {
|
||||||
let _p = profile("impl_data_query");
|
let _p = profile::span("impl_data_query");
|
||||||
let impl_loc = id.lookup(db);
|
let impl_loc = id.lookup(db);
|
||||||
|
|
||||||
let item_tree = db.item_tree(impl_loc.id.file_id);
|
let item_tree = db.item_tree(impl_loc.id.file_id);
|
|
@ -1,10 +1,9 @@
|
||||||
//! Defines database & queries for name resolution.
|
//! Defines database & queries for name resolution.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
|
||||||
use hir_expand::{db::AstDatabase, HirFileId};
|
use hir_expand::{db::AstDatabase, HirFileId};
|
||||||
use ra_db::{salsa, CrateId, SourceDatabase, Upcast};
|
use syntax::SmolStr;
|
||||||
use ra_prof::profile;
|
|
||||||
use ra_syntax::SmolStr;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::{EnumData, StructData},
|
adt::{EnumData, StructData},
|
||||||
|
@ -116,6 +115,6 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
|
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
|
||||||
let _p = profile("crate_def_map:wait");
|
let _p = profile::span("crate_def_map:wait");
|
||||||
db.crate_def_map_query(krate)
|
db.crate_def_map_query(krate)
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use hir_expand::diagnostics::Diagnostic;
|
use hir_expand::diagnostics::Diagnostic;
|
||||||
use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
|
use syntax::{ast, AstPtr, SyntaxNodePtr};
|
||||||
|
|
||||||
use hir_expand::{HirFileId, InFile};
|
use hir_expand::{HirFileId, InFile};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ impl Diagnostic for UnresolvedModule {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"unresolved module".to_string()
|
"unresolved module".to_string()
|
||||||
}
|
}
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile::new(self.file, self.decl.clone().into())
|
InFile::new(self.file, self.decl.clone().into())
|
||||||
}
|
}
|
||||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
|
@ -6,7 +6,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use ra_syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
|
@ -12,9 +12,9 @@
|
||||||
//!
|
//!
|
||||||
//! See also a neighboring `body` module.
|
//! See also a neighboring `body` module.
|
||||||
|
|
||||||
|
use arena::{Idx, RawId};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use ra_arena::{Idx, RawId};
|
use syntax::ast::RangeOp;
|
||||||
use ra_syntax::ast::RangeOp;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
builtin_type::{BuiltinFloat, BuiltinInt},
|
builtin_type::{BuiltinFloat, BuiltinInt},
|
||||||
|
@ -197,7 +197,7 @@ pub enum ArithOp {
|
||||||
BitAnd,
|
BitAnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use ra_syntax::ast::PrefixOp as UnaryOp;
|
pub use syntax::ast::PrefixOp as UnaryOp;
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum Array {
|
pub enum Array {
|
||||||
ElementList(Vec<ExprId>),
|
ElementList(Vec<ExprId>),
|
|
@ -1,7 +1,6 @@
|
||||||
//! An algorithm to find a path to refer to a certain item.
|
//! An algorithm to find a path to refer to a certain item.
|
||||||
|
|
||||||
use hir_expand::name::{known, AsName, Name};
|
use hir_expand::name::{known, AsName, Name};
|
||||||
use ra_prof::profile;
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ use crate::{
|
||||||
/// Find a path that can be used to refer to a certain item. This can depend on
|
/// Find a path that can be used to refer to a certain item. This can depend on
|
||||||
/// *from where* you're referring to the item, hence the `from` parameter.
|
/// *from where* you're referring to the item, hence the `from` parameter.
|
||||||
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
||||||
let _p = profile("find_path");
|
let _p = profile::span("find_path");
|
||||||
find_path_inner(db, item, from, MAX_PATH_LEN)
|
find_path_inner(db, item, from, MAX_PATH_LEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +214,7 @@ fn find_local_import_locations(
|
||||||
item: ItemInNs,
|
item: ItemInNs,
|
||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
) -> Vec<(ModuleId, Name)> {
|
) -> Vec<(ModuleId, Name)> {
|
||||||
let _p = profile("find_local_import_locations");
|
let _p = profile::span("find_local_import_locations");
|
||||||
|
|
||||||
// `from` can import anything below `from` with visibility of at least `from`, and anything
|
// `from` can import anything below `from` with visibility of at least `from`, and anything
|
||||||
// above `from` with any visibility. That means we do not need to descend into private siblings
|
// above `from` with any visibility. That means we do not need to descend into private siblings
|
||||||
|
@ -293,9 +292,9 @@ fn find_local_import_locations(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use base_db::fixture::WithFixture;
|
||||||
use hir_expand::hygiene::Hygiene;
|
use hir_expand::hygiene::Hygiene;
|
||||||
use ra_db::fixture::WithFixture;
|
use syntax::ast::AstNode;
|
||||||
use ra_syntax::ast::AstNode;
|
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::test_db::TestDB;
|
use crate::test_db::TestDB;
|
||||||
|
@ -308,12 +307,9 @@ mod tests {
|
||||||
fn check_found_path(ra_fixture: &str, path: &str) {
|
fn check_found_path(ra_fixture: &str, path: &str) {
|
||||||
let (db, pos) = TestDB::with_position(ra_fixture);
|
let (db, pos) = TestDB::with_position(ra_fixture);
|
||||||
let module = db.module_for_file(pos.file_id);
|
let module = db.module_for_file(pos.file_id);
|
||||||
let parsed_path_file = ra_syntax::SourceFile::parse(&format!("use {};", path));
|
let parsed_path_file = syntax::SourceFile::parse(&format!("use {};", path));
|
||||||
let ast_path = parsed_path_file
|
let ast_path =
|
||||||
.syntax_node()
|
parsed_path_file.syntax_node().descendants().find_map(syntax::ast::Path::cast).unwrap();
|
||||||
.descendants()
|
|
||||||
.find_map(ra_syntax::ast::Path::cast)
|
|
||||||
.unwrap();
|
|
||||||
let mod_path = ModPath::from_src(ast_path, &Hygiene::new_unhygienic()).unwrap();
|
let mod_path = ModPath::from_src(ast_path, &Hygiene::new_unhygienic()).unwrap();
|
||||||
|
|
||||||
let crate_def_map = db.crate_def_map(module.krate);
|
let crate_def_map = db.crate_def_map(module.krate);
|
||||||
|
@ -442,12 +438,12 @@ mod tests {
|
||||||
// already in scope.
|
// already in scope.
|
||||||
check_found_path(
|
check_found_path(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:ra_syntax
|
//- /main.rs crate:main deps:syntax
|
||||||
|
|
||||||
use ra_syntax::ast;
|
use syntax::ast;
|
||||||
<|>
|
<|>
|
||||||
|
|
||||||
//- /lib.rs crate:ra_syntax
|
//- /lib.rs crate:syntax
|
||||||
pub mod ast {
|
pub mod ast {
|
||||||
pub enum ModuleItem {
|
pub enum ModuleItem {
|
||||||
A, B, C,
|
A, B, C,
|
||||||
|
@ -459,18 +455,18 @@ mod tests {
|
||||||
|
|
||||||
check_found_path(
|
check_found_path(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:ra_syntax
|
//- /main.rs crate:main deps:syntax
|
||||||
|
|
||||||
<|>
|
<|>
|
||||||
|
|
||||||
//- /lib.rs crate:ra_syntax
|
//- /lib.rs crate:syntax
|
||||||
pub mod ast {
|
pub mod ast {
|
||||||
pub enum ModuleItem {
|
pub enum ModuleItem {
|
||||||
A, B, C,
|
A, B, C,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
"ra_syntax::ast::ModuleItem",
|
"syntax::ast::ModuleItem",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
//! in rustc.
|
//! in rustc.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arena::{map::ArenaMap, Arena};
|
||||||
|
use base_db::FileId;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{name, AsName, Name},
|
name::{name, AsName, Name},
|
||||||
InFile,
|
InFile,
|
||||||
};
|
};
|
||||||
use ra_arena::{map::ArenaMap, Arena};
|
use syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
|
||||||
use ra_db::FileId;
|
|
||||||
use ra_prof::profile;
|
|
||||||
use ra_syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::LowerCtx,
|
body::LowerCtx,
|
||||||
|
@ -73,7 +72,7 @@ impl GenericParams {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
) -> Arc<GenericParams> {
|
) -> Arc<GenericParams> {
|
||||||
let _p = profile("generic_params_query");
|
let _p = profile::span("generic_params_query");
|
||||||
|
|
||||||
let generics = match def {
|
let generics = match def {
|
||||||
GenericDefId::FunctionId(id) => {
|
GenericDefId::FunctionId(id) => {
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
|
use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
|
||||||
|
|
||||||
|
use base_db::CrateId;
|
||||||
use fst::{self, Streamer};
|
use fst::{self, Streamer};
|
||||||
use indexmap::{map::Entry, IndexMap};
|
use indexmap::{map::Entry, IndexMap};
|
||||||
use ra_db::CrateId;
|
|
||||||
use ra_syntax::SmolStr;
|
|
||||||
use rustc_hash::{FxHashMap, FxHasher};
|
use rustc_hash::{FxHashMap, FxHasher};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
|
@ -56,7 +56,7 @@ pub struct ImportMap {
|
||||||
|
|
||||||
impl ImportMap {
|
impl ImportMap {
|
||||||
pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
|
pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
|
||||||
let _p = ra_prof::profile("import_map_query");
|
let _p = profile::span("import_map_query");
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = db.crate_def_map(krate);
|
||||||
let mut import_map = Self::default();
|
let mut import_map = Self::default();
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ pub fn search_dependencies<'a>(
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
query: Query,
|
query: Query,
|
||||||
) -> Vec<ItemInNs> {
|
) -> Vec<ItemInNs> {
|
||||||
let _p = ra_prof::profile("search_dependencies").detail(|| format!("{:?}", query));
|
let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query));
|
||||||
|
|
||||||
let graph = db.crate_graph();
|
let graph = db.crate_graph();
|
||||||
let import_maps: Vec<_> =
|
let import_maps: Vec<_> =
|
||||||
|
@ -327,8 +327,8 @@ pub fn search_dependencies<'a>(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use base_db::{fixture::WithFixture, SourceDatabase, Upcast};
|
||||||
use expect::{expect, Expect};
|
use expect::{expect, Expect};
|
||||||
use ra_db::{fixture::WithFixture, SourceDatabase, Upcast};
|
|
||||||
|
|
||||||
use crate::{test_db::TestDB, AssocContainerId, Lookup};
|
use crate::{test_db::TestDB, AssocContainerId, Lookup};
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
|
use base_db::CrateId;
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use ra_db::CrateId;
|
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
|
@ -13,6 +13,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use arena::{Arena, Idx, RawId};
|
||||||
use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
|
use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
|
@ -21,10 +22,9 @@ use hir_expand::{
|
||||||
name::{name, AsName, Name},
|
name::{name, AsName, Name},
|
||||||
HirFileId, InFile,
|
HirFileId, InFile,
|
||||||
};
|
};
|
||||||
use ra_arena::{Arena, Idx, RawId};
|
|
||||||
use ra_syntax::{ast, match_ast};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use syntax::{ast, match_ast};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -77,7 +77,7 @@ pub struct ItemTree {
|
||||||
|
|
||||||
impl ItemTree {
|
impl ItemTree {
|
||||||
pub fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
|
pub fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
|
||||||
let _p = ra_prof::profile("item_tree_query").detail(|| format!("{:?}", file_id));
|
let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id));
|
||||||
let syntax = if let Some(node) = db.parse_or_expand(file_id) {
|
let syntax = if let Some(node) = db.parse_or_expand(file_id) {
|
||||||
node
|
node
|
||||||
} else {
|
} else {
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
use std::{collections::hash_map::Entry, mem, sync::Arc};
|
use std::{collections::hash_map::Entry, mem, sync::Arc};
|
||||||
|
|
||||||
|
use arena::map::ArenaMap;
|
||||||
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId};
|
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId};
|
||||||
use ra_arena::map::ArenaMap;
|
use smallvec::SmallVec;
|
||||||
use ra_syntax::{
|
use syntax::{
|
||||||
ast::{self, ModuleItemOwner},
|
ast::{self, ModuleItemOwner},
|
||||||
SyntaxNode,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
|
@ -1,10 +1,10 @@
|
||||||
|
use base_db::fixture::WithFixture;
|
||||||
use expect::{expect, Expect};
|
use expect::{expect, Expect};
|
||||||
use hir_expand::{db::AstDatabase, HirFileId, InFile};
|
use hir_expand::{db::AstDatabase, HirFileId, InFile};
|
||||||
use ra_db::fixture::WithFixture;
|
|
||||||
use ra_syntax::{ast, AstNode};
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
use syntax::{ast, AstNode};
|
||||||
|
|
||||||
use crate::{db::DefDatabase, test_db::TestDB};
|
use crate::{db::DefDatabase, test_db::TestDB};
|
||||||
|
|
||||||
|
@ -228,31 +228,31 @@ fn smoke() {
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
|
||||||
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
|
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
|
||||||
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
|
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
|
||||||
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) }
|
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<syntax::ast::generated::nodes::ExternCrate>(1) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
|
||||||
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(2) }
|
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
|
||||||
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TypeAlias>(8) }
|
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
|
||||||
> Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Const>(9) }
|
> Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<syntax::ast::generated::nodes::Const>(9) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(10) }
|
> Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(10) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(11) }
|
> Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(11) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }]
|
||||||
Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(3), kind: Unit }
|
Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(3), kind: Unit }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }]
|
||||||
Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<ra_hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(4), kind: Tuple }
|
Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(4), kind: Tuple }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }]
|
||||||
Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(5), kind: Record }
|
Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(5), kind: Record }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }]
|
||||||
Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Enum>(6) }
|
Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<syntax::ast::generated::nodes::Enum>(6) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }]
|
||||||
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Union>(7) }
|
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<syntax::ast::generated::nodes::Union>(7) }
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -274,13 +274,13 @@ fn simple_inner_items() {
|
||||||
inner attrs: Attrs { entries: None }
|
inner attrs: Attrs { entries: None }
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
|
Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
|
||||||
> Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
|
> Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
|
||||||
|
|
||||||
inner items:
|
inner items:
|
||||||
|
|
||||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
|
for AST FileAstId::<syntax::ast::generated::nodes::Item>(2):
|
||||||
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
|
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
|
||||||
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -303,9 +303,9 @@ fn extern_attrs() {
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
|
||||||
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
|
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
|
||||||
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
|
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -327,11 +327,11 @@ fn trait_attrs() {
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
|
||||||
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(0) }
|
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(0) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
|
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
|
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -353,11 +353,11 @@ fn impl_attrs() {
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }]
|
||||||
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
|
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
|
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
|
||||||
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
|
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
|
||||||
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
|
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -408,13 +408,13 @@ fn inner_item_attrs() {
|
||||||
inner attrs: Attrs { entries: None }
|
inner attrs: Attrs { entries: None }
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(0) }
|
Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(0) }
|
||||||
|
|
||||||
inner items:
|
inner items:
|
||||||
|
|
||||||
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
|
for AST FileAstId::<syntax::ast::generated::nodes::Item>(1):
|
||||||
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
|
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
|
||||||
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
|
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
|
||||||
|
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
|
@ -432,8 +432,8 @@ fn assoc_item_macros() {
|
||||||
inner attrs: Attrs { entries: None }
|
inner attrs: Attrs { entries: None }
|
||||||
|
|
||||||
top-level items:
|
top-level items:
|
||||||
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
|
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
|
||||||
> MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::MacroCall>(1) }
|
> MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<syntax::ast::generated::nodes::MacroCall>(1) }
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -3,8 +3,8 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use hir_expand::{InFile, MacroDefId};
|
use hir_expand::{InFile, MacroDefId};
|
||||||
use ra_syntax::{ast, AstNode, AstPtr};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use syntax::{ast, AstNode, AstPtr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dyn_map::{DynMap, Policy},
|
dyn_map::{DynMap, Policy},
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue