diff options
Diffstat (limited to 'crates')
22 files changed, 343 insertions, 80 deletions
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index c7e0d0f0f..21a37c7bf 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml | |||
@@ -7,7 +7,7 @@ publish = false | |||
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | pico-args = "0.3.0" | 9 | pico-args = "0.3.0" |
10 | flexi_logger = "0.14.0" | 10 | env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] } |
11 | 11 | ||
12 | ra_syntax = { path = "../ra_syntax" } | 12 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_ide = { path = "../ra_ide" } | 13 | ra_ide = { path = "../ra_ide" } |
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index fe847e611..3808590ab 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -7,7 +7,6 @@ mod progress_report; | |||
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read}; | 8 | use std::{error::Error, fmt::Write, io::Read}; |
9 | 9 | ||
10 | use flexi_logger::Logger; | ||
11 | use pico_args::Arguments; | 10 | use pico_args::Arguments; |
12 | use ra_ide::{file_structure, Analysis}; | 11 | use ra_ide::{file_structure, Analysis}; |
13 | use ra_prof::profile; | 12 | use ra_prof::profile; |
@@ -32,7 +31,7 @@ impl Verbosity { | |||
32 | } | 31 | } |
33 | 32 | ||
34 | fn main() -> Result<()> { | 33 | fn main() -> Result<()> { |
35 | Logger::with_env_or_str("error").start()?; | 34 | env_logger::try_init()?; |
36 | 35 | ||
37 | let subcommand = match std::env::args_os().nth(1) { | 36 | let subcommand = match std::env::args_os().nth(1) { |
38 | None => { | 37 | None => { |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 331736cb2..be1eaa523 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -429,10 +429,19 @@ where | |||
429 | let index = self.collect_expr_opt(e.index()); | 429 | let index = self.collect_expr_opt(e.index()); |
430 | self.alloc_expr(Expr::Index { base, index }, syntax_ptr) | 430 | self.alloc_expr(Expr::Index { base, index }, syntax_ptr) |
431 | } | 431 | } |
432 | ast::Expr::RangeExpr(e) => { | ||
433 | let lhs = e.start().map(|lhs| self.collect_expr(lhs)); | ||
434 | let rhs = e.end().map(|rhs| self.collect_expr(rhs)); | ||
435 | match e.op_kind() { | ||
436 | Some(range_type) => { | ||
437 | self.alloc_expr(Expr::Range { lhs, rhs, range_type }, syntax_ptr) | ||
438 | } | ||
439 | None => self.alloc_expr(Expr::Missing, syntax_ptr), | ||
440 | } | ||
441 | } | ||
432 | 442 | ||
433 | // FIXME implement HIR for these: | 443 | // FIXME implement HIR for these: |
434 | ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 444 | ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
435 | ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | ||
436 | ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) { | 445 | ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) { |
437 | Some((mark, expansion)) => { | 446 | Some((mark, expansion)) => { |
438 | let id = self.collect_expr(expansion); | 447 | let id = self.collect_expr(expansion); |
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs index 04c1d8f69..6fad80a8d 100644 --- a/crates/ra_hir_def/src/expr.rs +++ b/crates/ra_hir_def/src/expr.rs | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | use hir_expand::name::Name; | 15 | use hir_expand::name::Name; |
16 | use ra_arena::{impl_arena_id, RawId}; | 16 | use ra_arena::{impl_arena_id, RawId}; |
17 | use ra_syntax::ast::RangeOp; | ||
17 | 18 | ||
18 | use crate::{ | 19 | use crate::{ |
19 | builtin_type::{BuiltinFloat, BuiltinInt}, | 20 | builtin_type::{BuiltinFloat, BuiltinInt}, |
@@ -130,6 +131,11 @@ pub enum Expr { | |||
130 | rhs: ExprId, | 131 | rhs: ExprId, |
131 | op: Option<BinaryOp>, | 132 | op: Option<BinaryOp>, |
132 | }, | 133 | }, |
134 | Range { | ||
135 | lhs: Option<ExprId>, | ||
136 | rhs: Option<ExprId>, | ||
137 | range_type: RangeOp, | ||
138 | }, | ||
133 | Index { | 139 | Index { |
134 | base: ExprId, | 140 | base: ExprId, |
135 | index: ExprId, | 141 | index: ExprId, |
@@ -288,6 +294,14 @@ impl Expr { | |||
288 | f(*lhs); | 294 | f(*lhs); |
289 | f(*rhs); | 295 | f(*rhs); |
290 | } | 296 | } |
297 | Expr::Range { lhs, rhs, .. } => { | ||
298 | if let Some(lhs) = rhs { | ||
299 | f(*lhs); | ||
300 | } | ||
301 | if let Some(rhs) = lhs { | ||
302 | f(*rhs); | ||
303 | } | ||
304 | } | ||
291 | Expr::Index { base, index } => { | 305 | Expr::Index { base, index } => { |
292 | f(*base); | 306 | f(*base); |
293 | f(*index); | 307 | f(*index); |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 10688df4d..ff252fe44 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -409,6 +409,36 @@ pub mod known { | |||
409 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY_TYPE]) | 409 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY_TYPE]) |
410 | } | 410 | } |
411 | 411 | ||
412 | pub fn std_ops_range() -> Path { | ||
413 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TYPE]) | ||
414 | } | ||
415 | |||
416 | pub fn std_ops_range_from() -> Path { | ||
417 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FROM_TYPE]) | ||
418 | } | ||
419 | |||
420 | pub fn std_ops_range_full() -> Path { | ||
421 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_FULL_TYPE]) | ||
422 | } | ||
423 | |||
424 | pub fn std_ops_range_inclusive() -> Path { | ||
425 | Path::from_simple_segments( | ||
426 | PathKind::Abs, | ||
427 | vec![name::STD, name::OPS, name::RANGE_INCLUSIVE_TYPE], | ||
428 | ) | ||
429 | } | ||
430 | |||
431 | pub fn std_ops_range_to() -> Path { | ||
432 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::RANGE_TO_TYPE]) | ||
433 | } | ||
434 | |||
435 | pub fn std_ops_range_to_inclusive() -> Path { | ||
436 | Path::from_simple_segments( | ||
437 | PathKind::Abs, | ||
438 | vec![name::STD, name::OPS, name::RANGE_TO_INCLUSIVE_TYPE], | ||
439 | ) | ||
440 | } | ||
441 | |||
412 | pub fn std_result_result() -> Path { | 442 | pub fn std_result_result() -> Path { |
413 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE]) | 443 | Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE]) |
414 | } | 444 | } |
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs index 7824489d7..05ba37070 100644 --- a/crates/ra_hir_expand/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -140,6 +140,12 @@ pub const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); | |||
140 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); | 140 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); |
141 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); | 141 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); |
142 | pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); | 142 | pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); |
143 | pub const RANGE_FROM_TYPE: Name = Name::new_inline_ascii(9, b"RangeFrom"); | ||
144 | pub const RANGE_FULL_TYPE: Name = Name::new_inline_ascii(9, b"RangeFull"); | ||
145 | pub const RANGE_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(14, b"RangeInclusive"); | ||
146 | pub const RANGE_TO_INCLUSIVE_TYPE: Name = Name::new_inline_ascii(16, b"RangeToInclusive"); | ||
147 | pub const RANGE_TO_TYPE: Name = Name::new_inline_ascii(7, b"RangeTo"); | ||
148 | pub const RANGE_TYPE: Name = Name::new_inline_ascii(5, b"Range"); | ||
143 | 149 | ||
144 | // Builtin Macros | 150 | // Builtin Macros |
145 | pub const FILE_MACRO: Name = Name::new_inline_ascii(4, b"file"); | 151 | pub const FILE_MACRO: Name = Name::new_inline_ascii(4, b"file"); |
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index 9ce154593..222a36a9f 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -11,7 +11,7 @@ use ra_db::{salsa, CrateId}; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | method_resolution::CrateImplBlocks, | 12 | method_resolution::CrateImplBlocks, |
13 | traits::{AssocTyValue, Impl}, | 13 | traits::{AssocTyValue, Impl}, |
14 | CallableDef, FnSig, GenericPredicate, ImplTy, InferenceResult, Substs, Ty, TyDefId, TypeCtor, | 14 | CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, TraitRef, Ty, TyDefId, TypeCtor, |
15 | ValueTyDefId, | 15 | ValueTyDefId, |
16 | }; | 16 | }; |
17 | 17 | ||
@@ -22,13 +22,18 @@ pub trait HirDatabase: DefDatabase { | |||
22 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | 22 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; |
23 | 23 | ||
24 | #[salsa::invoke(crate::lower::ty_query)] | 24 | #[salsa::invoke(crate::lower::ty_query)] |
25 | #[salsa::cycle(crate::lower::ty_recover)] | ||
25 | fn ty(&self, def: TyDefId) -> Ty; | 26 | fn ty(&self, def: TyDefId) -> Ty; |
26 | 27 | ||
27 | #[salsa::invoke(crate::lower::value_ty_query)] | 28 | #[salsa::invoke(crate::lower::value_ty_query)] |
28 | fn value_ty(&self, def: ValueTyDefId) -> Ty; | 29 | fn value_ty(&self, def: ValueTyDefId) -> Ty; |
29 | 30 | ||
30 | #[salsa::invoke(crate::lower::impl_ty_query)] | 31 | #[salsa::invoke(crate::lower::impl_self_ty_query)] |
31 | fn impl_ty(&self, def: ImplId) -> ImplTy; | 32 | #[salsa::cycle(crate::lower::impl_self_ty_recover)] |
33 | fn impl_self_ty(&self, def: ImplId) -> Ty; | ||
34 | |||
35 | #[salsa::invoke(crate::lower::impl_trait_query)] | ||
36 | fn impl_trait(&self, def: ImplId) -> Option<TraitRef>; | ||
32 | 37 | ||
33 | #[salsa::invoke(crate::lower::field_types_query)] | 38 | #[salsa::invoke(crate::lower::field_types_query)] |
34 | fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>; | 39 | fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Ty>>; |
@@ -37,6 +42,7 @@ pub trait HirDatabase: DefDatabase { | |||
37 | fn callable_item_signature(&self, def: CallableDef) -> FnSig; | 42 | fn callable_item_signature(&self, def: CallableDef) -> FnSig; |
38 | 43 | ||
39 | #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] | 44 | #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] |
45 | #[salsa::cycle(crate::lower::generic_predicates_for_param_recover)] | ||
40 | fn generic_predicates_for_param( | 46 | fn generic_predicates_for_param( |
41 | &self, | 47 | &self, |
42 | def: GenericDefId, | 48 | def: GenericDefId, |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index f6283ab6d..fe259371f 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -577,6 +577,42 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
577 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 577 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
578 | Some(struct_.into()) | 578 | Some(struct_.into()) |
579 | } | 579 | } |
580 | |||
581 | fn resolve_range_full(&self) -> Option<AdtId> { | ||
582 | let path = known::std_ops_range_full(); | ||
583 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
584 | Some(struct_.into()) | ||
585 | } | ||
586 | |||
587 | fn resolve_range(&self) -> Option<AdtId> { | ||
588 | let path = known::std_ops_range(); | ||
589 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
590 | Some(struct_.into()) | ||
591 | } | ||
592 | |||
593 | fn resolve_range_inclusive(&self) -> Option<AdtId> { | ||
594 | let path = known::std_ops_range_inclusive(); | ||
595 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
596 | Some(struct_.into()) | ||
597 | } | ||
598 | |||
599 | fn resolve_range_from(&self) -> Option<AdtId> { | ||
600 | let path = known::std_ops_range_from(); | ||
601 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
602 | Some(struct_.into()) | ||
603 | } | ||
604 | |||
605 | fn resolve_range_to(&self) -> Option<AdtId> { | ||
606 | let path = known::std_ops_range_to(); | ||
607 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
608 | Some(struct_.into()) | ||
609 | } | ||
610 | |||
611 | fn resolve_range_to_inclusive(&self) -> Option<AdtId> { | ||
612 | let path = known::std_ops_range_to_inclusive(); | ||
613 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | ||
614 | Some(struct_.into()) | ||
615 | } | ||
580 | } | 616 | } |
581 | 617 | ||
582 | /// The ID of a type variable. | 618 | /// The ID of a type variable. |
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 719a0f395..064993d34 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -8,7 +8,7 @@ use hir_def::{lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutabilit | |||
8 | use rustc_hash::FxHashMap; | 8 | use rustc_hash::FxHashMap; |
9 | use test_utils::tested_by; | 9 | use test_utils::tested_by; |
10 | 10 | ||
11 | use crate::{autoderef, db::HirDatabase, ImplTy, Substs, Ty, TypeCtor, TypeWalk}; | 11 | use crate::{autoderef, db::HirDatabase, Substs, Ty, TypeCtor, TypeWalk}; |
12 | 12 | ||
13 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; | 13 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; |
14 | 14 | ||
@@ -54,10 +54,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
54 | impls | 54 | impls |
55 | .iter() | 55 | .iter() |
56 | .filter_map(|&impl_id| { | 56 | .filter_map(|&impl_id| { |
57 | let trait_ref = match db.impl_ty(impl_id) { | 57 | let trait_ref = db.impl_trait(impl_id)?; |
58 | ImplTy::TraitRef(it) => it, | ||
59 | ImplTy::Inherent(_) => return None, | ||
60 | }; | ||
61 | 58 | ||
62 | // `CoerseUnsized` has one generic parameter for the target type. | 59 | // `CoerseUnsized` has one generic parameter for the target type. |
63 | let cur_from_ty = trait_ref.substs.0.get(0)?; | 60 | let cur_from_ty = trait_ref.substs.0.get(0)?; |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 2f9ca4bbb..4014f4732 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -12,6 +12,7 @@ use hir_def::{ | |||
12 | AdtId, ContainerId, Lookup, StructFieldId, | 12 | AdtId, ContainerId, Lookup, StructFieldId, |
13 | }; | 13 | }; |
14 | use hir_expand::name::{self, Name}; | 14 | use hir_expand::name::{self, Name}; |
15 | use ra_syntax::ast::RangeOp; | ||
15 | 16 | ||
16 | use crate::{ | 17 | use crate::{ |
17 | autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data, | 18 | autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data, |
@@ -415,6 +416,44 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
415 | } | 416 | } |
416 | _ => Ty::Unknown, | 417 | _ => Ty::Unknown, |
417 | }, | 418 | }, |
419 | Expr::Range { lhs, rhs, range_type } => { | ||
420 | let lhs_ty = lhs.map(|e| self.infer_expr(e, &Expectation::none())); | ||
421 | let rhs_expect = lhs_ty | ||
422 | .as_ref() | ||
423 | .map_or_else(Expectation::none, |ty| Expectation::has_type(ty.clone())); | ||
424 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); | ||
425 | match (range_type, lhs_ty, rhs_ty) { | ||
426 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { | ||
427 | Some(adt) => Ty::simple(TypeCtor::Adt(adt)), | ||
428 | None => Ty::Unknown, | ||
429 | }, | ||
430 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { | ||
431 | Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), | ||
432 | None => Ty::Unknown, | ||
433 | }, | ||
434 | (RangeOp::Inclusive, None, Some(ty)) => { | ||
435 | match self.resolve_range_to_inclusive() { | ||
436 | Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), | ||
437 | None => Ty::Unknown, | ||
438 | } | ||
439 | } | ||
440 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { | ||
441 | Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), | ||
442 | None => Ty::Unknown, | ||
443 | }, | ||
444 | (RangeOp::Inclusive, Some(_), Some(ty)) => { | ||
445 | match self.resolve_range_inclusive() { | ||
446 | Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), | ||
447 | None => Ty::Unknown, | ||
448 | } | ||
449 | } | ||
450 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { | ||
451 | Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), | ||
452 | None => Ty::Unknown, | ||
453 | }, | ||
454 | (RangeOp::Inclusive, _, None) => Ty::Unknown, | ||
455 | } | ||
456 | } | ||
418 | Expr::Index { base, index } => { | 457 | Expr::Index { base, index } => { |
419 | let _base_ty = self.infer_expr(*base, &Expectation::none()); | 458 | let _base_ty = self.infer_expr(*base, &Expectation::none()); |
420 | let _index_ty = self.infer_expr(*index, &Expectation::none()); | 459 | let _index_ty = self.infer_expr(*index, &Expectation::none()); |
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 14be66836..bbf146418 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -244,7 +244,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
244 | ContainerId::ImplId(it) => it, | 244 | ContainerId::ImplId(it) => it, |
245 | _ => return None, | 245 | _ => return None, |
246 | }; | 246 | }; |
247 | let self_ty = self.db.impl_ty(impl_id).self_type().clone(); | 247 | let self_ty = self.db.impl_self_ty(impl_id).clone(); |
248 | let self_ty_substs = self_ty.substs()?; | 248 | let self_ty_substs = self_ty.substs()?; |
249 | let actual_substs = actual_def_ty.substs()?; | 249 | let actual_substs = actual_def_ty.substs()?; |
250 | 250 | ||
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index b45c8f82f..3c1f738df 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -486,21 +486,6 @@ impl TypeWalk for TraitRef { | |||
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
489 | #[derive(Clone, PartialEq, Eq, Debug)] | ||
490 | pub enum ImplTy { | ||
491 | Inherent(Ty), | ||
492 | TraitRef(TraitRef), | ||
493 | } | ||
494 | |||
495 | impl ImplTy { | ||
496 | pub(crate) fn self_type(&self) -> &Ty { | ||
497 | match self { | ||
498 | ImplTy::Inherent(it) => it, | ||
499 | ImplTy::TraitRef(tr) => &tr.substs[0], | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | |||
504 | /// Like `generics::WherePredicate`, but with resolved types: A condition on the | 489 | /// Like `generics::WherePredicate`, but with resolved types: A condition on the |
505 | /// parameters of a generic item. | 490 | /// parameters of a generic item. |
506 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 491 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 091c60f4f..32569ac66 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -27,8 +27,8 @@ use crate::{ | |||
27 | all_super_traits, associated_type_by_name_including_super_traits, make_mut_slice, | 27 | all_super_traits, associated_type_by_name_including_super_traits, make_mut_slice, |
28 | variant_data, | 28 | variant_data, |
29 | }, | 29 | }, |
30 | FnSig, GenericPredicate, ImplTy, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, | 30 | FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, |
31 | TraitRef, Ty, TypeCtor, TypeWalk, | 31 | Ty, TypeCtor, TypeWalk, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | impl Ty { | 34 | impl Ty { |
@@ -179,7 +179,7 @@ impl Ty { | |||
179 | let name = resolved_segment.name.clone(); | 179 | let name = resolved_segment.name.clone(); |
180 | Ty::Param { idx, name } | 180 | Ty::Param { idx, name } |
181 | } | 181 | } |
182 | TypeNs::SelfType(impl_id) => db.impl_ty(impl_id).self_type().clone(), | 182 | TypeNs::SelfType(impl_id) => db.impl_self_ty(impl_id).clone(), |
183 | TypeNs::AdtSelfType(adt) => db.ty(adt.into()), | 183 | TypeNs::AdtSelfType(adt) => db.ty(adt.into()), |
184 | 184 | ||
185 | TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()), | 185 | TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()), |
@@ -532,6 +532,15 @@ pub(crate) fn generic_predicates_for_param_query( | |||
532 | .collect() | 532 | .collect() |
533 | } | 533 | } |
534 | 534 | ||
535 | pub(crate) fn generic_predicates_for_param_recover( | ||
536 | _db: &impl HirDatabase, | ||
537 | _cycle: &[String], | ||
538 | _def: &GenericDefId, | ||
539 | _param_idx: &u32, | ||
540 | ) -> Arc<[GenericPredicate]> { | ||
541 | Arc::new([]) | ||
542 | } | ||
543 | |||
535 | impl TraitEnvironment { | 544 | impl TraitEnvironment { |
536 | pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { | 545 | pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { |
537 | let predicates = resolver | 546 | let predicates = resolver |
@@ -733,6 +742,11 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Ty { | |||
733 | TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), | 742 | TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), |
734 | } | 743 | } |
735 | } | 744 | } |
745 | |||
746 | pub(crate) fn ty_recover(_db: &impl HirDatabase, _cycle: &[String], _def: &TyDefId) -> Ty { | ||
747 | Ty::Unknown | ||
748 | } | ||
749 | |||
736 | pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty { | 750 | pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty { |
737 | match def { | 751 | match def { |
738 | ValueTyDefId::FunctionId(it) => type_for_fn(db, it), | 752 | ValueTyDefId::FunctionId(it) => type_for_fn(db, it), |
@@ -743,17 +757,24 @@ pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty { | |||
743 | } | 757 | } |
744 | } | 758 | } |
745 | 759 | ||
746 | pub(crate) fn impl_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> ImplTy { | 760 | pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Ty { |
747 | let impl_data = db.impl_data(impl_id); | 761 | let impl_data = db.impl_data(impl_id); |
748 | let resolver = impl_id.resolver(db); | 762 | let resolver = impl_id.resolver(db); |
749 | let self_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | 763 | Ty::from_hir(db, &resolver, &impl_data.target_type) |
750 | match impl_data.target_trait.as_ref() { | 764 | } |
751 | Some(trait_ref) => { | 765 | |
752 | match TraitRef::from_hir(db, &resolver, trait_ref, Some(self_ty.clone())) { | 766 | pub(crate) fn impl_self_ty_recover( |
753 | Some(it) => ImplTy::TraitRef(it), | 767 | _db: &impl HirDatabase, |
754 | None => ImplTy::Inherent(self_ty), | 768 | _cycle: &[String], |
755 | } | 769 | _impl_id: &ImplId, |
756 | } | 770 | ) -> Ty { |
757 | None => ImplTy::Inherent(self_ty), | 771 | Ty::Unknown |
758 | } | 772 | } |
773 | |||
774 | pub(crate) fn impl_trait_query(db: &impl HirDatabase, impl_id: ImplId) -> Option<TraitRef> { | ||
775 | let impl_data = db.impl_data(impl_id); | ||
776 | let resolver = impl_id.resolver(db); | ||
777 | let self_ty = db.impl_self_ty(impl_id); | ||
778 | let target_trait = impl_data.target_trait.as_ref()?; | ||
779 | TraitRef::from_hir(db, &resolver, target_trait, Some(self_ty.clone())) | ||
759 | } | 780 | } |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index ee1936b0e..2bded3dbd 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -19,7 +19,7 @@ use crate::{ | |||
19 | db::HirDatabase, | 19 | db::HirDatabase, |
20 | primitive::{FloatBitness, Uncertain}, | 20 | primitive::{FloatBitness, Uncertain}, |
21 | utils::all_super_traits, | 21 | utils::all_super_traits, |
22 | Canonical, ImplTy, InEnvironment, TraitEnvironment, TraitRef, Ty, TypeCtor, | 22 | Canonical, InEnvironment, TraitEnvironment, TraitRef, Ty, TypeCtor, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | /// This is used as a key for indexing impls. | 25 | /// This is used as a key for indexing impls. |
@@ -58,11 +58,12 @@ impl CrateImplBlocks { | |||
58 | let crate_def_map = db.crate_def_map(krate); | 58 | let crate_def_map = db.crate_def_map(krate); |
59 | for (_module_id, module_data) in crate_def_map.modules.iter() { | 59 | for (_module_id, module_data) in crate_def_map.modules.iter() { |
60 | for &impl_id in module_data.impls.iter() { | 60 | for &impl_id in module_data.impls.iter() { |
61 | match db.impl_ty(impl_id) { | 61 | match db.impl_trait(impl_id) { |
62 | ImplTy::TraitRef(tr) => { | 62 | Some(tr) => { |
63 | res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id); | 63 | res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id); |
64 | } | 64 | } |
65 | ImplTy::Inherent(self_ty) => { | 65 | None => { |
66 | let self_ty = db.impl_self_ty(impl_id); | ||
66 | if let Some(self_ty_fp) = TyFingerprint::for_impl(&self_ty) { | 67 | if let Some(self_ty_fp) = TyFingerprint::for_impl(&self_ty) { |
67 | res.impls.entry(self_ty_fp).or_default().push(impl_id); | 68 | res.impls.entry(self_ty_fp).or_default().push(impl_id); |
68 | } | 69 | } |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 3766ab981..a3cc5cf95 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -222,6 +222,56 @@ mod collections { | |||
222 | } | 222 | } |
223 | 223 | ||
224 | #[test] | 224 | #[test] |
225 | fn infer_ranges() { | ||
226 | let (db, pos) = TestDB::with_position( | ||
227 | r#" | ||
228 | //- /main.rs crate:main deps:std | ||
229 | fn test() { | ||
230 | let a = ..; | ||
231 | let b = 1..; | ||
232 | let c = ..2u32; | ||
233 | let d = 1..2usize; | ||
234 | let e = ..=10; | ||
235 | let f = 'a'..='z'; | ||
236 | |||
237 | let t = (a, b, c, d, e, f); | ||
238 | t<|>; | ||
239 | } | ||
240 | |||
241 | //- /std.rs crate:std | ||
242 | #[prelude_import] use prelude::*; | ||
243 | mod prelude {} | ||
244 | |||
245 | pub mod ops { | ||
246 | pub struct Range<Idx> { | ||
247 | pub start: Idx, | ||
248 | pub end: Idx, | ||
249 | } | ||
250 | pub struct RangeFrom<Idx> { | ||
251 | pub start: Idx, | ||
252 | } | ||
253 | struct RangeFull; | ||
254 | pub struct RangeInclusive<Idx> { | ||
255 | start: Idx, | ||
256 | end: Idx, | ||
257 | is_empty: u8, | ||
258 | } | ||
259 | pub struct RangeTo<Idx> { | ||
260 | pub end: Idx, | ||
261 | } | ||
262 | pub struct RangeToInclusive<Idx> { | ||
263 | pub end: Idx, | ||
264 | } | ||
265 | } | ||
266 | "#, | ||
267 | ); | ||
268 | assert_eq!( | ||
269 | "(RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)", | ||
270 | type_at_pos(&db, pos), | ||
271 | ); | ||
272 | } | ||
273 | |||
274 | #[test] | ||
225 | fn infer_while_let() { | 275 | fn infer_while_let() { |
226 | let (db, pos) = TestDB::with_position( | 276 | let (db, pos) = TestDB::with_position( |
227 | r#" | 277 | r#" |
@@ -2104,7 +2154,6 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) { | |||
2104 | } | 2154 | } |
2105 | 2155 | ||
2106 | #[test] | 2156 | #[test] |
2107 | #[should_panic] // we currently can't handle this | ||
2108 | fn recursive_type_alias() { | 2157 | fn recursive_type_alias() { |
2109 | assert_snapshot!( | 2158 | assert_snapshot!( |
2110 | infer(r#" | 2159 | infer(r#" |
@@ -2113,7 +2162,10 @@ type Foo = Foo; | |||
2113 | type Bar = A<Bar>; | 2162 | type Bar = A<Bar>; |
2114 | fn test(x: Foo) {} | 2163 | fn test(x: Foo) {} |
2115 | "#), | 2164 | "#), |
2116 | @"" | 2165 | @r###" |
2166 | [59; 60) 'x': {unknown} | ||
2167 | [67; 69) '{}': () | ||
2168 | "### | ||
2117 | ) | 2169 | ) |
2118 | } | 2170 | } |
2119 | 2171 | ||
@@ -4662,10 +4714,48 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
4662 | } | 4714 | } |
4663 | 4715 | ||
4664 | #[test] | 4716 | #[test] |
4665 | // FIXME this is currently a Salsa panic; it would be nicer if it just returned | 4717 | fn trait_impl_self_ty() { |
4666 | // in Unknown, and we should be able to do that once Salsa allows us to handle | 4718 | let t = type_at( |
4667 | // the cycle. But at least it doesn't overflow for now. | 4719 | r#" |
4668 | #[should_panic] | 4720 | //- /main.rs |
4721 | trait Trait<T> { | ||
4722 | fn foo(&self); | ||
4723 | } | ||
4724 | |||
4725 | struct S; | ||
4726 | |||
4727 | impl Trait<Self> for S {} | ||
4728 | |||
4729 | fn test() { | ||
4730 | S.foo()<|>; | ||
4731 | } | ||
4732 | "#, | ||
4733 | ); | ||
4734 | assert_eq!(t, "()"); | ||
4735 | } | ||
4736 | |||
4737 | #[test] | ||
4738 | fn trait_impl_self_ty_cycle() { | ||
4739 | let t = type_at( | ||
4740 | r#" | ||
4741 | //- /main.rs | ||
4742 | trait Trait { | ||
4743 | fn foo(&self); | ||
4744 | } | ||
4745 | |||
4746 | struct S<T>; | ||
4747 | |||
4748 | impl Trait for S<Self> {} | ||
4749 | |||
4750 | fn test() { | ||
4751 | S.foo()<|>; | ||
4752 | } | ||
4753 | "#, | ||
4754 | ); | ||
4755 | assert_eq!(t, "{unknown}"); | ||
4756 | } | ||
4757 | |||
4758 | #[test] | ||
4669 | fn unselected_projection_in_trait_env_cycle_1() { | 4759 | fn unselected_projection_in_trait_env_cycle_1() { |
4670 | let t = type_at( | 4760 | let t = type_at( |
4671 | r#" | 4761 | r#" |
@@ -4686,10 +4776,6 @@ fn test<T: Trait>() where T: Trait2<T::Item> { | |||
4686 | } | 4776 | } |
4687 | 4777 | ||
4688 | #[test] | 4778 | #[test] |
4689 | // FIXME this is currently a Salsa panic; it would be nicer if it just returned | ||
4690 | // in Unknown, and we should be able to do that once Salsa allows us to handle | ||
4691 | // the cycle. But at least it doesn't overflow for now. | ||
4692 | #[should_panic] | ||
4693 | fn unselected_projection_in_trait_env_cycle_2() { | 4779 | fn unselected_projection_in_trait_env_cycle_2() { |
4694 | let t = type_at( | 4780 | let t = type_at( |
4695 | r#" | 4781 | r#" |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 35de37e6b..104346ada 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -20,8 +20,8 @@ use ra_db::salsa::{InternId, InternKey}; | |||
20 | 20 | ||
21 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; | 21 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; |
22 | use crate::{ | 22 | use crate::{ |
23 | db::HirDatabase, display::HirDisplay, ApplicationTy, GenericPredicate, ImplTy, ProjectionTy, | 23 | db::HirDatabase, display::HirDisplay, ApplicationTy, GenericPredicate, ProjectionTy, Substs, |
24 | Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 24 | TraitRef, Ty, TypeCtor, TypeWalk, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | /// This represents a trait whose name we could not resolve. | 27 | /// This represents a trait whose name we could not resolve. |
@@ -630,10 +630,7 @@ fn impl_block_datum( | |||
630 | chalk_id: chalk_ir::ImplId, | 630 | chalk_id: chalk_ir::ImplId, |
631 | impl_id: ImplId, | 631 | impl_id: ImplId, |
632 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 632 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
633 | let trait_ref = match db.impl_ty(impl_id) { | 633 | let trait_ref = db.impl_trait(impl_id)?; |
634 | ImplTy::TraitRef(it) => it, | ||
635 | ImplTy::Inherent(_) => return None, | ||
636 | }; | ||
637 | let impl_data = db.impl_data(impl_id); | 634 | let impl_data = db.impl_data(impl_id); |
638 | 635 | ||
639 | let generic_params = db.generic_params(impl_id.into()); | 636 | let generic_params = db.generic_params(impl_id.into()); |
@@ -787,11 +784,7 @@ fn type_alias_associated_ty_value( | |||
787 | _ => panic!("assoc ty value should be in impl"), | 784 | _ => panic!("assoc ty value should be in impl"), |
788 | }; | 785 | }; |
789 | 786 | ||
790 | let trait_ref = match db.impl_ty(impl_id) { | 787 | let trait_ref = db.impl_trait(impl_id).expect("assoc ty value should not exist"); // we don't return any assoc ty values if the impl'd trait can't be resolved |
791 | ImplTy::TraitRef(it) => it, | ||
792 | // we don't return any assoc ty values if the impl'd trait can't be resolved | ||
793 | ImplTy::Inherent(_) => panic!("assoc ty value should not exist"), | ||
794 | }; | ||
795 | 788 | ||
796 | let assoc_ty = db | 789 | let assoc_ty = db |
797 | .trait_data(trait_ref.trait_) | 790 | .trait_data(trait_ref.trait_) |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index ea6b354c2..b804d5f6d 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::ModuleSource; | 3 | use hir::ModuleSource; |
4 | use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt}; | 4 | use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, tokenize, AstNode, SyntaxKind, SyntaxNode}; |
6 | use ra_text_edit::TextEdit; | 6 | use ra_text_edit::TextEdit; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
@@ -17,6 +17,13 @@ pub(crate) fn rename( | |||
17 | position: FilePosition, | 17 | position: FilePosition, |
18 | new_name: &str, | 18 | new_name: &str, |
19 | ) -> Option<RangeInfo<SourceChange>> { | 19 | ) -> Option<RangeInfo<SourceChange>> { |
20 | let tokens = tokenize(new_name); | ||
21 | if tokens.len() != 1 | ||
22 | || (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE) | ||
23 | { | ||
24 | return None; | ||
25 | } | ||
26 | |||
20 | let parse = db.parse(position.file_id); | 27 | let parse = db.parse(position.file_id); |
21 | if let Some((ast_name, ast_module)) = | 28 | if let Some((ast_name, ast_module)) = |
22 | find_name_and_module_at_offset(parse.tree().syntax(), position) | 29 | find_name_and_module_at_offset(parse.tree().syntax(), position) |
@@ -124,6 +131,49 @@ mod tests { | |||
124 | }; | 131 | }; |
125 | 132 | ||
126 | #[test] | 133 | #[test] |
134 | fn test_rename_to_underscore() { | ||
135 | test_rename( | ||
136 | r#" | ||
137 | fn main() { | ||
138 | let i<|> = 1; | ||
139 | }"#, | ||
140 | "_", | ||
141 | r#" | ||
142 | fn main() { | ||
143 | let _ = 1; | ||
144 | }"#, | ||
145 | ); | ||
146 | } | ||
147 | |||
148 | #[test] | ||
149 | fn test_rename_to_raw_identifier() { | ||
150 | test_rename( | ||
151 | r#" | ||
152 | fn main() { | ||
153 | let i<|> = 1; | ||
154 | }"#, | ||
155 | "r#fn", | ||
156 | r#" | ||
157 | fn main() { | ||
158 | let r#fn = 1; | ||
159 | }"#, | ||
160 | ); | ||
161 | } | ||
162 | |||
163 | #[test] | ||
164 | fn test_rename_to_invalid_identifier() { | ||
165 | let (analysis, position) = single_file_with_position( | ||
166 | " | ||
167 | fn main() { | ||
168 | let i<|> = 1; | ||
169 | }", | ||
170 | ); | ||
171 | let new_name = "invalid!"; | ||
172 | let source_change = analysis.rename(position, new_name).unwrap(); | ||
173 | assert!(source_change.is_none()); | ||
174 | } | ||
175 | |||
176 | #[test] | ||
127 | fn test_rename_for_local() { | 177 | fn test_rename_for_local() { |
128 | test_rename( | 178 | test_rename( |
129 | r#" | 179 | r#" |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 21aef842c..41672eaff 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -13,7 +13,6 @@ relative-path = "1.0.0" | |||
13 | serde_json = "1.0.34" | 13 | serde_json = "1.0.34" |
14 | serde = { version = "1.0.83", features = ["derive"] } | 14 | serde = { version = "1.0.83", features = ["derive"] } |
15 | crossbeam-channel = "0.4" | 15 | crossbeam-channel = "0.4" |
16 | flexi_logger = "0.14.0" | ||
17 | log = "0.4.3" | 16 | log = "0.4.3" |
18 | lsp-types = { version = "0.61.0", features = ["proposed"] } | 17 | lsp-types = { version = "0.61.0", features = ["proposed"] } |
19 | rustc-hash = "1.0" | 18 | rustc-hash = "1.0" |
@@ -27,6 +26,7 @@ lsp-server = "0.3.0" | |||
27 | ra_project_model = { path = "../ra_project_model" } | 26 | ra_project_model = { path = "../ra_project_model" } |
28 | ra_prof = { path = "../ra_prof" } | 27 | ra_prof = { path = "../ra_prof" } |
29 | ra_vfs_glob = { path = "../ra_vfs_glob" } | 28 | ra_vfs_glob = { path = "../ra_vfs_glob" } |
29 | env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] } | ||
30 | 30 | ||
31 | [dev-dependencies] | 31 | [dev-dependencies] |
32 | tempfile = "3" | 32 | tempfile = "3" |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index e13c8ca14..8076a7fa5 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! `ra_lsp_server` binary | 1 | //! `ra_lsp_server` binary |
2 | 2 | ||
3 | use flexi_logger::{Duplicate, Logger}; | ||
4 | use lsp_server::Connection; | 3 | use lsp_server::Connection; |
5 | use ra_lsp_server::{show_message, Result, ServerConfig}; | 4 | use ra_lsp_server::{show_message, Result, ServerConfig}; |
6 | use ra_prof; | 5 | use ra_prof; |
@@ -14,11 +13,7 @@ fn main() -> Result<()> { | |||
14 | fn setup_logging() -> Result<()> { | 13 | fn setup_logging() -> Result<()> { |
15 | std::env::set_var("RUST_BACKTRACE", "short"); | 14 | std::env::set_var("RUST_BACKTRACE", "short"); |
16 | 15 | ||
17 | let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All); | 16 | env_logger::try_init()?; |
18 | match std::env::var("RA_LOG_DIR") { | ||
19 | Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?, | ||
20 | _ => logger.start()?, | ||
21 | }; | ||
22 | 17 | ||
23 | ra_prof::set_filter(match std::env::var("RA_PROFILE") { | 18 | ra_prof::set_filter(match std::env::var("RA_PROFILE") { |
24 | Ok(spec) => ra_prof::Filter::from_spec(&spec), | 19 | Ok(spec) => ra_prof::Filter::from_spec(&spec), |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c81fa7f67..ca47ff5e1 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -480,8 +480,6 @@ pub fn handle_prepare_rename( | |||
480 | let _p = profile("handle_prepare_rename"); | 480 | let _p = profile("handle_prepare_rename"); |
481 | let position = params.try_conv_with(&world)?; | 481 | let position = params.try_conv_with(&world)?; |
482 | 482 | ||
483 | // We support renaming references like handle_rename does. | ||
484 | // In the future we may want to reject the renaming of things like keywords here too. | ||
485 | let optional_change = world.analysis().rename(position, "dummy")?; | 483 | let optional_change = world.analysis().rename(position, "dummy")?; |
486 | let range = match optional_change { | 484 | let range = match optional_change { |
487 | None => return Ok(None), | 485 | None => return Ok(None), |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 2ba82ab05..29224cbe8 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -15,7 +15,6 @@ use tempfile::TempDir; | |||
15 | 15 | ||
16 | use crate::support::{project, Project}; | 16 | use crate::support::{project, Project}; |
17 | 17 | ||
18 | const LOG: &'static str = ""; | ||
19 | const PROFILE: &'static str = ""; | 18 | const PROFILE: &'static str = ""; |
20 | // const PROFILE: &'static str = "*@3>100"; | 19 | // const PROFILE: &'static str = "*@3>100"; |
21 | 20 | ||
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 86073b57d..d5ea52fa9 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -7,7 +7,6 @@ use std::{ | |||
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crossbeam_channel::{after, select, Receiver}; | 9 | use crossbeam_channel::{after, select, Receiver}; |
10 | use flexi_logger::Logger; | ||
11 | use lsp_server::{Connection, Message, Notification, Request}; | 10 | use lsp_server::{Connection, Message, Notification, Request}; |
12 | use lsp_types::{ | 11 | use lsp_types::{ |
13 | notification::{DidOpenTextDocument, Exit}, | 12 | notification::{DidOpenTextDocument, Exit}, |
@@ -53,7 +52,7 @@ impl<'a> Project<'a> { | |||
53 | let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); | 52 | let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); |
54 | static INIT: Once = Once::new(); | 53 | static INIT: Once = Once::new(); |
55 | INIT.call_once(|| { | 54 | INIT.call_once(|| { |
56 | let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); | 55 | let _ = env_logger::builder().is_test(true).try_init().unwrap(); |
57 | ra_prof::set_filter(if crate::PROFILE.is_empty() { | 56 | ra_prof::set_filter(if crate::PROFILE.is_empty() { |
58 | ra_prof::Filter::disabled() | 57 | ra_prof::Filter::disabled() |
59 | } else { | 58 | } else { |