Skip to content

Accept Command with args for BufferEditor - #630

Merged
sholderbach merged 7 commits into
nushell:mainfrom
horasal:buffereditor
Sep 28, 2023
Merged

sholderbach merged 7 commits into
nushell:mainfrom
horasal:buffereditor

Conversation

@horasal

@horasal horasal commented Sep 6, 2023 •

Copy link
Copy Markdown
Contributor

Thin pr contains the reedline-side change for nushell/nushell#10210

BufferEditor in current reedline only use a big string to represent editor and it's arguments, which is broken when editor's path contains any spaces. This pr make BufferEditor also accept list<string> from $nu.EDITOR just like config env.

(To avoid breaking current version of nushell, this pr add a new api with_argumented_buffer_editor instead of directly modify with_buffer_editor.)

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for taking care of this!

Thanks for being considerate about breaking changes. In this case I think to make errors less likely I would be open to one.

To keep things simple and tidy, we could pass std::process::Command directly. It communicates the requirements very clearly, is Send/Sync, and you can add the file just by .arg() and then .spawn()

@horasal

horasal commented Sep 7, 2023

Copy link
Copy Markdown
Contributor Author

Personally I think just store a set of string is more flexible so reedline can implement its own feature like hints for argument (e.g. throw warning when call vscode without -w) or editor selection (show a list of editor if no one is set).
(I'm no sure if it's in reedline's scope or not, though.)

and I also agree that Command sounds good enough for open_editor.

@sholderbach

Copy link
Copy Markdown
Member

I think as a library reedline doesn't have to take full responsibility for that. If you want to implement additional checks for the editor you would also have to implement them on the nushell (or other app) side if there is any use of an editor.
Command makes this clean, that it is the responsibility of the caller.

@horasal

horasal commented Sep 7, 2023

Copy link
Copy Markdown
Contributor Author

Command makes this clean,

I don't think it's true.

Command does not implement Clone there's no way to insert temp_file without affecting current instance. Of course you can construct another Command by Command::new(old_command.get_program().to_string_lossy()) but why.

@sholderbach

Copy link
Copy Markdown
Member

Mhh open_editor currently only ever uses one temp_file through extension.
So taking the Command by value would be fine with the current behavior. Yes there is a slight burden on the user of reedline to properly set this up.

fn with_buffer_editor(mut self, editor: Command, ....) -> Self

Instead of extension we could also have

fn with_buffer_editor(mut self, editor: Command, tempfile: impl AsRef<OsStr>) -> Self

so the file name is not dependent on reedline and can be configured to please the application. But then the responsibility to deconflict multiple Reedline instances is on the caller.

A strong argument for Command is that this would allow us to resolve nushell/nushell#10241 by also managing the environment through the same interface.

@horasal

horasal commented Sep 8, 2023

Copy link
Copy Markdown
Contributor Author

I get your point and now the new api only accepts Command

  • Command should always contains full arguments, including the path of temp file
  • temp_file used in Command should match the one passed in with_buffer_editor_command

@sholderbach

Copy link
Copy Markdown
Member

Thanks for the quick turnaround, with a cargo fmt run we are pretty much good to go.

I think, as we will bump the leading version number, we would be fine with just making the breaking change to with_buffer_editor, so we don't need to maintain two functions.

temp_file used in Command should match the one passed in with_buffer_editor_command

We could check that .get_args() contains temp_file :)

@codecov

codecov Bot commented Sep 15, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #630 (5874cd6) into main (6739c6a) will increase coverage by 0.00%.
Report is 5 commits behind head on main.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #630   +/-   ##
=======================================
  Coverage   49.80%   49.80%           
=======================================
  Files          41       41           
  Lines        7805     7821   +16     
=======================================
+ Hits         3887     3895    +8     
- Misses       3918     3926    +8     
Files Coverage Δ
src/engine.rs 5.13% <0.00%> (+<0.01%) ⬆️

... and 2 files with indirect coverage changes

The old `with_buffer_editor` would have not set the file and
`with_buffer_editor_command` had unclear semantics if you should provide
the file to the command or not.

Instead of going the route of deprecation let's just make the breaking
change and update `with_buffer_editor` to a more practical signature.
Expect a `Command` and a `PathBuf` for the file.
If the file is not among the args push it.
@sholderbach

Copy link
Copy Markdown
Member

I took the liberty to move the new flexible but explicit behavior into the .with_buffer_editor method.
Added a check to see if the file name is already added.

Thanks for getting us in a good shape here @horasal!

@sholderbach sholderbach changed the title Accept list of arguments for BufferEditor Accept Command with args for BufferEditor Sep 28, 2023
@sholderbach
sholderbach merged commit b1344f6 into nushell:main Sep 28, 2023
sholderbach pushed a commit to sholderbach/nushell that referenced this pull request Sep 28, 2023
use one temp file per instance
Pull in recent reedline

Fix to `with_buffer_editor`

nushell/reedline#630
sholderbach pushed a commit to sholderbach/nushell that referenced this pull request Sep 29, 2023
use one temp file per instance
Pull in recent reedline

Fix to `with_buffer_editor`

nushell/reedline#630
sholderbach pushed a commit to sholderbach/nushell that referenced this pull request Sep 29, 2023
use one temp file per instance
Pull in recent reedline

Fix to `with_buffer_editor`

nushell/reedline#630
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.

2 participants