Skip to content

Commit 498ccfe

Browse files
committed
More use of 'point_from_cursor()'
This should have been part of #805. Oops.
1 parent e6a54a1 commit 498ccfe

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/ark/src/lsp/document_context.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,25 @@ impl<'a> DocumentContext<'a> {
9797
#[cfg(test)]
9898
mod tests {
9999
use super::*;
100+
use crate::fixtures::point_from_cursor;
100101
use crate::treesitter::node_text;
101102
use crate::treesitter::NodeType;
102103
use crate::treesitter::NodeTypeExt;
103104

104105
#[test]
105106
fn test_document_context_start_of_document() {
106-
let point = Point { row: 0, column: 0 };
107-
108107
// Empty document
109-
let document = Document::new("", None);
108+
let (text, point) = point_from_cursor("@");
109+
let document = Document::new(text.as_str(), None);
110110
let context = DocumentContext::new(&document, point, None);
111111
assert_eq!(
112112
node_text(&context.node, &context.document.contents).unwrap(),
113113
""
114114
);
115115

116116
// Start of document with text
117-
let document = Document::new("1 + 1", None);
117+
let (text, point) = point_from_cursor("@1 + 1");
118+
let document = Document::new(text.as_str(), None);
118119
let context = DocumentContext::new(&document, point, None);
119120
assert_eq!(
120121
node_text(&context.node, &context.document.contents).unwrap(),
@@ -124,8 +125,9 @@ mod tests {
124125

125126
#[test]
126127
fn test_document_context_cursor_on_empty_line() {
127-
let document = Document::new("toupper(letters)\n", None);
128-
let point = Point { row: 1, column: 0 }; // as if we're about to type on the second line
128+
// as if we're about to type on the second line
129+
let (text, point) = point_from_cursor("toupper(letters)\n@");
130+
let document = Document::new(text.as_str(), None);
129131
let context = DocumentContext::new(&document, point, None);
130132

131133
assert_eq!(context.node.node_type(), NodeType::Program);

0 commit comments

Comments
 (0)