Skip to content

Commit

Permalink
nixd/Nix: promote nested namespace nix::nixd -> nixd
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Aug 11, 2023
1 parent e943f4b commit b8d6205
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions nixd/include/nixd/Nix/Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <optional>
#include <string>

namespace nix::nixd {
namespace nixd {
struct OptionInfo {
std::optional<std::string> Type;
std::optional<std::string> Description;
Expand All @@ -15,4 +15,4 @@ struct OptionInfo {
};

OptionInfo optionInfo(nix::EvalState &State, nix::Value &V);
} // namespace nix::nixd
} // namespace nixd
8 changes: 4 additions & 4 deletions nixd/include/nixd/Nix/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <nix/attr-path.hh>
#include <nix/eval.hh>

namespace nix::nixd {
namespace nixd {

bool isOption(EvalState &State, Value &V);
bool isOption(nix::EvalState &State, nix::Value &V);

bool isDerivation(EvalState &State, Value &V);
bool isDerivation(nix::EvalState &State, nix::Value &V);

std::optional<std::string> attrPathStr(nix::EvalState &State, nix::Value &V,
const std::string &AttrPath) noexcept;

extern int PrintDepth;

} // namespace nix::nixd
} // namespace nixd
4 changes: 2 additions & 2 deletions nixd/lib/Nix/Option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <llvm/Support/FormatVariadic.h>

namespace nix::nixd {
namespace nixd {

OptionInfo optionInfo(nix::EvalState &State, nix::Value &V) {
OptionInfo Info;
Expand Down Expand Up @@ -41,4 +41,4 @@ std::string OptionInfo::mdDoc() {
Example, Description);
}

} // namespace nix::nixd
} // namespace nixd
16 changes: 8 additions & 8 deletions nixd/lib/Nix/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
#include <nix/eval.hh>
#include <nix/print.hh>

namespace nix::nixd {
namespace nixd {

bool isOption(EvalState &State, Value &V) {
State.forceValue(V, noPos);
if (V.type() != ValueType::nAttrs)
bool isOption(nix::EvalState &State, nix::Value &V) {
State.forceValue(V, nix::noPos);
if (V.type() != nix::ValueType::nAttrs)
return false;

// https://github.com/NixOS/nixpkgs/blob/58ca986543b591a8269cbce3328293ca8d64480f/lib/options.nix#L89
auto S = attrPathStr(State, V, "_type");
return S && S.value() == "option";
};

bool isDerivation(EvalState &State, Value &V) {
State.forceValue(V, noPos);
if (V.type() != ValueType::nAttrs)
bool isDerivation(nix::EvalState &State, nix::Value &V) {
State.forceValue(V, nix::noPos);
if (V.type() != nix::ValueType::nAttrs)
return false;

// Derivations has a special attribute "type" == "derivation"
Expand All @@ -41,7 +41,7 @@ std::optional<std::string> attrPathStr(nix::EvalState &State, nix::Value &V,

int PrintDepth;

} // namespace nix::nixd
} // namespace nixd

namespace nix {

Expand Down
6 changes: 3 additions & 3 deletions nixd/lib/Server/EvalWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void EvalWorker::onDefinition(
// to the location which defines the package.
try {
auto V = AST->getValueEval(Node, *State);
if (nix::nixd::isDerivation(*State, V)) {
if (auto S = nix::nixd::attrPathStr(*State, V, "meta.position")) {
if (isDerivation(*State, V)) {
if (auto S = attrPathStr(*State, V, "meta.position")) {
llvm::StringRef PositionStr = S.value();
auto [Path, LineStr] = PositionStr.split(':');
int Line;
Expand Down Expand Up @@ -142,7 +142,7 @@ void EvalWorker::onHover(const lspserver::TextDocumentPositionParams &Params,
try {
auto Value = AST->getValueEval(Node, *IER->Session->getState());
std::stringstream Res{};
nix::nixd::PrintDepth = 3;
PrintDepth = 3;
Value.print(IER->Session->getState()->symbols, Res);
HoverText =
llvm::formatv("## {0} \n Value: `{1}`", ExprName, Res.str());
Expand Down
1 change: 0 additions & 1 deletion nixd/lib/Server/OptionWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void OptionWorker::onEvalOptionSet(
void OptionWorker::onCompletion(const ipc::AttrPathParams &Params,
lspserver::Callback<llvm::json::Value> Reply) {
using namespace lspserver;
using namespace nix::nixd;
ReplyRAII<CompletionList> RR(std::move(Reply));

if (!OptionAttrSet)
Expand Down

0 comments on commit b8d6205

Please sign in to comment.