@@ -90,21 +90,15 @@ impl ArkFile {
9090 db : & dyn ArkDb ,
9191 point : tree_sitter:: Point ,
9292 ) -> anyhow:: Result < lsp_types:: Position > {
93- let line_col = biome_line_index:: LineCol {
94- line : point. row as u32 ,
95- col : point. column as u32 ,
96- } ;
97- to_proto:: position_from_line_col ( line_col, self . line_index ( db) , self . encoding )
93+ lsp_position_from_tree_sitter_point ( point, self . line_index ( db) , self . encoding )
9894 }
9995
10096 pub ( crate ) fn lsp_range_from_tree_sitter_range (
10197 & self ,
10298 db : & dyn ArkDb ,
10399 range : tree_sitter:: Range ,
104100 ) -> anyhow:: Result < lsp_types:: Range > {
105- let start = self . lsp_position_from_tree_sitter_point ( db, range. start_point ) ?;
106- let end = self . lsp_position_from_tree_sitter_point ( db, range. end_point ) ?;
107- Ok ( lsp_types:: Range :: new ( start, end) )
101+ lsp_range_from_tree_sitter_range ( range, self . line_index ( db) , self . encoding )
108102 }
109103
110104 pub ( crate ) fn tree_sitter_range_from_lsp_range (
@@ -126,6 +120,31 @@ impl ArkFile {
126120 }
127121}
128122
123+ /// Free functions over `LineIndex` + `PositionEncoding`, so anything holding
124+ /// those two (an `ArkFile` plus its `db`, or a `DocumentContext`) can convert
125+ /// without each carrying its own copy of the logic.
126+ pub ( crate ) fn lsp_position_from_tree_sitter_point (
127+ point : tree_sitter:: Point ,
128+ line_index : & biome_line_index:: LineIndex ,
129+ encoding : PositionEncoding ,
130+ ) -> anyhow:: Result < lsp_types:: Position > {
131+ let line_col = biome_line_index:: LineCol {
132+ line : point. row as u32 ,
133+ col : point. column as u32 ,
134+ } ;
135+ to_proto:: position_from_line_col ( line_col, line_index, encoding)
136+ }
137+
138+ pub ( crate ) fn lsp_range_from_tree_sitter_range (
139+ range : tree_sitter:: Range ,
140+ line_index : & biome_line_index:: LineIndex ,
141+ encoding : PositionEncoding ,
142+ ) -> anyhow:: Result < lsp_types:: Range > {
143+ let start = lsp_position_from_tree_sitter_point ( range. start_point , line_index, encoding) ?;
144+ let end = lsp_position_from_tree_sitter_point ( range. end_point , line_index, encoding) ?;
145+ Ok ( lsp_types:: Range :: new ( start, end) )
146+ }
147+
129148#[ cfg( test) ]
130149pub ( crate ) fn test_ark_file ( code : & str ) -> ( oak_db:: OakDatabase , ArkFile ) {
131150 use aether_path:: FilePath ;
0 commit comments