forked from lix-project/lix
src/libcmd/repl.cc: avoid unneeded reload after :e
If `:edit`ing a store path, don't reload repl afterwards
to avoid losing local variables: store is immutable,
so "editing" a store path is always just viewing it.
Resolves: lix-project/lix#341
Change-Id: I3747f75ce26e0595e953069c39ddc3ee80699718
This commit is contained in:
parent
548c973e82
commit
1a6d7a3af4
|
@ -57,6 +57,11 @@ ericson:
|
||||||
display_name: John Ericson
|
display_name: John Ericson
|
||||||
github: ericson2314
|
github: ericson2314
|
||||||
|
|
||||||
|
goldstein:
|
||||||
|
display_name: goldstein
|
||||||
|
forgejo: goldstein
|
||||||
|
github: GoldsteinE
|
||||||
|
|
||||||
horrors:
|
horrors:
|
||||||
display_name: eldritch horrors
|
display_name: eldritch horrors
|
||||||
forgejo: pennae
|
forgejo: pennae
|
||||||
|
|
11
doc/manual/rl-next/repl-edit-store.md
Normal file
11
doc/manual/rl-next/repl-edit-store.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
synopsis: "`:edit`ing a file in Nix store no longer reloads the repl"
|
||||||
|
issues: [fj#341]
|
||||||
|
cls: [1620]
|
||||||
|
category: Improvements
|
||||||
|
credits: [goldstein]
|
||||||
|
---
|
||||||
|
|
||||||
|
Calling `:edit` from the repl now only reloads if the file being edited was outside of Nix store.
|
||||||
|
That means that all the local variables are now preserved across `:edit`s of store paths.
|
||||||
|
This is always safe because the store is read-only.
|
|
@ -652,9 +652,12 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
// using runProgram2 to allow editors to display their UI
|
// using runProgram2 to allow editors to display their UI
|
||||||
runProgram2(RunOptions { .program = editor, .searchPath = true, .args = args }).wait();
|
runProgram2(RunOptions { .program = editor, .searchPath = true, .args = args }).wait();
|
||||||
|
|
||||||
// Reload right after exiting the editor
|
// Reload right after exiting the editor if path is not in store
|
||||||
state->resetFileCache();
|
// Store is immutable, so there could be no changes, so there's no need to reload
|
||||||
reloadFiles();
|
if (!state->store->isInStore(path.resolveSymlinks().path.abs())) {
|
||||||
|
state->resetFileCache();
|
||||||
|
reloadFiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":t") {
|
else if (command == ":t") {
|
||||||
|
|
|
@ -244,3 +244,30 @@ testReplResponseNoRegex '
|
||||||
y = { a = 1; };
|
y = { a = 1; };
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Test that editing a store path does not reload...
|
||||||
|
echo '{ identity = a: a; }' > repl-test.nix
|
||||||
|
repl_test_store="$(nix-store --add repl-test.nix)"
|
||||||
|
EDITOR=true testReplResponseNoRegex "
|
||||||
|
a = ''test string that we'll grep later''
|
||||||
|
:l $repl_test_store
|
||||||
|
:e identity
|
||||||
|
a
|
||||||
|
" "test string that we'll grep later"
|
||||||
|
|
||||||
|
# ...even through symlinks
|
||||||
|
ln -s "$repl_test_store" repl-test-link.nix
|
||||||
|
EDITOR=true testReplResponseNoRegex "
|
||||||
|
a = ''test string that we'll grep later''
|
||||||
|
:l repl-test-link.nix
|
||||||
|
:e identity
|
||||||
|
a
|
||||||
|
" "test string that we'll grep later"
|
||||||
|
|
||||||
|
# Test that editing a local file does reload
|
||||||
|
EDITOR=true testReplResponseNoRegex "
|
||||||
|
a = ''test string that we'll grep later''
|
||||||
|
:l repl-test.nix
|
||||||
|
:e identity
|
||||||
|
a
|
||||||
|
" "undefined variable"
|
||||||
|
|
Loading…
Reference in a new issue