mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Replace ra_hir_expand::either
with crate
This commit is contained in:
parent
15f143f0c3
commit
009437f5d9
23 changed files with 69 additions and 112 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -944,6 +944,7 @@ dependencies = [
|
||||||
name = "ra_hir"
|
name = "ra_hir"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_db 0.1.0",
|
"ra_db 0.1.0",
|
||||||
"ra_hir_def 0.1.0",
|
"ra_hir_def 0.1.0",
|
||||||
|
@ -957,6 +958,7 @@ dependencies = [
|
||||||
name = "ra_hir_def"
|
name = "ra_hir_def"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -976,6 +978,7 @@ dependencies = [
|
||||||
name = "ra_hir_expand"
|
name = "ra_hir_expand"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_arena 0.1.0",
|
"ra_arena 0.1.0",
|
||||||
"ra_db 0.1.0",
|
"ra_db 0.1.0",
|
||||||
|
@ -1012,6 +1015,7 @@ dependencies = [
|
||||||
name = "ra_ide"
|
name = "ra_ide"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -10,6 +10,7 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
|
either = "1.5"
|
||||||
|
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
|
|
|
@ -4,6 +4,7 @@ pub(crate) mod src;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
body::{Body, BodySourceMap},
|
body::{Body, BodySourceMap},
|
||||||
|
@ -30,7 +31,7 @@ use crate::{
|
||||||
db::{DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
ty::display::HirFormatter,
|
ty::display::HirFormatter,
|
||||||
ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
|
ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
|
||||||
CallableDef, Either, HirDisplay, InFile, Name,
|
CallableDef, HirDisplay, InFile, Name,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// hir::Crate describes a single crate. It's the main interface with which
|
/// hir::Crate describes a single crate. It's the main interface with which
|
||||||
|
@ -905,7 +906,9 @@ impl Local {
|
||||||
let (_body, source_map) = db.body_with_source_map(self.parent.into());
|
let (_body, source_map) = db.body_with_source_map(self.parent.into());
|
||||||
let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
|
let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
|
||||||
let root = src.file_syntax(db);
|
let root = src.file_syntax(db);
|
||||||
src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root)))
|
src.map(|ast| {
|
||||||
|
ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
src::{HasChildSource, HasSource as _},
|
src::{HasChildSource, HasSource as _},
|
||||||
AstItemDef, Lookup, VariantId,
|
AstItemDef, Lookup, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::either::Either;
|
|
||||||
use ra_syntax::ast;
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -27,8 +27,8 @@ impl Module {
|
||||||
let def_map = db.crate_def_map(self.id.krate);
|
let def_map = db.crate_def_map(self.id.krate);
|
||||||
let src = def_map[self.id.local_id].definition_source(db);
|
let src = def_map[self.id.local_id].definition_source(db);
|
||||||
src.map(|it| match it {
|
src.map(|it| match it {
|
||||||
Either::A(it) => ModuleSource::SourceFile(it),
|
Either::Left(it) => ModuleSource::SourceFile(it),
|
||||||
Either::B(it) => ModuleSource::Module(it),
|
Either::Right(it) => ModuleSource::Module(it),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ impl HasSource for StructField {
|
||||||
let var = VariantId::from(self.parent);
|
let var = VariantId::from(self.parent);
|
||||||
let src = var.child_source(db);
|
let src = var.child_source(db);
|
||||||
src.map(|it| match it[self.id].clone() {
|
src.map(|it| match it[self.id].clone() {
|
||||||
Either::A(it) => FieldSource::Pos(it),
|
Either::Left(it) => FieldSource::Pos(it),
|
||||||
Either::B(it) => FieldSource::Named(it),
|
Either::Right(it) => FieldSource::Named(it),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,6 @@ impl HasSource for Import {
|
||||||
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
|
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
|
||||||
let root = db.parse_or_expand(src.file_id).unwrap();
|
let root = db.parse_or_expand(src.file_id).unwrap();
|
||||||
let ptr = source_map.get(self.id);
|
let ptr = source_map.get(self.id);
|
||||||
src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root)))
|
src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,5 +63,5 @@ pub use hir_def::{
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
pub use hir_expand::{
|
pub use hir_expand::{
|
||||||
either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
|
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//! purely for "IDE needs".
|
//! purely for "IDE needs".
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{
|
body::{
|
||||||
scope::{ExprScopes, ScopeId},
|
scope::{ExprScopes, ScopeId},
|
||||||
|
@ -33,8 +34,8 @@ use crate::{
|
||||||
method_resolution::{self, implements_trait},
|
method_resolution::{self, implements_trait},
|
||||||
InEnvironment, TraitEnvironment, Ty,
|
InEnvironment, TraitEnvironment, Ty,
|
||||||
},
|
},
|
||||||
Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
|
Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam,
|
||||||
GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
|
Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
|
fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
|
||||||
|
@ -349,7 +350,7 @@ impl SourceAnalyzer {
|
||||||
// should switch to general reference search infra there.
|
// should switch to general reference search infra there.
|
||||||
pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
|
pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
|
||||||
let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
|
let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
|
||||||
let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone())));
|
let ptr = Either::Left(AstPtr::new(&ast::Pat::from(pat.clone())));
|
||||||
fn_def
|
fn_def
|
||||||
.syntax()
|
.syntax()
|
||||||
.descendants()
|
.descendants()
|
||||||
|
|
|
@ -11,6 +11,7 @@ doctest = false
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
once_cell = "1.0.1"
|
once_cell = "1.0.1"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
|
either = "1.5"
|
||||||
|
|
||||||
ra_arena = { path = "../ra_arena" }
|
ra_arena = { path = "../ra_arena" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
either::Either,
|
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
InFile,
|
InFile,
|
||||||
};
|
};
|
||||||
|
@ -184,7 +184,7 @@ fn lower_struct(
|
||||||
ast::StructKind::Tuple(fl) => {
|
ast::StructKind::Tuple(fl) => {
|
||||||
for (i, fd) in fl.fields().enumerate() {
|
for (i, fd) in fl.fields().enumerate() {
|
||||||
trace.alloc(
|
trace.alloc(
|
||||||
|| Either::A(fd.clone()),
|
|| Either::Left(fd.clone()),
|
||||||
|| StructFieldData {
|
|| StructFieldData {
|
||||||
name: Name::new_tuple_field(i),
|
name: Name::new_tuple_field(i),
|
||||||
type_ref: TypeRef::from_ast_opt(fd.type_ref()),
|
type_ref: TypeRef::from_ast_opt(fd.type_ref()),
|
||||||
|
@ -196,7 +196,7 @@ fn lower_struct(
|
||||||
ast::StructKind::Record(fl) => {
|
ast::StructKind::Record(fl) => {
|
||||||
for fd in fl.fields() {
|
for fd in fl.fields() {
|
||||||
trace.alloc(
|
trace.alloc(
|
||||||
|| Either::B(fd.clone()),
|
|| Either::Right(fd.clone()),
|
||||||
|| StructFieldData {
|
|| StructFieldData {
|
||||||
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
|
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
|
||||||
type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
|
type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
use std::{ops, sync::Arc};
|
use std::{ops, sync::Arc};
|
||||||
|
|
||||||
use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile};
|
use either::Either;
|
||||||
|
use hir_expand::{hygiene::Hygiene, AstId, InFile};
|
||||||
use mbe::ast_to_token_tree;
|
use mbe::ast_to_token_tree;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, AstNode, AttrsOwner},
|
ast::{self, AstNode, AttrsOwner},
|
||||||
|
@ -45,8 +46,8 @@ impl Attrs {
|
||||||
AttrDefId::StructFieldId(it) => {
|
AttrDefId::StructFieldId(it) => {
|
||||||
let src = it.parent.child_source(db);
|
let src = it.parent.child_source(db);
|
||||||
match &src.value[it.local_id] {
|
match &src.value[it.local_id] {
|
||||||
Either::A(_tuple) => Attrs::default(),
|
Either::Left(_tuple) => Attrs::default(),
|
||||||
Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
|
Either::Right(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AttrDefId::EnumVariantId(var_id) => {
|
AttrDefId::EnumVariantId(var_id) => {
|
||||||
|
|
|
@ -5,9 +5,8 @@ pub mod scope;
|
||||||
|
|
||||||
use std::{ops::Index, sync::Arc};
|
use std::{ops::Index, sync::Arc};
|
||||||
|
|
||||||
use hir_expand::{
|
use either::Either;
|
||||||
either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind,
|
use hir_expand::{hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind};
|
||||||
};
|
|
||||||
use ra_arena::{map::ArenaMap, Arena};
|
use ra_arena::{map::ArenaMap, Arena};
|
||||||
use ra_syntax::{ast, AstNode, AstPtr};
|
use ra_syntax::{ast, AstNode, AstPtr};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -210,7 +209,7 @@ impl BodySourceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
||||||
let src = node.map(|it| Either::A(AstPtr::new(it)));
|
let src = node.map(|it| Either::Left(AstPtr::new(it)));
|
||||||
self.expr_map.get(&src).cloned()
|
self.expr_map.get(&src).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +218,7 @@ impl BodySourceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
||||||
let src = node.map(|it| Either::A(AstPtr::new(it)));
|
let src = node.map(|it| Either::Left(AstPtr::new(it)));
|
||||||
self.pat_map.get(&src).cloned()
|
self.pat_map.get(&src).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
|
//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
|
||||||
//! representation.
|
//! representation.
|
||||||
|
|
||||||
use hir_expand::{
|
use either::Either;
|
||||||
either::Either,
|
use hir_expand::name::{self, AsName, Name};
|
||||||
name::{self, AsName, Name},
|
|
||||||
};
|
|
||||||
use ra_arena::Arena;
|
use ra_arena::Arena;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
|
@ -74,7 +72,7 @@ where
|
||||||
mode: BindingAnnotation::Unannotated,
|
mode: BindingAnnotation::Unannotated,
|
||||||
subpat: None,
|
subpat: None,
|
||||||
},
|
},
|
||||||
Either::B(ptr),
|
Either::Right(ptr),
|
||||||
);
|
);
|
||||||
self.body.params.push(param_pat);
|
self.body.params.push(param_pat);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +92,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
||||||
let ptr = Either::A(ptr);
|
let ptr = Either::Left(ptr);
|
||||||
let id = self.body.exprs.alloc(expr);
|
let id = self.body.exprs.alloc(expr);
|
||||||
let src = self.expander.to_source(ptr);
|
let src = self.expander.to_source(ptr);
|
||||||
self.source_map.expr_map.insert(src, id);
|
self.source_map.expr_map.insert(src, id);
|
||||||
|
@ -107,7 +105,7 @@ where
|
||||||
self.body.exprs.alloc(expr)
|
self.body.exprs.alloc(expr)
|
||||||
}
|
}
|
||||||
fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
|
fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
|
||||||
let ptr = Either::B(ptr);
|
let ptr = Either::Right(ptr);
|
||||||
let id = self.body.exprs.alloc(expr);
|
let id = self.body.exprs.alloc(expr);
|
||||||
let src = self.expander.to_source(ptr);
|
let src = self.expander.to_source(ptr);
|
||||||
self.source_map.expr_map.insert(src, id);
|
self.source_map.expr_map.insert(src, id);
|
||||||
|
@ -277,7 +275,7 @@ where
|
||||||
ast::Expr::ParenExpr(e) => {
|
ast::Expr::ParenExpr(e) => {
|
||||||
let inner = self.collect_expr_opt(e.expr());
|
let inner = self.collect_expr_opt(e.expr());
|
||||||
// make the paren expr point to the inner expression as well
|
// make the paren expr point to the inner expression as well
|
||||||
let src = self.expander.to_source(Either::A(syntax_ptr));
|
let src = self.expander.to_source(Either::Left(syntax_ptr));
|
||||||
self.source_map.expr_map.insert(src, inner);
|
self.source_map.expr_map.insert(src, inner);
|
||||||
inner
|
inner
|
||||||
}
|
}
|
||||||
|
@ -550,7 +548,7 @@ where
|
||||||
ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
|
ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
|
||||||
};
|
};
|
||||||
let ptr = AstPtr::new(&pat);
|
let ptr = AstPtr::new(&pat);
|
||||||
self.alloc_pat(pattern, Either::A(ptr))
|
self.alloc_pat(pattern, Either::Left(ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
|
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_expand::either::Either;
|
use either::Either;
|
||||||
use ra_syntax::ast;
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -46,8 +46,8 @@ impl Documentation {
|
||||||
AttrDefId::StructFieldId(it) => {
|
AttrDefId::StructFieldId(it) => {
|
||||||
let src = it.parent.child_source(db);
|
let src = it.parent.child_source(db);
|
||||||
match &src.value[it.local_id] {
|
match &src.value[it.local_id] {
|
||||||
Either::A(_tuple) => None,
|
Either::Left(_tuple) => None,
|
||||||
Either::B(record) => docs_from_ast(record),
|
Either::Right(record) => docs_from_ast(record),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AttrDefId::AdtId(it) => match it {
|
AttrDefId::AdtId(it) => match it {
|
||||||
|
|
|
@ -57,9 +57,9 @@ mod tests;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile,
|
ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId,
|
||||||
MacroDefId,
|
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use ra_arena::Arena;
|
use ra_arena::Arena;
|
||||||
|
@ -287,10 +287,10 @@ impl ModuleData {
|
||||||
) -> InFile<Either<ast::SourceFile, ast::Module>> {
|
) -> InFile<Either<ast::SourceFile, ast::Module>> {
|
||||||
if let Some(file_id) = self.definition {
|
if let Some(file_id) = self.definition {
|
||||||
let sf = db.parse(file_id).tree();
|
let sf = db.parse(file_id).tree();
|
||||||
return InFile::new(file_id.into(), Either::A(sf));
|
return InFile::new(file_id.into(), Either::Left(sf));
|
||||||
}
|
}
|
||||||
let decl = self.declaration.unwrap();
|
let decl = self.declaration.unwrap();
|
||||||
InFile::new(decl.file_id, Either::B(decl.to_node(db)))
|
InFile::new(decl.file_id, Either::Right(decl.to_node(db)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
use std::{ops::Index, sync::Arc};
|
use std::{ops::Index, sync::Arc};
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
ast_id_map::AstIdMap,
|
ast_id_map::AstIdMap,
|
||||||
db::AstDatabase,
|
db::AstDatabase,
|
||||||
either::Either,
|
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
};
|
};
|
||||||
|
@ -324,7 +324,7 @@ impl RawItemsCollector {
|
||||||
is_extern_crate: false,
|
is_extern_crate: false,
|
||||||
is_macro_use: false,
|
is_macro_use: false,
|
||||||
};
|
};
|
||||||
buf.push((import_data, Either::A(AstPtr::new(use_tree))));
|
buf.push((import_data, Either::Left(AstPtr::new(use_tree))));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
for (import_data, ptr) in buf {
|
for (import_data, ptr) in buf {
|
||||||
|
@ -355,7 +355,7 @@ impl RawItemsCollector {
|
||||||
current_module,
|
current_module,
|
||||||
attrs,
|
attrs,
|
||||||
import_data,
|
import_data,
|
||||||
Either::B(AstPtr::new(&extern_crate)),
|
Either::Right(AstPtr::new(&extern_crate)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use std::{iter, sync::Arc};
|
use std::{iter, sync::Arc};
|
||||||
|
|
||||||
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
either::Either,
|
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
name::{self, AsName, Name},
|
name::{self, AsName, Name},
|
||||||
};
|
};
|
||||||
|
@ -111,7 +111,7 @@ impl Path {
|
||||||
ast::PathSegmentKind::Name(name_ref) => {
|
ast::PathSegmentKind::Name(name_ref) => {
|
||||||
// FIXME: this should just return name
|
// FIXME: this should just return name
|
||||||
match hygiene.name_ref_to_name(name_ref) {
|
match hygiene.name_ref_to_name(name_ref) {
|
||||||
Either::A(name) => {
|
Either::Left(name) => {
|
||||||
let args = segment
|
let args = segment
|
||||||
.type_arg_list()
|
.type_arg_list()
|
||||||
.and_then(GenericArgs::from_ast)
|
.and_then(GenericArgs::from_ast)
|
||||||
|
@ -125,7 +125,7 @@ impl Path {
|
||||||
let segment = PathSegment { name, args_and_bindings: args };
|
let segment = PathSegment { name, args_and_bindings: args };
|
||||||
segments.push(segment);
|
segments.push(segment);
|
||||||
}
|
}
|
||||||
Either::B(crate_id) => {
|
Either::Right(crate_id) => {
|
||||||
kind = PathKind::DollarCrate(crate_id);
|
kind = PathKind::DollarCrate(crate_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ fn convert_path(prefix: Option<Path>, path: ast::Path, hygiene: &Hygiene) -> Opt
|
||||||
let res = match segment.kind()? {
|
let res = match segment.kind()? {
|
||||||
ast::PathSegmentKind::Name(name_ref) => {
|
ast::PathSegmentKind::Name(name_ref) => {
|
||||||
match hygiene.name_ref_to_name(name_ref) {
|
match hygiene.name_ref_to_name(name_ref) {
|
||||||
Either::A(name) => {
|
Either::Left(name) => {
|
||||||
// no type args in use
|
// no type args in use
|
||||||
let mut res = prefix.unwrap_or_else(|| Path {
|
let mut res = prefix.unwrap_or_else(|| Path {
|
||||||
kind: PathKind::Plain,
|
kind: PathKind::Plain,
|
||||||
|
@ -359,7 +359,7 @@ fn convert_path(prefix: Option<Path>, path: ast::Path, hygiene: &Hygiene) -> Opt
|
||||||
});
|
});
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
Either::B(crate_id) => {
|
Either::Right(crate_id) => {
|
||||||
return Some(Path::from_simple_segments(
|
return Some(Path::from_simple_segments(
|
||||||
PathKind::DollarCrate(crate_id),
|
PathKind::DollarCrate(crate_id),
|
||||||
iter::empty(),
|
iter::empty(),
|
||||||
|
|
|
@ -9,6 +9,7 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
|
either = "1.5"
|
||||||
|
|
||||||
ra_arena = { path = "../ra_arena" }
|
ra_arena = { path = "../ra_arena" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
//! FIXME: write short doc here
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub enum Either<A, B> {
|
|
||||||
A(A),
|
|
||||||
B(B),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A, B> Either<A, B> {
|
|
||||||
pub fn either<R, F1, F2>(self, f1: F1, f2: F2) -> R
|
|
||||||
where
|
|
||||||
F1: FnOnce(A) -> R,
|
|
||||||
F2: FnOnce(B) -> R,
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
Either::A(a) => f1(a),
|
|
||||||
Either::B(b) => f2(b),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V>
|
|
||||||
where
|
|
||||||
F1: FnOnce(A) -> U,
|
|
||||||
F2: FnOnce(B) -> V,
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
Either::A(a) => Either::A(f1(a)),
|
|
||||||
Either::B(b) => Either::B(f2(b)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn map_a<U, F>(self, f: F) -> Either<U, B>
|
|
||||||
where
|
|
||||||
F: FnOnce(A) -> U,
|
|
||||||
{
|
|
||||||
self.map(f, |it| it)
|
|
||||||
}
|
|
||||||
pub fn a(self) -> Option<A> {
|
|
||||||
match self {
|
|
||||||
Either::A(it) => Some(it),
|
|
||||||
Either::B(_) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn b(self) -> Option<B> {
|
|
||||||
match self {
|
|
||||||
Either::A(_) => None,
|
|
||||||
Either::B(it) => Some(it),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn as_ref(&self) -> Either<&A, &B> {
|
|
||||||
match self {
|
|
||||||
Either::A(it) => Either::A(it),
|
|
||||||
Either::B(it) => Either::B(it),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,12 +2,12 @@
|
||||||
//!
|
//!
|
||||||
//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
|
//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
|
||||||
//! this moment, this is horribly incomplete and handles only `$crate`.
|
//! this moment, this is horribly incomplete and handles only `$crate`.
|
||||||
|
use either::Either;
|
||||||
use ra_db::CrateId;
|
use ra_db::CrateId;
|
||||||
use ra_syntax::ast;
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::AstDatabase,
|
db::AstDatabase,
|
||||||
either::Either,
|
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
HirFileId, HirFileIdRepr, MacroDefKind,
|
HirFileId, HirFileIdRepr, MacroDefKind,
|
||||||
};
|
};
|
||||||
|
@ -41,9 +41,9 @@ impl Hygiene {
|
||||||
pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
|
pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
|
||||||
if let Some(def_crate) = self.def_crate {
|
if let Some(def_crate) = self.def_crate {
|
||||||
if name_ref.text() == "$crate" {
|
if name_ref.text() == "$crate" {
|
||||||
return Either::B(def_crate);
|
return Either::Right(def_crate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Either::A(name_ref.as_name())
|
Either::Left(name_ref.as_name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod ast_id_map;
|
pub mod ast_id_map;
|
||||||
pub mod either;
|
|
||||||
pub mod name;
|
pub mod name;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
pub mod diagnostics;
|
pub mod diagnostics;
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
let (_, source_map) = db.body_with_source_map(self.func.into());
|
let (_, source_map) = db.body_with_source_map(self.func.into());
|
||||||
|
|
||||||
if let Some(source_ptr) = source_map.expr_syntax(id) {
|
if let Some(source_ptr) = source_map.expr_syntax(id) {
|
||||||
if let Some(expr) = source_ptr.value.a() {
|
if let Some(expr) = source_ptr.value.left() {
|
||||||
let root = source_ptr.file_syntax(db);
|
let root = source_ptr.file_syntax(db);
|
||||||
if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
|
if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
|
||||||
if let Some(field_list) = record_lit.record_field_list() {
|
if let Some(field_list) = record_lit.record_field_list() {
|
||||||
|
@ -142,7 +142,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
let (_, source_map) = db.body_with_source_map(self.func.into());
|
let (_, source_map) = db.body_with_source_map(self.func.into());
|
||||||
|
|
||||||
if let Some(source_ptr) = source_map.expr_syntax(id) {
|
if let Some(source_ptr) = source_map.expr_syntax(id) {
|
||||||
if let Some(expr) = source_ptr.value.a() {
|
if let Some(expr) = source_ptr.value.left() {
|
||||||
self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
|
self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ doctest = false
|
||||||
wasm = []
|
wasm = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
either = "1.5"
|
||||||
format-buf = "1.0.0"
|
format-buf = "1.0.0"
|
||||||
itertools = "0.8.0"
|
itertools = "0.8.0"
|
||||||
join_to_string = "0.1.3"
|
join_to_string = "0.1.3"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use hir::{Adt, Either, HasSource, PathResolution};
|
use either::Either;
|
||||||
|
use hir::{Adt, HasSource, PathResolution};
|
||||||
use ra_syntax::AstNode;
|
use ra_syntax::AstNode;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
if Some(module) == ctx.module {
|
if Some(module) == ctx.module {
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
if let Either::A(use_tree) = import.source(ctx.db).value {
|
if let Either::Left(use_tree) = import.source(ctx.db).value {
|
||||||
if use_tree.syntax().text_range().contains_inclusive(ctx.offset) {
|
if use_tree.syntax().text_range().contains_inclusive(ctx.offset) {
|
||||||
// for `use self::foo<|>`, don't suggest `foo` as a completion
|
// for `use self::foo<|>`, don't suggest `foo` as a completion
|
||||||
tested_by!(dont_complete_current_use);
|
tested_by!(dont_complete_current_use);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource};
|
use either::Either;
|
||||||
|
use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource};
|
||||||
use ra_db::{FileId, SourceDatabase};
|
use ra_db::{FileId, SourceDatabase};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, DocCommentsOwner, NameOwner},
|
ast::{self, DocCommentsOwner, NameOwner},
|
||||||
|
@ -342,10 +343,10 @@ impl ToNav for hir::Local {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||||
let src = self.source(db);
|
let src = self.source(db);
|
||||||
let (full_range, focus_range) = match src.value {
|
let (full_range, focus_range) = match src.value {
|
||||||
Either::A(it) => {
|
Either::Left(it) => {
|
||||||
(it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
|
(it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
|
||||||
}
|
}
|
||||||
Either::B(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
|
Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
|
||||||
};
|
};
|
||||||
let name = match self.name(db) {
|
let name = match self.name(db) {
|
||||||
Some(it) => it.to_string().into(),
|
Some(it) => it.to_string().into(),
|
||||||
|
|
Loading…
Reference in a new issue