Skip to content

Commit

Permalink
Hot patch indent_edit() for tree-sitter-r bug (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan authored Jun 21, 2024
1 parent efaea0d commit 6b5da1e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/ark/src/lsp/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ pub fn indent_edit(doc: &Document, line: usize) -> anyhow::Result<Option<Vec<Ark
column: 0,
};

let node = ast
.root_node()
.find_smallest_spanning_node(indent_pos)
.unwrap(); // Can only happen if `line` is OOB, which it isn't
let node = ast.root_node().find_smallest_spanning_node(indent_pos);

// FIXME: Remove this as soon as https://github.com/r-lib/tree-sitter-r/pull/126
// is merged and we have synced with upstream tree-sitter-r.
// Due to a tree-sitter-r bug, if there are leading newlines in a document, they are
// consumed before the `program` node is created, meaning that rows at the beginning
// of a document before the first token can look OOB and won't be contained by any
// node. There should be no indent adjustment required in these cases.
if node.is_none() {
return Ok(None);
}

let node = node.unwrap(); // Can only happen if `line` is OOB, which it isn't

// Get the parent node of the beginning of line
let mut bol_parent = node;
Expand Down

0 comments on commit 6b5da1e

Please sign in to comment.