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

feat: add notify based formatter #510

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

shikanime
Copy link

Close: #509

@shikanime shikanime changed the title Add notify based formatter feat: add notify based formatter Jan 18, 2025
@shikanime shikanime force-pushed the pr510 branch 4 times, most recently from ff745b2 to c3a206c Compare January 18, 2025 03:33
walk/watch.go Outdated
}

// start watching the path
if err := watcher.Add(fqPath); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When does this run? Is it exactly once (per path) on startup? What about the scenario where new files are created after we register all these watches?

Copy link
Author

Choose a reason for hiding this comment

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

It will run in async mode as soon as we call the Add method, for the moment I've kept it simple so that this only formats file changes and not the initial formatting, but later this would be the preferred behaviour.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I don't think I understand: with the code in this PR, will we start watching files if they're created after the watch starts, or would someone have to restart the watch process to watch those new files?

Copy link
Author

@shikanime shikanime Jan 21, 2025

Choose a reason for hiding this comment

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

Oh, I've just understood what you meant. It continuously monitors file system events from the moment it starts, including the creation and update of all files within the specified paths, without the need to restart the monitoring process.

@shikanime
Copy link
Author

shikanime commented Jan 21, 2025

Files detected by the walker are not guaranteed to exist when the format, caching or release funcs kicks in. This code captures the creation of IDE swap and temporary files, but if deleted quickly such saving to file in Neovim will result in a crash with file not found.

I'm not quite sure how to fix this at the moment, but it shouldn't be hard to find later.

@shikanime shikanime force-pushed the pr510 branch 8 times, most recently from 150bea4 to b91c5e3 Compare January 23, 2025 10:25
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.

Add a watch mode for automatic formatting on file save
2 participants