mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
fix: more rules to forbidden arg completion (#1493)
* fix: more rules to forbidden arg completion * fix: fix case * feat: revert one
This commit is contained in:
parent
a68399c92e
commit
774227d328
14 changed files with 145 additions and 15 deletions
|
@ -1088,6 +1088,18 @@ impl<'a> SyntaxContext<'a> {
|
|||
| SyntaxContext::Normal(node) => node.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the argument container node.
|
||||
pub fn arg_container(&self) -> Option<&LinkedNode<'a>> {
|
||||
match self {
|
||||
Self::Arg { args, .. }
|
||||
| Self::Element {
|
||||
container: args, ..
|
||||
} => Some(args),
|
||||
Self::Paren { container, .. } => Some(container),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Kind of argument source.
|
||||
|
@ -1342,6 +1354,37 @@ fn arg_context<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
/// The cursor is on an invalid position.
|
||||
pub enum BadCompletionCursor {
|
||||
/// The cursor is outside of the argument list.
|
||||
ArgListPos,
|
||||
}
|
||||
|
||||
/// Checks if the cursor is on an invalid position for completion.
|
||||
pub fn bad_completion_cursor(
|
||||
syntax: Option<&SyntaxClass>,
|
||||
syntax_context: Option<&SyntaxContext>,
|
||||
leaf: &LinkedNode,
|
||||
) -> Option<BadCompletionCursor> {
|
||||
// The cursor is on `f()|`
|
||||
if (matches!(syntax, Some(SyntaxClass::Callee(..))) && {
|
||||
syntax_context
|
||||
.and_then(SyntaxContext::arg_container)
|
||||
.is_some_and(|container| {
|
||||
container.rightmost_leaf().map(|s| s.offset()) == Some(leaf.offset())
|
||||
})
|
||||
// The cursor is on `f[]|`
|
||||
}) || (matches!(
|
||||
syntax,
|
||||
Some(SyntaxClass::Normal(SyntaxKind::ContentBlock, _))
|
||||
) && matches!(leaf.kind(), SyntaxKind::RightBracket))
|
||||
{
|
||||
return Some(BadCompletionCursor::ArgListPos);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue