From 36e3fc9d5413f7e6e17e82867aae1318645880a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Nov 2019 09:40:36 +0300 Subject: Rename Source::ast -> Source::value --- crates/ra_hir_expand/src/lib.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_expand/src/lib.rs') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index cfe7e6d15..6ca4bc7a3 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -166,19 +166,19 @@ impl ExpansionInfo { pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option> { assert_eq!(token.file_id, self.arg.file_id); let range = - token.ast.text_range().checked_sub(self.arg.ast.syntax().text_range().start())?; + token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?; let token_id = self.macro_arg.1.token_by_range(range)?; let token_id = self.macro_def.0.map_id_down(token_id); let range = self.exp_map.range_by_token(token_id)?; - let token = algo::find_covering_element(&self.expanded.ast, range).into_token()?; + let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; Some(self.expanded.with_ast(token)) } pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option> { - let token_id = self.exp_map.token_by_range(token.ast.text_range())?; + let token_id = self.exp_map.token_by_range(token.value.text_range())?; let (token_id, origin) = self.macro_def.0.map_id_up(token_id); let (token_map, tt) = match origin { @@ -188,8 +188,8 @@ impl ExpansionInfo { let range = token_map.range_by_token(token_id)?; let token = algo::find_covering_element( - tt.ast.syntax(), - range + tt.ast.syntax().text_range().start(), + tt.value.syntax(), + range + tt.value.syntax().text_range().start(), ) .into_token()?; Some(tt.with_ast(token)) @@ -240,30 +240,34 @@ impl AstId { } } -/// FIXME: https://github.com/matklad/with ? +/// `Source` stores a value of `T` inside a particular file/syntax tree. +/// +/// Typical usages are: +/// +/// * `Source` -- syntax node in a file +/// * `Source` -- ast node in a file +/// * `Source` -- offset in a file #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub struct Source { pub file_id: HirFileId, - // FIXME: this stores all kind of things, not only `ast`. - // There should be a better name... - pub ast: T, + pub value: T, } impl Source { - pub fn new(file_id: HirFileId, ast: T) -> Source { - Source { file_id, ast } + pub fn new(file_id: HirFileId, value: T) -> Source { + Source { file_id, value } } // Similarly, naming here is stupid... - pub fn with_ast(&self, ast: U) -> Source { - Source::new(self.file_id, ast) + pub fn with_ast(&self, value: U) -> Source { + Source::new(self.file_id, value) } pub fn map U, U>(self, f: F) -> Source { - Source::new(self.file_id, f(self.ast)) + Source::new(self.file_id, f(self.value)) } pub fn as_ref(&self) -> Source<&T> { - self.with_ast(&self.ast) + self.with_ast(&self.value) } pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { db.parse_or_expand(self.file_id).expect("source created from invalid file") -- cgit v1.2.3 From 51baaf298d4ac56036062786bf070aeab7ab8e79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Nov 2019 13:09:21 +0300 Subject: Rename with_ast -> with_value --- crates/ra_hir_expand/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_expand/src/lib.rs') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 6ca4bc7a3..1389f64ce 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -174,7 +174,7 @@ impl ExpansionInfo { let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; - Some(self.expanded.with_ast(token)) + Some(self.expanded.with_value(token)) } pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option> { @@ -192,7 +192,7 @@ impl ExpansionInfo { range + tt.value.syntax().text_range().start(), ) .into_token()?; - Some(tt.with_ast(token)) + Some(tt.with_value(token)) } } @@ -259,7 +259,7 @@ impl Source { } // Similarly, naming here is stupid... - pub fn with_ast(&self, value: U) -> Source { + pub fn with_value(&self, value: U) -> Source { Source::new(self.file_id, value) } @@ -267,7 +267,7 @@ impl Source { Source::new(self.file_id, f(self.value)) } pub fn as_ref(&self) -> Source<&T> { - self.with_ast(&self.value) + self.with_value(&self.value) } pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { db.parse_or_expand(self.file_id).expect("source created from invalid file") -- cgit v1.2.3