-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "string subset" completions (#493)
* Add tests to show that we enquote in composite subset completions * Extract out common subset helper * Add a few more treesitter `Node` utilities * Implement string subset completions as a special case of unique string completions * Custom `r_is_matrix()` just to be sure about the definition * Add support for extracting `colnames()` from a matrix * Add test for `matrix[, "<tab>"]` extracting column names * Adapt to post rebase `main`
- Loading branch information
1 parent
c9377f8
commit 15ef29e
Showing
11 changed files
with
496 additions
and
61 deletions.
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
// | ||
// | ||
|
||
mod common; | ||
mod composite; | ||
mod unique; | ||
mod utils; | ||
|
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// common.rs | ||
// | ||
// Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
// | ||
// | ||
|
||
pub(crate) mod subset; |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// subset.rs | ||
// | ||
// Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
// | ||
// | ||
|
||
use tree_sitter::Node; | ||
use tree_sitter::Point; | ||
|
||
use crate::lsp::traits::point::PointExt; | ||
use crate::treesitter::NodeType; | ||
use crate::treesitter::NodeTypeExt; | ||
|
||
pub(crate) fn is_within_subset_delimiters( | ||
x: &Point, | ||
subset_node: &Node, | ||
subset_type: &NodeType, | ||
) -> bool { | ||
let (open, close) = match subset_type { | ||
NodeType::Subset => ("[", "]"), | ||
NodeType::Subset2 => ("[[", "]]"), | ||
_ => std::unreachable!(), | ||
}; | ||
|
||
let Some(arguments) = subset_node.child_by_field_name("arguments") else { | ||
return false; | ||
}; | ||
|
||
let n_children = arguments.child_count(); | ||
|
||
if n_children < 2 { | ||
return false; | ||
} | ||
|
||
let Some(open_node) = arguments.child(1 - 1) else { | ||
return false; | ||
}; | ||
let Some(close_node) = arguments.child(n_children - 1) else { | ||
return false; | ||
}; | ||
|
||
// Ensure open and closing nodes are the right type | ||
if !matches!( | ||
open_node.node_type(), | ||
NodeType::Anonymous(kind) if kind == open | ||
) { | ||
return false; | ||
} | ||
if !matches!( | ||
close_node.node_type(), | ||
NodeType::Anonymous(kind) if kind == close | ||
) { | ||
return false; | ||
} | ||
|
||
let contains_start = x.is_after_or_equal(open_node.end_position()); | ||
let contains_end = x.is_before_or_equal(close_node.start_position()); | ||
|
||
contains_start && contains_end | ||
} |
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
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
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
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
Oops, something went wrong.