Skip to content

Commit

Permalink
Removed Derefing of backing symbols in annotated symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Aug 17, 2024
1 parent 3c21e7f commit a917796
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 60 deletions.
66 changes: 30 additions & 36 deletions crates/analysis/src/symbol_analysis/symbols/annotated_symbols.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use shrinkwraprs::Shrinkwrap;
use witcherscript::ast::WRAPPED_METHOD_NAME;
use crate::symbol_analysis::symbol_path::SymbolPath;
use super::*;


/// Corresponding to @addMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derive(Debug, Clone)]
pub struct MemberFunctionInjectorSymbol {
pub inner: MemberFunctionSymbol
pub backer: MemberFunctionSymbol
}

impl Symbol for MemberFunctionInjectorSymbol {
Expand All @@ -17,33 +15,32 @@ impl Symbol for MemberFunctionInjectorSymbol {
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
&self.backer.path()
}
}

impl LocatableSymbol for MemberFunctionInjectorSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
&self.backer.location()
}
}

impl PrimarySymbol for MemberFunctionInjectorSymbol { }

impl MemberFunctionInjectorSymbol {
pub fn new(inner: MemberFunctionSymbol) -> Self {
pub fn new(backer: MemberFunctionSymbol) -> Self {
Self {
inner
backer
}
}
}



/// Corresponding to @replaceMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derive(Debug, Clone)]
pub struct MemberFunctionReplacerSymbol {
pub inner: MemberFunctionSymbol
pub backer: MemberFunctionSymbol
}

impl Symbol for MemberFunctionReplacerSymbol {
Expand All @@ -52,33 +49,32 @@ impl Symbol for MemberFunctionReplacerSymbol {
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
&self.backer.path()
}
}

impl LocatableSymbol for MemberFunctionReplacerSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
&self.backer.location()
}
}

impl PrimarySymbol for MemberFunctionReplacerSymbol { }

impl MemberFunctionReplacerSymbol {
pub fn new(inner: MemberFunctionSymbol) -> Self {
pub fn new(backer: MemberFunctionSymbol) -> Self {
Self {
inner
backer
}
}
}



/// Corresponding to @replaceMethod functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derive(Debug, Clone)]
pub struct GlobalFunctionReplacerSymbol {
pub inner: GlobalFunctionSymbol
pub backer: GlobalFunctionSymbol
}

impl Symbol for GlobalFunctionReplacerSymbol {
Expand All @@ -87,33 +83,32 @@ impl Symbol for GlobalFunctionReplacerSymbol {
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
&self.backer.path()
}
}

impl LocatableSymbol for GlobalFunctionReplacerSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
&self.backer.location()
}
}

impl PrimarySymbol for GlobalFunctionReplacerSymbol { }

impl GlobalFunctionReplacerSymbol {
pub fn new(inner: GlobalFunctionSymbol) -> Self {
pub fn new(backer: GlobalFunctionSymbol) -> Self {
Self {
inner
backer
}
}
}



/// Corresponding to @wrapMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derive(Debug, Clone)]
pub struct MemberFunctionWrapperSymbol {
pub inner: MemberFunctionSymbol
pub backer: MemberFunctionSymbol
}

impl Symbol for MemberFunctionWrapperSymbol {
Expand All @@ -122,22 +117,22 @@ impl Symbol for MemberFunctionWrapperSymbol {
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
&self.backer.path()
}
}

impl LocatableSymbol for MemberFunctionWrapperSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
&self.backer.location()
}
}

impl PrimarySymbol for MemberFunctionWrapperSymbol { }

impl MemberFunctionWrapperSymbol {
pub fn new(inner: MemberFunctionSymbol) -> Self {
pub fn new(backer: MemberFunctionSymbol) -> Self {
Self {
inner
backer
}
}
}
Expand Down Expand Up @@ -176,10 +171,9 @@ impl WrappedMethodSymbol {


/// Corresponding to @addField(Class) vars
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derive(Debug, Clone)]
pub struct MemberVarInjectorSymbol {
pub inner: MemberVarSymbol
pub backer: MemberVarSymbol
}

impl Symbol for MemberVarInjectorSymbol {
Expand All @@ -188,22 +182,22 @@ impl Symbol for MemberVarInjectorSymbol {
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
&self.backer.path()
}
}

impl LocatableSymbol for MemberVarInjectorSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
&self.backer.location()
}
}

impl PrimarySymbol for MemberVarInjectorSymbol { }

