Skip to content

Commit 355c98f

Browse files
committed
Docs
1 parent 8a39519 commit 355c98f

File tree

5 files changed

+84
-75
lines changed

5 files changed

+84
-75
lines changed

crates/ra_ide_db/src/change.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! FIXME: write short doc here
1+
//! Defines a unit of change that can applied to a state of IDE to get the next
2+
//! state. Changes are transactional.
23
34
use std::{fmt, sync::Arc, time};
45

crates/ra_ide_db/src/feature_flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! FIXME: write short doc here
1+
//! See docs for `FeatureFlags`.
22
33
use rustc_hash::FxHashMap;
44

crates/ra_ide_db/src/line_index_utils.rs

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,87 @@
1-
//! FIXME: write short doc here
1+
//! Code actions can specify desirable final position of the cursor.
2+
//!
3+
//! The position is specified as a `TextUnit` in the final file. We need to send
4+
//! it in `(Line, Column)` coordinate though. However, we only have a LineIndex
5+
//! for a file pre-edit!
6+
//!
7+
//! Code in this module applies this "to (Line, Column) after edit"
8+
//! transformation.
29
310
use ra_syntax::{TextRange, TextUnit};
411
use ra_text_edit::{AtomTextEdit, TextEdit};
512

613
use crate::line_index::{LineCol, LineIndex, Utf16Char};
714

15+
pub fn translate_offset_with_edit(
16+
line_index: &LineIndex,
17+
offset: TextUnit,
18+
text_edit: &TextEdit,
19+
) -> LineCol {
20+
let mut state = Edits::from_text_edit(&text_edit);
21+
22+
let mut res = RunningLineCol::new();
23+
24+
macro_rules! test_step {
25+
($x:ident) => {
26+
match &$x {
27+
Step::Newline(n) => {
28+
if offset < *n {
29+
return res.to_line_col(offset);
30+
} else {
31+
res.add_line(*n);
32+
}
33+
}
34+
Step::Utf16Char(x) => {
35+
if offset < x.end() {
36+
// if the offset is inside a multibyte char it's invalid
37+
// clamp it to the start of the char
38+
let clamp = offset.min(x.start());
39+
return res.to_line_col(clamp);
40+
} else {
41+
res.adjust_col(*x);
42+
}
43+
}
44+
}
45+
};
46+
}
47+
48+
for orig_step in LineIndexStepIter::from(line_index) {
49+
loop {
50+
let translated_step = state.translate_step(&orig_step);
51+
match state.next_steps(&translated_step) {
52+
NextSteps::Use => {
53+
test_step!(translated_step);
54+
break;
55+
}
56+
NextSteps::ReplaceMany(ns) => {
57+
for n in ns {
58+
test_step!(n);
59+
}
60+
break;
61+
}
62+
NextSteps::AddMany(ns) => {
63+
for n in ns {
64+
test_step!(n);
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
loop {
72+
match state.next_inserted_steps() {
73+
None => break,
74+
Some(ns) => {
75+
for n in ns {
76+
test_step!(n);
77+
}
78+
}
79+
}
80+
}
81+
82+
res.to_line_col(offset)
83+
}
84+
885
#[derive(Debug, Clone)]
986
enum Step {
1087
Newline(TextUnit),
@@ -55,7 +132,7 @@ struct OffsetStepIter<'a> {
55132
offset: TextUnit,
56133
}
57134

58-
impl<'a> Iterator for OffsetStepIter<'a> {
135+
impl Iterator for OffsetStepIter<'_> {
59136
type Item = Step;
60137
fn next(&mut self) -> Option<Step> {
61138
let (next, next_offset) = self
@@ -221,76 +298,6 @@ impl RunningLineCol {
221298
}
222299
}
223300

224-
pub fn translate_offset_with_edit(
225-
line_index: &LineIndex,
226-
offset: TextUnit,
227-
text_edit: &TextEdit,
228-
) -> LineCol {
229-
let mut state = Edits::from_text_edit(&text_edit);
230-
231-
let mut res = RunningLineCol::new();
232-
233-
macro_rules! test_step {
234-
($x:ident) => {
235-
match &$x {
236-
Step::Newline(n) => {
237-
if offset < *n {
238-
return res.to_line_col(offset);
239-
} else {
240-
res.add_line(*n);
241-
}
242-
}
243-
Step::Utf16Char(x) => {
244-
if offset < x.end() {
245-
// if the offset is inside a multibyte char it's invalid
246-
// clamp it to the start of the char
247-
let clamp = offset.min(x.start());
248-
return res.to_line_col(clamp);
249-
} else {
250-
res.adjust_col(*x);
251-
}
252-
}
253-
}
254-
};
255-
}
256-
257-
for orig_step in LineIndexStepIter::from(line_index) {
258-
loop {
259-
let translated_step = state.translate_step(&orig_step);
260-
match state.next_steps(&translated_step) {
261-
NextSteps::Use => {
262-
test_step!(translated_step);
263-
break;
264-
}
265-
NextSteps::ReplaceMany(ns) => {
266-
for n in ns {
267-
test_step!(n);
268-
}
269-
break;
270-
}
271-
NextSteps::AddMany(ns) => {
272-
for n in ns {
273-
test_step!(n);
274-
}
275-
}
276-
}
277-
}
278-
}
279-
280-
loop {
281-
match state.next_inserted_steps() {
282-
None => break,
283-
Some(ns) => {
284-
for n in ns {
285-
test_step!(n);
286-
}
287-
}
288-
}
289-
}
290-
291-
res.to_line_col(offset)
292-
}
293-
294301
#[cfg(test)]
295302
mod test {
296303
use proptest::{prelude::*, proptest};

crates/ra_ide_db/src/symbol_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! for each library (which is assumed to never change) and an FST for each Rust
2020
//! file in the current workspace, and run a query against the union of all
2121
//! those FSTs.
22+
2223
use std::{
2324
fmt,
2425
hash::{Hash, Hasher},

crates/ra_ide_db/src/wasm_shims.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! FIXME: write short doc here
1+
//! A version of `std::time::Instant` that doesn't panic in WASM.
22
33
#[cfg(not(feature = "wasm"))]
44
pub use std::time::Instant;

0 commit comments

Comments
 (0)