diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/primitive.rs | 32 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 |
4 files changed, 58 insertions, 4 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 36dc5d137..087385b98 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -9,7 +9,7 @@ use std::collections::HashMap; | |||
9 | 9 | ||
10 | use ra_db::LocalSyntaxPtr; | 10 | use ra_db::LocalSyntaxPtr; |
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | TextRange, TextUnit, | 12 | TextRange, TextUnit, SmolStr, |
13 | algo::visit::{visitor, Visitor}, | 13 | algo::visit::{visitor, Visitor}, |
14 | ast::{self, AstNode, DocCommentsOwner, NameOwner, LoopBodyOwner, ArgListOwner}, | 14 | ast::{self, AstNode, DocCommentsOwner, NameOwner, LoopBodyOwner, ArgListOwner}, |
15 | SyntaxNodeRef | 15 | SyntaxNodeRef |
@@ -148,7 +148,25 @@ impl Ty { | |||
148 | ParenType(_inner) => Ty::Unknown, // TODO | 148 | ParenType(_inner) => Ty::Unknown, // TODO |
149 | TupleType(_inner) => Ty::Unknown, // TODO | 149 | TupleType(_inner) => Ty::Unknown, // TODO |
150 | NeverType(..) => Ty::Never, | 150 | NeverType(..) => Ty::Never, |
151 | PathType(_inner) => Ty::Unknown, // TODO | 151 | PathType(inner) => { |
152 | let path = if let Some(p) = inner.path() { p } else { return Ty::Unknown }; | ||
153 | if path.qualifier().is_none() { | ||
154 | let name = path.segment().and_then(|s| s.name_ref()).map(|n| n.text()).unwrap_or(SmolStr::new("")); | ||
155 | if let Some(int_ty) = primitive::IntTy::from_string(&name) { | ||
156 | Ty::Int(int_ty) | ||
157 | } else if let Some(uint_ty) = primitive::UintTy::from_string(&name) { | ||
158 | Ty::Uint(uint_ty) | ||
159 | } else if let Some(float_ty) = primitive::FloatTy::from_string(&name) { | ||
160 | Ty::Float(float_ty) | ||
161 | } else { | ||
162 | // TODO | ||
163 | Ty::Unknown | ||
164 | } | ||
165 | } else { | ||
166 | // TODO | ||
167 | Ty::Unknown | ||
168 | } | ||
169 | }, | ||
152 | PointerType(_inner) => Ty::Unknown, // TODO | 170 | PointerType(_inner) => Ty::Unknown, // TODO |
153 | ArrayType(_inner) => Ty::Unknown, // TODO | 171 | ArrayType(_inner) => Ty::Unknown, // TODO |
154 | SliceType(_inner) => Ty::Unknown, // TODO | 172 | SliceType(_inner) => Ty::Unknown, // TODO |
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs index 4a5ce5a97..ad79b17e4 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs | |||
@@ -33,6 +33,18 @@ impl IntTy { | |||
33 | IntTy::I128 => "i128", | 33 | IntTy::I128 => "i128", |
34 | } | 34 | } |
35 | } | 35 | } |
36 | |||
37 | pub fn from_string(s: &str) -> Option<IntTy> { | ||
38 | match s { | ||
39 | "isize" => Some(IntTy::Isize), | ||
40 | "i8" => Some(IntTy::I8), | ||
41 | "i16" => Some(IntTy::I16), | ||
42 | "i32" => Some(IntTy::I32), | ||
43 | "i64" => Some(IntTy::I64), | ||
44 | "i128" => Some(IntTy::I128), | ||
45 | _ => None, | ||
46 | } | ||
47 | } | ||
36 | } | 48 | } |
37 | 49 | ||
38 | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] | 50 | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] |
@@ -56,6 +68,18 @@ impl UintTy { | |||
56 | UintTy::U128 => "u128", | 68 | UintTy::U128 => "u128", |
57 | } | 69 | } |
58 | } | 70 | } |
71 | |||
72 | pub fn from_string(s: &str) -> Option<UintTy> { | ||
73 | match s { | ||
74 | "usize" => Some(UintTy::Usize), | ||
75 | "u8" => Some(UintTy::U8), | ||
76 | "u16" => Some(UintTy::U16), | ||
77 | "u32" => Some(UintTy::U32), | ||
78 | "u64" => Some(UintTy::U64), | ||
79 | "u128" => Some(UintTy::U128), | ||
80 | _ => None, | ||
81 | } | ||
82 | } | ||
59 | } | 83 | } |
60 | 84 | ||
61 | impl fmt::Debug for UintTy { | 85 | impl fmt::Debug for UintTy { |
@@ -95,4 +119,12 @@ impl FloatTy { | |||
95 | FloatTy::F64 => "f64", | 119 | FloatTy::F64 => "f64", |
96 | } | 120 | } |
97 | } | 121 | } |
122 | |||
123 | pub fn from_string(s: &str) -> Option<FloatTy> { | ||
124 | match s { | ||
125 | "f32" => Some(FloatTy::F32), | ||
126 | "f64" => Some(FloatTy::F64), | ||
127 | _ => None, | ||
128 | } | ||
129 | } | ||
98 | } | 130 | } |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 91f27fb26..74bf4d3cc 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -2697,7 +2697,11 @@ impl<R: TreeRoot<RaTypes>> PathTypeNode<R> { | |||
2697 | } | 2697 | } |
2698 | 2698 | ||
2699 | 2699 | ||
2700 | impl<'a> PathType<'a> {} | 2700 | impl<'a> PathType<'a> { |
2701 | pub fn path(self) -> Option<Path<'a>> { | ||
2702 | super::child_opt(self) | ||
2703 | } | ||
2704 | } | ||
2701 | 2705 | ||
2702 | // PlaceholderPat | 2706 | // PlaceholderPat |
2703 | #[derive(Debug, Clone, Copy,)] | 2707 | #[derive(Debug, Clone, Copy,)] |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index c43db51b6..29b84854a 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -304,7 +304,7 @@ Grammar( | |||
304 | "ParenType": (), | 304 | "ParenType": (), |
305 | "TupleType": (), | 305 | "TupleType": (), |
306 | "NeverType": (), | 306 | "NeverType": (), |
307 | "PathType": (), | 307 | "PathType": (options: ["Path"]), |
308 | "PointerType": (), | 308 | "PointerType": (), |
309 | "ArrayType": (), | 309 | "ArrayType": (), |
310 | "SliceType": (), | 310 | "SliceType": (), |