impl MemberVarInjectorSymbol {
pub fn new(inner: MemberVarSymbol) -> Self {
pub fn new(backer: MemberVarSymbol) -> Self {
Self {
inner
backer
}
}
}
12 changes: 6 additions & 6 deletions crates/analysis/src/utils/visitors/expr_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ impl<'a> ExpressionEvaluator<'a> {
},
SymbolVariant::ParentVar(s) => s.type_path().to_owned(),
SymbolVariant::VirtualParentVar(s) => s.type_path().to_owned(),
SymbolVariant::MemberFuncInjector(s) => s.return_type_path.clone().into(),
SymbolVariant::MemberFuncReplacer(s) => s.return_type_path.clone().into(),
SymbolVariant::GlobalFuncReplacer(s) => s.return_type_path.clone().into(),
SymbolVariant::MemberFuncWrapper(s) => s.return_type_path.clone().into(),
SymbolVariant::MemberVarInjector(s) => s.type_path.clone().into(),
SymbolVariant::MemberFuncInjector(s) => s.backer.return_type_path.clone().into(),
SymbolVariant::MemberFuncReplacer(s) => s.backer.return_type_path.clone().into(),
SymbolVariant::GlobalFuncReplacer(s) => s.backer.return_type_path.clone().into(),
SymbolVariant::MemberFuncWrapper(s) => s.backer.return_type_path.clone().into(),
SymbolVariant::MemberVarInjector(s) => s.backer.type_path.clone().into(),
SymbolVariant::WrappedMethod(s) => {
self.symtab_marcher
.get_symbol(s.wrapped_path())
.and_then(|v| v.try_as_member_func_wrapper_ref())
.map(|wrapper| wrapper.return_type_path.clone().into())
.map(|wrapper| wrapper.backer.return_type_path.clone().into())
.unwrap_or(SymbolPathBuf::unknown(SymbolCategory::Type))
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/lsp/src/providers/document_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,35 +411,35 @@ impl ToDocumentSymbol for ConstructorSymbol {
impl ToDocumentSymbol for MemberFunctionInjectorSymbol {
#[inline]
fn to_doc_sym(&self) -> Option<lsp::DocumentSymbol> {
self.inner.to_doc_sym()
self.backer.to_doc_sym()
}
}

impl ToDocumentSymbol for MemberFunctionReplacerSymbol {
#[inline]
fn to_doc_sym(&self) -> Option<lsp::DocumentSymbol> {
self.inner.to_doc_sym()
self.backer.to_doc_sym()
}
}

impl ToDocumentSymbol for GlobalFunctionReplacerSymbol {
#[inline]
fn to_doc_sym(&self) -> Option<lsp::DocumentSymbol> {
self.inner.to_doc_sym()
self.backer.to_doc_sym()
}
}

impl ToDocumentSymbol for MemberFunctionWrapperSymbol {
#[inline]
fn to_doc_sym(&self) -> Option<lsp::DocumentSymbol> {
self.inner.to_doc_sym()
self.backer.to_doc_sym()
}
}

impl ToDocumentSymbol for MemberVarInjectorSymbol {
#[inline]
fn to_doc_sym(&self) -> Option<lsp::DocumentSymbol> {
self.inner.to_doc_sym()
self.backer.to_doc_sym()
}
}

Expand Down
26 changes: 13 additions & 13 deletions crates/lsp/src/providers/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,13 @@ impl RenderTooltip for MemberFunctionInjectorSymbol {
buf.push(')');
buf.push('\n');

for spec in self.specifiers.iter() {
for spec in self.backer.specifiers.iter() {
let kw: Keyword = spec.into();
buf.push_str(kw.as_ref());
buf.push(' ');
}

if let Some(flavour) = self.flavour.clone() {
if let Some(flavour) = self.backer.flavour.clone() {
let kw: Keyword = flavour.into();
buf.push_str(kw.as_ref());
buf.push(' ');
Expand Down Expand Up @@ -783,7 +783,7 @@ impl RenderTooltip for MemberFunctionInjectorSymbol {
buf.push(' ');
buf.push(':');
buf.push(' ');
buf.push_str(self.return_type_name());
buf.push_str(self.backer.return_type_name());
}
}

Expand All @@ -795,13 +795,13 @@ impl RenderTooltip for MemberFunctionReplacerSymbol {
buf.push(')');
buf.push('\n');

for spec in self.specifiers.iter() {
for spec in self.backer.specifiers.iter() {
let kw: Keyword = spec.into();
buf.push_str(kw.as_ref());
buf.push(' ');
}

if let Some(flavour) = self.flavour.clone() {
if let Some(flavour) = self.backer.flavour.clone() {
let kw: Keyword = flavour.into();
buf.push_str(kw.as_ref());
buf.push(' ');
Expand Down Expand Up @@ -841,7 +841,7 @@ impl RenderTooltip for MemberFunctionReplacerSymbol {
buf.push(' ');
buf.push(':');
buf.push(' ');
buf.push_str(self.return_type_name());
buf.push_str(self.backer.return_type_name());
}
}

Expand All @@ -850,13 +850,13 @@ impl RenderTooltip for GlobalFunctionReplacerSymbol {
buf.push_str(AnnotationKind::ReplaceMethod.as_ref());
buf.push('\n');

for spec in self.specifiers.iter() {
for spec in self.backer.specifiers.iter() {
let kw: Keyword = spec.into();
buf.push_str(kw.as_ref());
buf.push(' ');
}

if let Some(flavour) = self.flavour.clone() {
if let Some(flavour) = self.backer.flavour.clone() {
let kw: Keyword = flavour.into();
buf.push_str(kw.as_ref());
buf.push(' ');
Expand Down Expand Up @@ -890,13 +890,13 @@ impl RenderTooltip for GlobalFunctionReplacerSymbol {
buf.push_str(", ");
param.render_partial(buf);
}

buf.push(')');

buf.push(' ');
buf.push(':');
buf.push(' ');
buf.push_str(self.return_type_name());
buf.push_str(self.backer.return_type_name());
}
}

Expand Down Expand Up @@ -944,7 +944,7 @@ impl RenderTooltip for MemberFunctionWrapperSymbol {
buf.push(' ');
buf.push(':');
buf.push(' ');
buf.push_str(self.return_type_name());
buf.push_str(self.backer.return_type_name());
}
}

Expand All @@ -956,7 +956,7 @@ impl RenderTooltip for MemberVarInjectorSymbol {
buf.push(')');
buf.push('\n');

for spec in self.specifiers.iter() {
for spec in self.backer.specifiers.iter() {
let kw: Keyword = spec.into();
buf.push_str(kw.as_ref());
buf.push(' ');
Expand All @@ -968,7 +968,7 @@ impl RenderTooltip for MemberVarInjectorSymbol {
buf.push(' ');
buf.push(':');
buf.push(' ');
buf.push_str(self.type_name());
buf.push_str(self.backer.type_name());
}
}

Expand Down

0 comments on commit a917796

Please sign in to comment.