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 feature #486

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

Tail feature #486

wants to merge 6 commits into from

Conversation

sjoshid
Copy link

@sjoshid sjoshid commented Dec 17, 2019

Closes xi-editor/xi-editor#922.
This PR adds a "Tail File" option under Debug menu. This option can be enabled/disabled per file.

TODO: Gray out this option if the file doesnt exist. No point in tailing a file that doesnt exist.

Review Checklist

  • I have responded to reviews and made changes where appropriate.
  • I have tested the code
  • I have updated comments / documentation related to the changes I made.
  • I have rebased my PR branch onto xi-mac/master.

Copy link
Member

@nangtrongvuon nangtrongvuon left a comment

Choose a reason for hiding this comment

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

The PR looks much better! I have a few remaining comments before I'm ok with merging this, though I think it's pretty close already.

@@ -711,6 +717,10 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc
document.xiCore.setTheme(themeName: sender.title)
}

@IBAction func debugToggleTail(_ sender: NSMenuItem) {
document.xiCore.toggleTailConfig(identifier: document.coreViewIdentifier!, enabled: !self.isTailEnabled)
Copy link
Member

Choose a reason for hiding this comment

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

We could probably rewrite this in a way so we don't have to do !self.isTailEnabled here, since it feels counter intuitive.

Copy link
Author

Choose a reason for hiding this comment

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

Rewrite how?

Copy link
Member

Choose a reason for hiding this comment

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

This is just a little nit, but I'd prefer if this was

document.xiCore.toggleTailConfig(identifier: document.coreViewIdentifier!, enabled: self.isTailEnabled)

@@ -86,4 +86,7 @@ protocol XiClient: AnyObject {

/// A notification containing the current replace status.
func replaceStatus(viewIdentifier: String, status: ReplaceStatus)

/// A notification telling toggle tail config was successfully changed.
func toggleTailConfigChanged(viewIdentifier: String, isTailEnabled: Bool)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this toggleTailConfigChanged? Do you envision the tail config to have more things than whether if the user enables tailing? Even if so, I feel like this should just be something like enableTailing.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. I have made this change.

@sjoshid
Copy link
Author

sjoshid commented Dec 18, 2019

There is one small thing remaining. Gray out "Tail" option if the file doesnt exist. Im working on that.
Also, we need to hold off on merging this till core's PR is merged.

1) "Tail" option under Debug is grayed out if a file doesnt exist. No point in tailing such files. 
2) Refactoring based on comments.
Copy link
Member

@nangtrongvuon nangtrongvuon left a comment

Choose a reason for hiding this comment

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

Few more comments, and then I think this is in a good enough state to merge after the core PR goes in!

@@ -711,6 +717,10 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc
document.xiCore.setTheme(themeName: sender.title)
}

@IBAction func debugToggleTail(_ sender: NSMenuItem) {
document.xiCore.toggleTailConfig(identifier: document.coreViewIdentifier!, enabled: !self.isTailEnabled)
Copy link
Member

Choose a reason for hiding this comment

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

This is just a little nit, but I'd prefer if this was

document.xiCore.toggleTailConfig(identifier: document.coreViewIdentifier!, enabled: self.isTailEnabled)

@@ -919,6 +951,11 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc
languagesMenu.addItem(item)
}
}

public func enableTailing(_ isTailEnabled: Bool) {
self.isTailEnabled = isTailEnabled
Copy link
Member

Choose a reason for hiding this comment

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

.. and this part is instead:
self.isTailEnabled = !isTailEnabled

This avoids having to rely on state from another method.

Copy link
Author

Choose a reason for hiding this comment

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

See my long comment below.

@@ -228,6 +229,11 @@ enum CoreNotification {
{
return .replaceStatus(viewIdentifier: viewIdentifier!, status: replaceStatus)
}
case "enable_tailing":
if let isTailEnabled = jsonParams["is_tail_enabled"] as? Bool
Copy link
Member

Choose a reason for hiding this comment

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

I think enable_tailing should be toggle_tailing instead, since it's way clearer in conveying what it does exactly. enable_tailing implies that it always enables tailing for any file, not what it actually does (which is toggle the tailing state for a specific view).

Since you changed this here, your plugin doesn't handle the old JSON properly. Perhaps you should update your other PR as well with this change?

Copy link
Author

Choose a reason for hiding this comment

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

I havent push the change. I'll do it based on outcome of the naming discussion we are having.

@sjoshid
Copy link
Author

sjoshid commented Dec 22, 2019

@nangtrongvuon
Allow me to add more details to the naming. I sort of struggled with it. (and Im bad at naming)
There are two parts
a) When user clicks the "Tail" option, EditViewController.debugToggleTail is the one that toggles the state (tail flag) and sends it to core. Hence the word 'toggle' in method. Tail flag belongs to EditViewController and so does debugToggleTail(). Instance method modifying instance variable. So toggling here is ok I think.
b) After sending to core, it replies with either true ie tail was toggled successfully or false otherwise. This reply from core is handled by EditViewController.enableTailing. It shouldnt be toggled because it represents the actual state of the flag. Toggling here would be incorrect. Besides, if core replies with true and I toggle in EditViewController.enableTailing, then my state would be false. Dont think this is correct either.

I still think EditViewController.enableTailing(**bool** ) is correct. Because it is not just enableTailing(). Parameter is important here. Without parameter, it means what you are saying: enable tailing. In my case it takes a bool. So I would read it as "Enable tailing. Yes or no?".

If you want me to separate enable and disable I would have to do something like

bool tailChangedInCore = <reply from core>
if tailChangedInCore
    EditViewController.enableTailing()
else
    EditViewController.disableTailing()
EditViewController.enableTailing() {
    self.isTailEnabled = true
}
EditViewController.disableTailing() {
    self.isTailEnabled = false
}

If this is what you want, I would be happy to make the change. If not, let me know what you think. Sorry about long comment. I hope Im not going off on a tangent.

@nangtrongvuon
Copy link
Member

nangtrongvuon commented Dec 29, 2019

My main problem with this:

document.xiCore.toggleTailConfig(identifier: document.coreViewIdentifier!, enabled: !self.isTailEnabled)

Is that you begin to mutate state in a method's argument which I think reads really weird. It doesn't produce the wrong results, but it's also something I'm not okay with seeing in a codebase, since it makes following this code hard and also makes it less maintainable.

I'm also not a fan of using this frontend boolean to determine behavior of core. I believe this is a code smell, and core should be able to maintain which views are currently being tailed. The frontend doesn't really need to control this state, at most it should only communicate that state to the user (for xi-mac, this should be the isTailEnabled boolean), so they know that their file is being tailed and not in an editing state.

So in conclusion, I wouldn't split it into enable and disable, but I would just have a toggleTailing without passing enabled that will toggle tailing state for a view. If it worked and the state changed, cool, we should tell this to the user by changing isTailEnabled. If not, then all is fine, just keep the current frontend state.

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?
2 participants