Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/rubydex-sys/src/diagnostic_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl DiagnosticArray {
pub unsafe extern "C" fn rdx_graph_diagnostics(pointer: GraphPointer) -> *mut DiagnosticArray {
with_graph(pointer, |graph| {
let entries = graph
.diagnostics()
.all_diagnostics()
.iter()
.map(|diagnostic| {
let document = graph.documents().get(diagnostic.uri_id()).unwrap();
Expand Down
10 changes: 3 additions & 7 deletions rust/rubydex/src/indexing/local_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type LocalGraphParts = (
IdentityHashMap<NameId, NameRef>,
IdentityHashMap<ReferenceId, ConstantReference>,
IdentityHashMap<ReferenceId, MethodRef>,
Vec<Diagnostic>,
);

#[derive(Debug)]
Expand All @@ -30,7 +29,6 @@ pub struct LocalGraph {
names: IdentityHashMap<NameId, NameRef>,
constant_references: IdentityHashMap<ReferenceId, ConstantReference>,
method_references: IdentityHashMap<ReferenceId, MethodRef>,
diagnostics: Vec<Diagnostic>,
}

impl LocalGraph {
Expand All @@ -44,7 +42,6 @@ impl LocalGraph {
names: IdentityHashMap::default(),
constant_references: IdentityHashMap::default(),
method_references: IdentityHashMap::default(),
diagnostics: Vec::new(),
}
}

Expand Down Expand Up @@ -149,13 +146,13 @@ impl LocalGraph {
// Diagnostics

#[must_use]
pub fn diagnostics(&self) -> &Vec<Diagnostic> {
&self.diagnostics
pub fn diagnostics(&self) -> &[Diagnostic] {
self.document.diagnostics()
}

pub fn add_diagnostic(&mut self, rule: Rule, offset: Offset, message: String) {
let diagnostic = Diagnostic::new(rule, self.uri_id, offset, message);
self.diagnostics.push(diagnostic);
self.document.add_diagnostic(diagnostic);
}

// Into parts
Expand All @@ -170,7 +167,6 @@ impl LocalGraph {
self.names,
self.constant_references,
self.method_references,
self.diagnostics,
)
}
}
39 changes: 37 additions & 2 deletions rust/rubydex/src/model/declaration.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we extend declarations (i.e.: find a second definition for the same thing), we need to ensure we're also extending the diagnostics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a fixup commit for this, but I couldn't find any tests for it, nor where it is called from. Maybe my Rust code navigation skills aren't up to scratch!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not be doing it yet, but it should happen in Graph#add_declaration.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::diagnostic::Diagnostic;
use crate::model::{
identity_maps::{IdentityHashMap, IdentityHashSet},
ids::{DeclarationId, DefinitionId, NameId, ReferenceId, StringId},
Expand Down Expand Up @@ -102,6 +103,8 @@ macro_rules! namespace_declaration {
descendants: IdentityHashSet<DeclarationId>,
/// The singleton class associated with this declaration
singleton_class_id: Option<DeclarationId>,
/// Diagnostics associated with this declaration
diagnostics: Vec<Diagnostic>,
}

impl $name {
Expand All @@ -116,13 +119,15 @@ macro_rules! namespace_declaration {
ancestors: Ancestors::Partial(Vec::new()),
descendants: IdentityHashSet::default(),
singleton_class_id: None,
diagnostics: Vec::new(),
}
}

pub fn extend(&mut self, other: Namespace) {
pub fn extend(&mut self, mut other: Namespace) {
self.definition_ids.extend(other.definitions());
self.references.extend(other.references());
self.members.extend(other.members());
self.diagnostics.extend(other.take_diagnostics());
}

pub fn set_singleton_class_id(&mut self, declaration_id: DeclarationId) {
Expand Down Expand Up @@ -205,6 +210,8 @@ macro_rules! simple_declaration {
references: IdentityHashSet<ReferenceId>,
/// The ID of the owner of this declaration
owner_id: DeclarationId,
/// Diagnostics associated with this declaration
diagnostics: Vec<Diagnostic>,
}

impl $name {
Expand All @@ -215,12 +222,14 @@ macro_rules! simple_declaration {
definition_ids: Vec::new(),
references: IdentityHashSet::default(),
owner_id,
diagnostics: Vec::new(),
}
}

pub fn extend(&mut self, other: Declaration) {
pub fn extend(&mut self, mut other: Declaration) {
self.definition_ids.extend(other.definitions());
self.references.extend(other.references());
self.diagnostics.extend(other.take_diagnostics());
}
}
};
Expand Down Expand Up @@ -339,6 +348,23 @@ impl Declaration {
after_colons.rsplit('#').next().unwrap_or(after_colons).to_string()
})
}

#[must_use]
pub fn diagnostics(&self) -> &[Diagnostic] {
all_declarations!(self, it => &it.diagnostics)
}

pub fn take_diagnostics(&mut self) -> Vec<Diagnostic> {
all_declarations!(self, it => std::mem::take(&mut it.diagnostics))
}

pub fn add_diagnostic(&mut self, diagnostic: Diagnostic) {
all_declarations!(self, it => it.diagnostics.push(diagnostic));
}

pub fn clear_diagnostics(&mut self) {
all_declarations!(self, it => it.diagnostics.clear());
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -373,6 +399,15 @@ impl Namespace {
all_namespaces!(self, it => &it.members)
}

#[must_use]
pub fn diagnostics(&self) -> &[Diagnostic] {
all_namespaces!(self, it => &it.diagnostics)
}

pub fn take_diagnostics(&mut self) -> Vec<Diagnostic> {
all_namespaces!(self, it => std::mem::take(&mut it.diagnostics))
}

/// # Panics
///
/// Panics if the declaration is not a namespace or a constant
Expand Down
Loading
Loading