summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshinyfelix <101457412+shinyfelix@users.noreply.github.com>2024-07-09 17:22:08 +0200
committerGitHub <noreply@github.com>2024-07-09 15:22:08 +0000
commitb1219395b15012b38cbfc1bdfefe12669be00e07 (patch)
tree30bb099db2dd9ac5ed6017ac16aedefea6871f49
parent34990f7f0e25d51a76520edc1101df606013973f (diff)
Fix suggestions for '.' after code mode has exited. (#4470)
-rw-r--r--crates/typst-ide/src/complete.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs
index cdcac956..90c8b4a1 100644
--- a/crates/typst-ide/src/complete.rs
+++ b/crates/typst-ide/src/complete.rs
@@ -334,6 +334,13 @@ fn math_completions(ctx: &mut CompletionContext) {
/// Complete field accesses.
fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
+ // Used to determine whether trivia nodes are allowed before '.'.
+ // During an inline expression in markup mode trivia nodes exit the inline expression.
+ let in_markup: bool = matches!(
+ ctx.leaf.parent_kind(),
+ None | Some(SyntaxKind::Markup) | Some(SyntaxKind::Ref)
+ );
+
// Behind an expression plus dot: "emoji.|".
if_chain! {
if ctx.leaf.kind() == SyntaxKind::Dot
@@ -341,6 +348,7 @@ fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
&& ctx.leaf.text() == ".");
if ctx.leaf.range().end == ctx.cursor;
if let Some(prev) = ctx.leaf.prev_sibling();
+ if !in_markup || prev.range().end == ctx.leaf.range().start;
if prev.is::<ast::Expr>();
if prev.parent_kind() != Some(SyntaxKind::Markup) ||
prev.prev_sibling_kind() == Some(SyntaxKind::Hash);
@@ -1434,6 +1442,16 @@ mod tests {
}
#[test]
+ fn test_whitespace_in_autocomplete() {
+ //Check that extra space before '.' is handled correctly.
+ test("#() .", 5, &[], &["insert", "remove", "len", "all"]);
+ test("#{() .}", 6, &["insert", "remove", "len", "all"], &["foo"]);
+
+ test("#() .a", 6, &[], &["insert", "remove", "len", "all"]);
+ test("#{() .a}", 7, &["at", "any", "all"], &["foo"]);
+ }
+
+ #[test]
fn test_before_window_char_boundary() {
// Check that the `before_window` doesn't slice into invalid byte
// boundaries.