-
Notifications
You must be signed in to change notification settings - Fork 13
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
Refactor symbol search #597
Conversation
This comment has been minimized.
This comment has been minimized.
I'm thinking that only Now that all methods own their store, we no longer need any ref or mut ref. So Does that makes sense? |
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.
Looks like a nice simplification!
fn new_symbol(name: String, kind: SymbolKind, range: Range) -> DocumentSymbol { | ||
DocumentSymbol { | ||
name, | ||
kind, | ||
detail: None, | ||
children: Some(Vec::new()), | ||
deprecated: None, | ||
tags: None, | ||
range, | ||
selection_range: range, | ||
} | ||
} | ||
|
||
fn new_symbol_node( | ||
name: String, | ||
kind: SymbolKind, | ||
range: Range, | ||
children: Vec<DocumentSymbol>, | ||
) -> DocumentSymbol { | ||
let mut symbol = new_symbol(name, kind, range); | ||
symbol.children = Some(children); | ||
symbol | ||
} |
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.
One thing that I really like from the Biome group is the with_<optional_feature>()
pattern
fn with_children(mut self, children) -> Self {
self.children = children;
self
}
So it becomes
new_symbol(symbol, kind, range).with_children(children)
It would require a DocumentSymbolExt
trait so this is fine if you want to keep it as is, just thought id point it out as a pattern to keep in mind
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.
That does seem like a nice pattern!
Oh yes it does. I wrote a new pull request to this specific branch in #606. My approach was to use a Note that this process involves assigning a |
a9e815e
to
2684b1e
Compare
Progress towards posit-dev/positron#3822.
Errors are now consistently propagated as
Err
and only logged at the very top.We no longer recurse blindly into all node types except argument lists (this is the current restriction but note that we should recurse in arg lists in the future for e.g.
lapply
andtest_that
). Instead, we only recurse in handlers of specific node types. For instance, comment sections are only expected in expression lists, and thus only handled in the expression list handler.We no longer pass around a mut ref of the parent. Instead we pass a store of children by value and return it once done. If a handler inserts a note in the outline, it creates a new store, recurse into its children with this new store, and adds itself to the store of its caller.
This simpler approach is easier to understand and should solve the lifetime issues encountered in Feature/nested-outline #593.
Bunch of tests.