Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tail toggle v2 #1241

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Tail toggle v2 #1241

wants to merge 11 commits into from

Conversation

sjoshid
Copy link
Contributor

@sjoshid sjoshid commented Nov 23, 2019

Closes #922

Review Checklist

  • I have responded to reviews and made changes where appropriate.
  • I have tested the code with cargo test --all / ./rust/run_all_checks.
  • I have updated comments / documentation related to the changes I made.
  • I have rebased my PR branch onto xi-editor/master.

@sjoshid
Copy link
Contributor Author

sjoshid commented Nov 23, 2019

@cmyr
Tailing works with this branch.
This PR is still not cleaned up. I have a bunch of custom todos which I'll clean up. Also clippy fails with

error: value assigned to `is_tail_event` is never read
   --> core-lib/src/tabs.rs:737:17
    |
737 |         let mut is_tail_event = false;
    |                 ^^^^^^^^^^^^^
    |
    = note: `-D unused-assignments` implied by `-D warnings`
    = help: maybe it is overwritten before being read?

But these arent issues that will stop you from reviewing.

If there is something you want me to do make it easier for you to review...let me know.

EventKind::Modify(ModifyKind::Any) if event.flag().is_some() => {
let flag_kind = event.flag().unwrap();

if Flag::Ongoing.eq(flag_kind) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ongoing events should not be handled here.

@@ -869,8 +882,30 @@ impl View {
let height = self.line_of_offset(text, text.len()) + 1;
let plan = RenderPlan::create(height, self.first_line, self.height);
self.send_update_for_plan(text, client, styles, style_spans, &plan, pristine);
if let Some(new_scroll_pos) = self.scroll_to.take() {
let (line, col) = self.offset_to_line_col(text, new_scroll_pos);
if !self.is_tail_enabled {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check makes sure that when user scrolls a tailing file, we dont auto scroll to cursor location. Mimics tail command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it'd be worth adding a comment to the source file about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

let mut inner =
watcher(tx_event, Duration::from_millis(100)).expect("watcher should spawn");
inner
.configure(Config::OngoingEvents(Some(Duration::from_millis(50))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any mills less than 100 would made sense here.

@sjoshid sjoshid mentioned this pull request Dec 16, 2019
4 tasks
rust/core-lib/src/client.rs Show resolved Hide resolved
return Ok(Rope::from(""));
}

let existing_file_info = self.file_info.get(&id).expect("File info must be present");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using expect here is kind of ugly.

rust/core-lib/src/file.rs Show resolved Hide resolved
f.seek(SeekFrom::End(0)).map_err(|e| FileError::Io(e, path.as_ref().to_owned()))?;

let current_position = file_info.tail_position.expect(
"tail_position is None. Since we are tailing a file, tail_position cannot be None.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, expect here isn't nice

);
let diff = end_position - current_position;
let mut buf = vec![0; diff as usize];
f.seek(SeekFrom::Current(-(buf.len() as i64))).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't buf.len() == diff here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it'd be nice if we could avoid unwrap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't buf.len() == diff here?

yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it'd make more sense to just use diff here directly I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Will make the change.

rust/core-lib/src/file.rs Show resolved Hide resolved
rust/core-lib/src/tabs.rs Show resolved Hide resolved
};

let has_changes = self.file_manager.check_file(path, buffer_id);
let is_pristine = self.editors.get(&buffer_id).map(|ed| ed.borrow().is_pristine()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, unwrapping isn't nice (unless None is a programmer error in which case the called code should probably panic! anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree but this code is copied as is from original.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess this returning None doesn't really happen then? @cmyr

@@ -869,8 +882,30 @@ impl View {
let height = self.line_of_offset(text, text.len()) + 1;
let plan = RenderPlan::create(height, self.first_line, self.height);
self.send_update_for_plan(text, client, styles, style_spans, &plan, pristine);
if let Some(new_scroll_pos) = self.scroll_to.take() {
let (line, col) = self.offset_to_line_col(text, new_scroll_pos);
if !self.is_tail_enabled {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it'd be worth adding a comment to the source file about this.

@Cogitri
Copy link
Member

Cogitri commented Dec 23, 2019

Could you please rebase this on master?

rust/core-lib/src/file.rs Show resolved Hide resolved
@sjoshid
Copy link
Contributor Author

sjoshid commented Dec 24, 2019

I have already rebased this on master. You shouldnt get any conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tail toggle?
3 participants