-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Create file if it doesn't exist on save #45
Conversation
My personal opinion would be that it's better to create it as soon as the user saves the file instead. |
I do agree, perhaps I submitted it too fast. I'll try to come up with a solution that will first create a buffer and later, if the user wishes to do so, it will save the file (just like any other sane editor behaves). |
61b6549
to
513eb58
Compare
I updated the code, now it will first create an empty buffer and if the user writes to the file it will create it. |
Title should be updated to |
Do agree on the title, but I think creating parent directories seems a bit too intrusive. Perhaps in the future there could some sort of a prompt asking user if the parent directories should be created with |
All done, tested and it works as expected on absolute, and not absolute paths. |
What happens if the intermediate path doesn't exist? I'm not sure if i.e.
|
It returns an error, but at the moment write errors seem to be silently ignored. |
helix-view/src/document.rs
Outdated
|
||
// TODO: create if not found | ||
let doc = if !path.exists() { | ||
Ok(Rope::from("\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why \n
but not new rope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The document sort of expects at least one trailing new line or things break -- that's why pressing d
in a new buffer makes the line number vanish.
Hmm, we probably want to address that: You should check if helix/helix-view/src/document.rs Line 189 in 3071339
Places that use save can then use |
1487bec
to
641689e
Compare
Sorry for the delay, I've been on vacation for a bit.
That is correct, done. I also don't think we should error out in
Currently |
Yeah, there are no error on this when it failed to save, like if there are a directory. I don't think we can pass editor in to save. We could probably solve this in another pull request. We could do like a channel to show status and have a thread or task to manage that. |
"can't save file, parent directory does not exist", | ||
)); | ||
} | ||
} | ||
let mut file = File::create(path).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, doesn't this already create the file? Currently it already does that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does create the file, that’s correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure what you’re getting at, could you explain the question further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m also thinking there should probably be an explicit error type so it can later be handled for example to show the prompt asking the user if the directories should be created.
Okay, I guess I will merge this since current it fails when the file doesn't exists. |
Thanks! 🎉 |
This PR fixes a crash on startup when the document that should be opened doesn't exist. For now the file will be created at launch, and will exist even if the user doesn't save it.
Closes: #25