diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-04-06 13:15:50 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2023-04-06 13:15:50 +0200 |
commit | 94812cca98fbb157e5f64a15a85a2b852d289feb (patch) | |
tree | 2f02c31fc42c7286f3c35dfd3ff1a88f235ab65b /src/libcmd/repl.cc | |
parent | 5256ba6d87403f2b58ec4586c26d8fb14027252f (diff) |
Backport SourcePath from the lazy-trees branch
This introduces the SourcePath type from lazy-trees as an abstraction
for accessing files from inputs that may not be materialized in the
real filesystem (e.g. Git repositories). Currently, however, it's just
a wrapper around CanonPath, so it shouldn't change any behaviour. (On
lazy-trees, SourcePath is a <InputAccessor, CanonPath> tuple.)
Diffstat (limited to 'src/libcmd/repl.cc')
-rw-r--r-- | src/libcmd/repl.cc | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index e3afb1531..9002fa555 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -54,8 +54,6 @@ struct NixRepl , gc #endif { - std::string curDir; - size_t debugTraceIndex; Strings loadedFiles; @@ -113,7 +111,6 @@ NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store, ref<EvalStat , staticEnv(new StaticEnv(false, state->staticBaseEnv.get())) , historyFile(getDataDir() + "/nix/repl-history") { - curDir = absPath("."); } @@ -590,7 +587,7 @@ bool NixRepl::processLine(std::string line) Value v; evalString(arg, v); - const auto [path, line] = [&] () -> std::pair<Path, uint32_t> { + const auto [path, line] = [&] () -> std::pair<SourcePath, uint32_t> { if (v.type() == nPath || v.type() == nString) { PathSet context; auto path = state->coerceToPath(noPos, v, context, "while evaluating the filename to edit"); @@ -598,7 +595,7 @@ bool NixRepl::processLine(std::string line) } else if (v.isLambda()) { auto pos = state->positions[v.lambda.fun->pos]; if (auto path = std::get_if<Path>(&pos.origin)) - return {*path, pos.line}; + return {SourcePath(CanonPath(*path)), pos.line}; else throw Error("'%s' cannot be shown in an editor", pos); } else { @@ -872,8 +869,7 @@ void NixRepl::addVarToScope(const Symbol name, Value & v) Expr * NixRepl::parseString(std::string s) { - Expr * e = state->parseExprFromString(std::move(s), curDir, staticEnv); - return e; + return state->parseExprFromString(std::move(s), state->rootPath(CanonPath::fromCwd()), staticEnv); } @@ -930,7 +926,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m break; case nPath: - str << ANSI_GREEN << v.path << ANSI_NORMAL; // !!! escaping? + str << ANSI_GREEN << v.path().to_string() << ANSI_NORMAL; // !!! escaping? break; case nNull: |