Skip to content

Commit 80c03f0

Browse files
committed
Add completion for expressions
1 parent 1aa655a commit 80c03f0

4 files changed

Lines changed: 494 additions & 3 deletions

File tree

rust/rubydex/src/model/declaration.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ impl Namespace {
479479
pub fn set_singleton_class_id(&mut self, declaration_id: DeclarationId) {
480480
all_namespaces!(self, it => it.set_singleton_class_id(declaration_id));
481481
}
482+
483+
#[must_use]
484+
pub fn owner_id(&self) -> &DeclarationId {
485+
all_namespaces!(self, it => &it.owner_id)
486+
}
482487
}
483488

484489
namespace_declaration!(Class, ClassDeclaration);

rust/rubydex/src/model/graph.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,27 @@ impl Graph {
320320
name_id
321321
}
322322

323+
/// Searches for the initial attached object for an arbitrarily nested singleton class
324+
///
325+
/// # Panics
326+
///
327+
/// Only panics if we attached a singleton class to something that isn't a namespace
328+
#[must_use]
329+
pub fn attached_object<'a>(&'a self, maybe_singleton: &'a Namespace) -> &'a Namespace {
330+
let mut attached_object = maybe_singleton;
331+
332+
while matches!(attached_object, Namespace::SingletonClass(_)) {
333+
attached_object = self
334+
.declarations
335+
.get(attached_object.owner_id())
336+
.unwrap()
337+
.as_namespace()
338+
.unwrap();
339+
}
340+
341+
attached_object
342+
}
343+
323344
#[must_use]
324345
pub fn get(&self, name: &str) -> Option<Vec<&Definition>> {
325346
let declaration_id = DeclarationId::from(name);

rust/rubydex/src/model/name.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ impl ResolvedName {
157157
pub fn declaration_id(&self) -> &DeclarationId {
158158
&self.declaration_id
159159
}
160+
161+
#[must_use]
162+
pub fn nesting(&self) -> &Option<NameId> {
163+
self.name.nesting()
164+
}
160165
}
161166

162167
/// A usage of a constant name. This could be a constant reference or a definition like a class or module

0 commit comments

Comments
 (0)