-
Notifications
You must be signed in to change notification settings - Fork 1
Provide resolution diagnostics (inline) #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Morriar
wants to merge
10
commits into
main
Choose a base branch
from
at-resolver-diagnostics-inline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7b20cd2
Extract `DefinitionKind`
Morriar 431a5e6
Extract `DeclarationKind`
Morriar 93a3e25
Add resolution diagnostic for kind mismatch
Morriar 808371f
Add resolution diagnostic for redefinition of parent
Morriar 2242810
Add resolution diagnostic for non-class parents
Morriar 2c485b5
Add resolution diagnostic for circular superclasses
Morriar 9b8bf6c
Add resolution diagnostic for non module mixins
Morriar 3ea1e71
Add resolution diagnostic for circular mixins
Morriar 52dc0e3
Add resolution diagnostic for unresolved constant reference
Morriar 58bf1bc
Address review comments: add TODO for retry issue, remove intermediat…
Morriar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| use crate::assert_mem_size; | ||
| use crate::diagnostic::Diagnostic; | ||
| use crate::model::{ | ||
| definitions::DefinitionKind, | ||
| identity_maps::{IdentityHashMap, IdentityHashSet}, | ||
| ids::{DeclarationId, DefinitionId, NameId, ReferenceId, StringId}, | ||
| }; | ||
|
|
@@ -54,6 +55,75 @@ impl<'a> IntoIterator for &'a Ancestors { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub enum DeclarationKind { | ||
| Class, | ||
| SingletonClass, | ||
| Module, | ||
| Todo, | ||
| Constant, | ||
| ConstantAlias, | ||
| Method, | ||
| GlobalVariable, | ||
| InstanceVariable, | ||
| ClassVariable, | ||
| } | ||
|
|
||
| impl DeclarationKind { | ||
| /// Returns the canonical `PascalCase` name used in external APIs and serialization. | ||
| #[must_use] | ||
| pub fn as_api_str(self) -> &'static str { | ||
| match self { | ||
| DeclarationKind::Class => "Class", | ||
| DeclarationKind::SingletonClass => "SingletonClass", | ||
| DeclarationKind::Module => "Module", | ||
| DeclarationKind::Constant => "Constant", | ||
| DeclarationKind::ConstantAlias => "ConstantAlias", | ||
| DeclarationKind::Method => "Method", | ||
| DeclarationKind::GlobalVariable => "GlobalVariable", | ||
| DeclarationKind::InstanceVariable => "InstanceVariable", | ||
| DeclarationKind::ClassVariable => "ClassVariable", | ||
| DeclarationKind::Todo => "<TODO>", | ||
| } | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub fn from_definition_kind(definition_kind: DefinitionKind) -> Self { | ||
| match definition_kind { | ||
| DefinitionKind::Class => DeclarationKind::Class, | ||
| DefinitionKind::SingletonClass => DeclarationKind::SingletonClass, | ||
| DefinitionKind::Module => DeclarationKind::Module, | ||
| DefinitionKind::Constant => DeclarationKind::Constant, | ||
| DefinitionKind::ConstantAlias => DeclarationKind::ConstantAlias, | ||
| DefinitionKind::Method | ||
| | DefinitionKind::MethodAlias | ||
| | DefinitionKind::AttrAccessor | ||
| | DefinitionKind::AttrReader | ||
| | DefinitionKind::AttrWriter => DeclarationKind::Method, | ||
| DefinitionKind::InstanceVariable => DeclarationKind::InstanceVariable, | ||
| DefinitionKind::ClassVariable => DeclarationKind::ClassVariable, | ||
| DefinitionKind::GlobalVariable | DefinitionKind::GlobalVariableAlias => DeclarationKind::GlobalVariable, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl std::fmt::Display for DeclarationKind { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| DeclarationKind::Class => write!(f, "class"), | ||
| DeclarationKind::SingletonClass => write!(f, "singleton class"), | ||
| DeclarationKind::Module => write!(f, "module"), | ||
| DeclarationKind::Todo => write!(f, "<TODO>"), | ||
| DeclarationKind::Constant => write!(f, "constant"), | ||
| DeclarationKind::ConstantAlias => write!(f, "constant alias"), | ||
| DeclarationKind::Method => write!(f, "method"), | ||
| DeclarationKind::GlobalVariable => write!(f, "global variable"), | ||
| DeclarationKind::InstanceVariable => write!(f, "instance variable"), | ||
| DeclarationKind::ClassVariable => write!(f, "class variable"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| macro_rules! all_declarations { | ||
| ($value:expr, $var:ident => $expr:expr) => { | ||
| match $value { | ||
|
|
@@ -264,15 +334,15 @@ impl Declaration { | |
| } | ||
|
|
||
| #[must_use] | ||
| pub fn kind(&self) -> &'static str { | ||
| pub fn kind(&self) -> DeclarationKind { | ||
| match self { | ||
| Declaration::Namespace(namespace) => namespace.kind(), | ||
| Declaration::Constant(_) => "Constant", | ||
| Declaration::ConstantAlias(_) => "ConstantAlias", | ||
| Declaration::Method(_) => "Method", | ||
| Declaration::GlobalVariable(_) => "GlobalVariable", | ||
| Declaration::InstanceVariable(_) => "InstanceVariable", | ||
| Declaration::ClassVariable(_) => "ClassVariable", | ||
| Declaration::Constant(_) => DeclarationKind::Constant, | ||
| Declaration::ConstantAlias(_) => DeclarationKind::ConstantAlias, | ||
| Declaration::Method(_) => DeclarationKind::Method, | ||
| Declaration::GlobalVariable(_) => DeclarationKind::GlobalVariable, | ||
| Declaration::InstanceVariable(_) => DeclarationKind::InstanceVariable, | ||
| Declaration::ClassVariable(_) => DeclarationKind::ClassVariable, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -362,12 +432,20 @@ impl Declaration { | |
| all_declarations!(self, it => &it.diagnostics) | ||
| } | ||
|
|
||
| pub fn diagnostics_mut(&mut self) -> &mut Vec<Diagnostic> { | ||
| all_declarations!(self, it => &mut 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)); | ||
| all_declarations!(self, it => { | ||
| if !it.diagnostics.iter().any(|d| d.rule() == diagnostic.rule() && d.uri_id() == diagnostic.uri_id() && d.offset() == diagnostic.offset()) { | ||
| it.diagnostics.push(diagnostic); | ||
| } | ||
|
Comment on lines
+445
to
+447
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be a separate PR, but I wonder if we should use a set here to avoid the duplicate check. |
||
| }); | ||
| } | ||
|
|
||
| pub fn clear_diagnostics(&mut self) { | ||
|
|
@@ -386,12 +464,12 @@ assert_mem_size!(Namespace, 16); | |
|
|
||
| impl Namespace { | ||
| #[must_use] | ||
| pub fn kind(&self) -> &'static str { | ||
| pub fn kind(&self) -> DeclarationKind { | ||
| match self { | ||
| Namespace::Class(_) => "Class", | ||
| Namespace::SingletonClass(_) => "SingletonClass", | ||
| Namespace::Module(_) => "Module", | ||
| Namespace::Todo(_) => "<TODO>", | ||
| Namespace::Class(_) => DeclarationKind::Class, | ||
| Namespace::SingletonClass(_) => DeclarationKind::SingletonClass, | ||
| Namespace::Module(_) => DeclarationKind::Module, | ||
| Namespace::Todo(_) => DeclarationKind::Todo, | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we name this
as_strinstead?