Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libcmd/include/nix/cmd/repl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct AbstractNixRepl
* @todo this is a layer violation
*
* @param programName Name of the command, e.g. `nix` or `nix-env`.
* @param args aguments to the command.
* @param args arguments to the command.
*/
using RunNix =
void(const std::string & programName, const Strings & args, const std::optional<std::string> & input);
Expand All @@ -37,7 +37,6 @@ struct AbstractNixRepl
*/
static std::unique_ptr<AbstractNixRepl> create(
const LookupPath & lookupPath,
nix::ref<Store> store,
ref<EvalState> state,
std::function<AnnotatedValues()> getValues,
RunNix * runNix = nullptr);
Expand Down
29 changes: 15 additions & 14 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc

const static int envSize = 32768;
std::shared_ptr<StaticEnv> staticEnv;
Value lastLoaded;
std::optional<Value> lastLoaded;
Env * env;
int displ;
StringSet varNames;
Expand All @@ -78,7 +78,6 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc

NixRepl(
const LookupPath & lookupPath,
nix::ref<Store> store,
ref<EvalState> state,
std::function<AnnotatedValues()> getValues,
RunNix * runNix);
Expand Down Expand Up @@ -133,7 +132,6 @@ std::string removeWhitespace(std::string s)

NixRepl::NixRepl(
const LookupPath & lookupPath,
nix::ref<Store> store,
ref<EvalState> state,
std::function<NixRepl::AnnotatedValues()> getValues,
RunNix * runNix)
Expand Down Expand Up @@ -773,11 +771,19 @@ void NixRepl::initEnv()

void NixRepl::showLastLoaded()
{
RunPager pager;
if (!lastLoaded)
throw Error("nothing has been loaded yet");

for (auto & i : *lastLoaded.attrs()) {
std::string_view name = state->symbols[i.name];
logger->cout(name);
RunPager pager;
try {
for (auto & i : *lastLoaded->attrs()) {
std::string_view name = state->symbols[i.name];
logger->cout(name);
}
} catch (SystemError & e) {
/* Ignore broken pipes when the pager gets interrupted. */
if (!e.is(std::errc::broken_pipe))
throw;
}
}

Expand Down Expand Up @@ -900,13 +906,9 @@ void NixRepl::runNix(const std::string & program, const Strings & args, const st
}

std::unique_ptr<AbstractNixRepl> AbstractNixRepl::create(
const LookupPath & lookupPath,
nix::ref<Store> store,
ref<EvalState> state,
std::function<AnnotatedValues()> getValues,
RunNix * runNix)
const LookupPath & lookupPath, ref<EvalState> state, std::function<AnnotatedValues()> getValues, RunNix * runNix)
{
return std::make_unique<NixRepl>(lookupPath, std::move(store), state, getValues, runNix);
return std::make_unique<NixRepl>(lookupPath, state, getValues, runNix);
}

ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap & extraEnv)
Expand All @@ -919,7 +921,6 @@ ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete)
auto repl = std::make_unique<NixRepl>(
lookupPath,
openStore(),
evalState,
getValues,
/*runNix=*/nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct CmdRepl : RawInstallablesCommand
}
return values;
};
auto repl = AbstractNixRepl::create(lookupPath, openStore(), state, getValues, runNix);
auto repl = AbstractNixRepl::create(lookupPath, state, getValues, runNix);
repl->autoArgs = getAutoArgs(*repl->state);
repl->initEnv();
repl->mainLoop();
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/repl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ testReplResponseNoRegex '
}
'

testReplResponseNoRegex '
:ll
' \
'error: nothing has been loaded yet
'

# Don't prompt for more input when getting unexpected EOF in imported files.
testReplResponse "
import $testDir/lang/parse-fail-eof-pos.nix
Expand Down
Loading