From fa2ea8f494d8434da705dc0e0f047f3bd7503af9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Apr 2020 22:05:06 +0200 Subject: Fix goto definition for record patterns --- crates/ra_hir/src/semantics.rs | 4 ++++ crates/ra_hir/src/source_analyzer.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 0b477f0e9..5d6edc45c 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -195,6 +195,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.analyze(field.syntax()).resolve_record_field(self.db, field) } + pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option { + self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) + } + pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option { let sa = self.analyze(macro_call.syntax()); let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call); diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 23af400b8..0ed6d0958 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -95,6 +95,7 @@ impl SourceAnalyzer { } fn pat_id(&self, pat: &ast::Pat) -> Option { + // FIXME: macros, see `expr_id` let src = InFile { file_id: self.file_id, value: pat }; self.body_source_map.as_ref()?.node_pat(src) } @@ -167,6 +168,16 @@ impl SourceAnalyzer { Some((struct_field.into(), local)) } + pub(crate) fn resolve_record_field_pat( + &self, + _db: &dyn HirDatabase, + field: &ast::RecordFieldPat, + ) -> Option { + let pat_id = self.pat_id(&field.pat()?)?; + let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; + Some(struct_field.into()) + } + pub(crate) fn resolve_macro_call( &self, db: &dyn HirDatabase, -- cgit v1.2.3