-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feature/nested-outline #593
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5dfb4c1
Fix broken output pane caused by lines with hashtags only
kv9898 945fa01
Add tests for hastag-only comment lines
kv9898 14c4bb3
experimental nested outline
kv9898 d1da86c
Merge branch 'posit-dev:main' into feature/nested-outline
kv9898 d3b3276
debug log added
kv9898 b77fe84
nested outline working, but missing other objects
kv9898 f684c81
remove logging
kv9898 fdc4e33
fix missing objects
kv9898 899dce6
fix unexpanded functions
kv9898 817a5ad
Merge branch 'posit-dev:main' into feature/nested-outline
kv9898 366e0b3
remove unnecessary comment
kv9898 c83b756
Revert symbol back to OBJECT
kv9898 10bc34d
fully working
kv9898 3dd37ee
Merge branch 'feature/nested-outline' into feature/neat-nested-outline
kv9898 5d57786
Merge pull request #1 from kv9898/feature/neat-nested-outline
kv9898 02f1cf2
fix merge errors
kv9898 b0e8bc7
remove unneeded comment
kv9898 72f7653
Merge branch 'posit-dev:main' into feature/nested-outline
kv9898 e381e34
Merge branch 'posit-dev:main' into feature/nested-outline
kv9898 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 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 |
---|---|---|
|
@@ -136,41 +136,69 @@ fn parse_comment_as_section(comment: &str) -> Option<(usize, String)> { | |
None | ||
} | ||
|
||
fn index_node( | ||
fn index_assignment_with_comments( | ||
node: &Node, | ||
contents: &Rope, | ||
parent: &mut DocumentSymbol, | ||
symbols: &mut Vec<DocumentSymbol>, | ||
section_stack: &mut Vec<(usize, *mut DocumentSymbol)>, | ||
) -> Result<bool> { | ||
// Check if the node is a comment and matches the markdown-style comment patterns | ||
if node.node_type() == NodeType::Comment { | ||
let comment_text = contents.node_slice(&node)?.to_string(); | ||
|
||
// Check if the comment starts with one or more '#' followed by any text and ends with 4+ punctuations | ||
if let Some((_level, title)) = parse_comment_as_section(&comment_text) { | ||
// Create a symbol based on the parsed comment | ||
let start = convert_point_to_position(contents, node.start_position()); | ||
let end = convert_point_to_position(contents, node.end_position()); | ||
|
||
let symbol = DocumentSymbol { | ||
name: title, // Use the title without the trailing '####' or '----' | ||
kind: SymbolKind::STRING, // Treat it as a string section | ||
detail: None, // No need to display level details | ||
children: Some(Vec::new()), // Prepare for child symbols if any | ||
deprecated: None, | ||
tags: None, | ||
range: Range { start, end }, | ||
selection_range: Range { start, end }, | ||
}; | ||
|
||
// Add the symbol to the parent node | ||
parent.children.as_mut().unwrap().push(symbol); | ||
let comment_text = contents.node_slice(&node)?.to_string(); | ||
|
||
// Check if the comment starts with one or more '#' followed by any text and ends with 4+ punctuations | ||
if let Some((level, title)) = parse_comment_as_section(&comment_text) { | ||
// Create a symbol based on the parsed comment | ||
let start = convert_point_to_position(contents, node.start_position()); | ||
let end = convert_point_to_position(contents, node.end_position()); | ||
|
||
let symbol = DocumentSymbol { | ||
name: title, // Use the title without the trailing '####' or '----' | ||
kind: SymbolKind::STRING, // Treat it as a string section | ||
detail: None, // No need to display level details | ||
children: Some(Vec::new()), // Prepare for child symbols if any | ||
deprecated: None, | ||
tags: None, | ||
range: Range { start, end }, | ||
selection_range: Range { start, end }, | ||
}; | ||
|
||
while let Some((current_level, _)) = section_stack.last() { | ||
if *current_level >= level { | ||
section_stack.pop(); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
// Return early to avoid further processing | ||
return Ok(true); | ||
// Push the new symbol to the current parent | ||
if let Some((_, current_parent_ptr)) = section_stack.last() { | ||
let current_parent = unsafe { &mut **current_parent_ptr }; | ||
current_parent.children.as_mut().unwrap().push(symbol); | ||
let new_parent = current_parent | ||
.children | ||
.as_mut() | ||
.unwrap() | ||
.last_mut() | ||
.unwrap(); | ||
section_stack.push((level, new_parent as *mut DocumentSymbol)); | ||
} else { | ||
parent.children.as_mut().unwrap().push(symbol); | ||
let new_parent = parent.children.as_mut().unwrap().last_mut().unwrap(); | ||
section_stack.push((level, new_parent as *mut DocumentSymbol)); | ||
} | ||
|
||
return Ok(true); | ||
} else { | ||
// No need to index the comment | ||
return Ok(false); | ||
} | ||
} | ||
|
||
fn index_node( | ||
node: &Node, | ||
contents: &Rope, | ||
parent: &mut DocumentSymbol, | ||
symbols: &mut Vec<DocumentSymbol>, | ||
) -> Result<bool> { | ||
if matches!( | ||
node.node_type(), | ||
NodeType::BinaryOperator(BinaryOperatorType::LeftAssignment) | | ||
|
@@ -188,11 +216,23 @@ fn index_node( | |
|
||
// Recurse into children | ||
let mut cursor = node.walk(); | ||
let mut section_stack: Vec<(usize, *mut DocumentSymbol)> = vec![(0, &mut *parent)]; | ||
for child in node.children(&mut cursor) { | ||
if is_indexable(&child) { | ||
let result = index_node(&child, contents, parent, symbols); | ||
if let Err(error) = result { | ||
error!("{:?}", error); | ||
if child.node_type() == NodeType::Comment { | ||
let result: Result<bool> = | ||
index_assignment_with_comments(&child, contents, parent, &mut section_stack); | ||
if let Err(error) = result { | ||
error!("{:?}", error); | ||
} | ||
} else { | ||
if let Some((_, current_parent_ptr)) = section_stack.last() { | ||
let current_parent = unsafe { &mut **current_parent_ptr }; | ||
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. 2nd unsafe reference |
||
let result = index_node(&child, contents, current_parent, symbols); | ||
if let Err(error) = result { | ||
error!("{:?}", error); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
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.
1st unsafe reference