aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-28 09:50:26 +0000
committerAleksey Kladov <[email protected]>2019-11-28 09:50:26 +0000
commitccd1b0800a5de5e046e6e9a4b6f49030c1ce3639 (patch)
treee878f88aebf11c0e54eff2e107dfaa4d192ab272 /crates/ra_hir_expand/src
parent2702fa1c5d6d8ad504c0d7703b6363ea09ba5570 (diff)
Rename Source -> InFile
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs4
-rw-r--r--crates/ra_hir_expand/src/lib.rs42
2 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index 3d37e9335..108c1e38c 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -18,11 +18,11 @@ use std::{any::Any, fmt};
18 18
19use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange}; 19use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange};
20 20
21use crate::{db::AstDatabase, Source}; 21use crate::{db::AstDatabase, InFile};
22 22
23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
24 fn message(&self) -> String; 24 fn message(&self) -> String;
25 fn source(&self) -> Source<SyntaxNodePtr>; 25 fn source(&self) -> InFile<SyntaxNodePtr>;
26 fn highlight_range(&self) -> TextRange { 26 fn highlight_range(&self) -> TextRange {
27 self.source().value.range() 27 self.source().value.range()
28 } 28 }
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index b6a739cda..2c5b6b2bb 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -90,9 +90,9 @@ impl HirFileId {
90 let macro_arg = db.macro_arg(macro_file.macro_call_id)?; 90 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
91 91
92 Some(ExpansionInfo { 92 Some(ExpansionInfo {
93 expanded: Source::new(self, parse.syntax_node()), 93 expanded: InFile::new(self, parse.syntax_node()),
94 arg: Source::new(loc.ast_id.file_id, arg_tt), 94 arg: InFile::new(loc.ast_id.file_id, arg_tt),
95 def: Source::new(loc.ast_id.file_id, def_tt), 95 def: InFile::new(loc.ast_id.file_id, def_tt),
96 macro_arg, 96 macro_arg,
97 macro_def, 97 macro_def,
98 exp_map, 98 exp_map,
@@ -167,9 +167,9 @@ impl MacroCallId {
167/// ExpansionInfo mainly describes how to map text range between src and expanded macro 167/// ExpansionInfo mainly describes how to map text range between src and expanded macro
168#[derive(Debug, Clone, PartialEq, Eq)] 168#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct ExpansionInfo { 169pub struct ExpansionInfo {
170 expanded: Source<SyntaxNode>, 170 expanded: InFile<SyntaxNode>,
171 arg: Source<ast::TokenTree>, 171 arg: InFile<ast::TokenTree>,
172 def: Source<ast::TokenTree>, 172 def: InFile<ast::TokenTree>,
173 173
174 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, 174 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>,
175 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, 175 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
@@ -177,7 +177,7 @@ pub struct ExpansionInfo {
177} 177}
178 178
179impl ExpansionInfo { 179impl ExpansionInfo {
180 pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { 180 pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
181 assert_eq!(token.file_id, self.arg.file_id); 181 assert_eq!(token.file_id, self.arg.file_id);
182 let range = 182 let range =
183 token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?; 183 token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?;
@@ -191,7 +191,7 @@ impl ExpansionInfo {
191 Some(self.expanded.with_value(token)) 191 Some(self.expanded.with_value(token))
192 } 192 }
193 193
194 pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { 194 pub fn map_token_up(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
195 let token_id = self.exp_map.token_by_range(token.value.text_range())?; 195 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
196 196
197 let (token_id, origin) = self.macro_def.0.map_id_up(token_id); 197 let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
@@ -254,33 +254,33 @@ impl<N: AstNode> AstId<N> {
254 } 254 }
255} 255}
256 256
257/// `Source<T>` stores a value of `T` inside a particular file/syntax tree. 257/// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
258/// 258///
259/// Typical usages are: 259/// Typical usages are:
260/// 260///
261/// * `Source<SyntaxNode>` -- syntax node in a file 261/// * `InFile<SyntaxNode>` -- syntax node in a file
262/// * `Source<ast::FnDef>` -- ast node in a file 262/// * `InFile<ast::FnDef>` -- ast node in a file
263/// * `Source<TextUnit>` -- offset in a file 263/// * `InFile<TextUnit>` -- offset in a file
264#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] 264#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
265pub struct Source<T> { 265pub struct InFile<T> {
266 pub file_id: HirFileId, 266 pub file_id: HirFileId,
267 pub value: T, 267 pub value: T,
268} 268}
269 269
270impl<T> Source<T> { 270impl<T> InFile<T> {
271 pub fn new(file_id: HirFileId, value: T) -> Source<T> { 271 pub fn new(file_id: HirFileId, value: T) -> InFile<T> {
272 Source { file_id, value } 272 InFile { file_id, value }
273 } 273 }
274 274
275 // Similarly, naming here is stupid... 275 // Similarly, naming here is stupid...
276 pub fn with_value<U>(&self, value: U) -> Source<U> { 276 pub fn with_value<U>(&self, value: U) -> InFile<U> {
277 Source::new(self.file_id, value) 277 InFile::new(self.file_id, value)
278 } 278 }
279 279
280 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { 280 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> InFile<U> {
281 Source::new(self.file_id, f(self.value)) 281 InFile::new(self.file_id, f(self.value))
282 } 282 }
283 pub fn as_ref(&self) -> Source<&T> { 283 pub fn as_ref(&self) -> InFile<&T> {
284 self.with_value(&self.value) 284 self.with_value(&self.value)
285 } 285 }
286 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { 286 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {