Skip to content

Commit

Permalink
Merge branch 'main' into release/2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Aug 16, 2024
2 parents bed4a95 + c9d8970 commit f7702f1
Show file tree
Hide file tree
Showing 44 changed files with 539 additions and 305 deletions.
6 changes: 1 addition & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
meson,
ninja,
nix,
nixpkgs-fmt,
pkg-config,
nlohmann_json,
python312,
Expand All @@ -29,10 +28,7 @@ stdenv.mkDerivation {
pkg-config
];

nativeCheckInputs = [
lit
nixpkgs-fmt
];
nativeCheckInputs = [ lit ];

buildInputs = [
nix
Expand Down
201 changes: 104 additions & 97 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,105 +12,112 @@
};
};

outputs = { nixpkgs, flake-parts, treefmt-nix, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem = { config, pkgs, ... }:
let
inherit (pkgs) nixVersions llvmPackages_16 callPackage stdenv;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt {
inherit nix;
};
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. {
inherit nix llvmPackages;
};
nixdLLVM = nixdMono.override {
stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv;
};
regressionDeps = with pkgs; [
clang-tools
nixpkgs-fmt
lit
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = { inherit nixd nixf nixt; };
outputs =
{
nixpkgs,
flake-parts,
treefmt-nix,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem =
{ config, pkgs, ... }:
let
inherit (pkgs)
nixVersions
llvmPackages_16
callPackage
stdenv
;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt { inherit nix; };
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. { inherit nix llvmPackages; };
nixdLLVM = nixdMono.override { stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv; };
regressionDeps = with pkgs; [
clang-tools
lit
nixfmt-rfc-style
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = {
inherit nixd nixf nixt;
};

devShells.llvm = nixdLLVM.overrideAttrs shellOverride;
devShells.llvm = nixdLLVM.overrideAttrs shellOverride;

devShells.default = nixdMono.overrideAttrs shellOverride;
devShells.default = nixdMono.overrideAttrs shellOverride;

devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixpkgs-fmt
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [
config.flake-root.devShell
];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixpkgs-fmt
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [ config.flake-root.devShell ];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
};
formatter = treefmtEval.config.build.wrapper;
};
formatter = treefmtEval.config.build.wrapper;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
}
6 changes: 1 addition & 5 deletions libnixf/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ninja,
pkg-config,
lit,
nixpkgs-fmt,
gtest,
boost182,
nlohmann_json,
Expand Down Expand Up @@ -37,10 +36,7 @@ stdenv.mkDerivation {
python312
];

nativeCheckInputs = [
lit
nixpkgs-fmt
];
nativeCheckInputs = [ lit ];

buildInputs = [
gtest
Expand Down
1 change: 1 addition & 0 deletions libnixf/include/nixf/Basic/JSONDiagnostic.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// \file
/// \brief Provide jsonified diagnostic, for other languages/structured output.
#pragma once

#include "Diagnostic.h"
#include "nixf/Basic/Range.h"
Expand Down
4 changes: 1 addition & 3 deletions libnixf/include/nixf/Basic/NoteKinds.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ DIAG_NOTE("merge-diff-rec-consider", RecConsider,
"will be considered as {}recursive")
DIAG_NOTE("note-bcomment-begin", BCommentBegin, "/* comment begins at here")
DIAG_NOTE("to-match-this", ToMachThis, "to match this {}")
DIAG_NOTE("var-bind-to-this", VarBindToThis,
"variable will bind to this definition")
DIAG_NOTE("escaping-this-with", EscapingWith, "escaping this with expression")

#endif // DIAG_NOTE
6 changes: 0 additions & 6 deletions libnixf/src/Basic/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,4 @@ class Diagnostic(TypedDict):
"severity": "Warning",
"message": "unused `with` expression",
},
{
"sname": "sema-escaping-with",
"cname": "EscapingWith",
"severity": "Hint",
"message": "this variable comes from the scope outside of the `with` expression",
},
]
16 changes: 0 additions & 16 deletions libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ void VariableLookupAnalysis::lookupVar(const ExprVar &Var,
if (Def) {
Def->usedBy(Var);
Results.insert({&Var, LookupResult{LookupResultKind::Defined, Def}});

if (EnclosedWith && !Def->isBuiltin()) {
// Escaping from "with" to outer scope.
// https://github.com/NixOS/nix/issues/490

assert(WithEnv && "EnclosedWith -> WithEnv");
// Make a diagnostic.
Diagnostic &D =
Diags.emplace_back(Diagnostic::DK_EscapingWith, Var.range());
if (Def->syntax()) {
D.note(Note::NK_VarBindToThis, Def->syntax()->range());
}
const auto &KwWith =
static_cast<const nixf::ExprWith *>(WithEnv->syntax())->kwWith();
D.note(Note::NK_EscapingWith, KwWith.range());
}
return;
}
if (EnclosedWith) {
Expand Down
29 changes: 0 additions & 29 deletions libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,35 +273,6 @@ TEST_F(VLATest, FormalDef) {
ASSERT_EQ(Diags.size(), 0);
}

TEST_F(VLATest, EscapingWith) {
std::shared_ptr<Node> AST = parse("a: with { a = 1; b = 2; }; a + b", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

ASSERT_EQ(Diags.size(), 1);

const Diagnostic &D = Diags[0];

ASSERT_EQ(D.notes().size(), 2);

ASSERT_EQ(D.notes()[0].kind(), Note::NK_VarBindToThis);
ASSERT_EQ(D.notes()[0].range().lCur().offset(), 0);
ASSERT_EQ(D.notes()[0].range().rCur().offset(), 1);

ASSERT_EQ(D.notes()[1].kind(), Note::NK_EscapingWith);
ASSERT_EQ(D.notes()[1].range().lCur().offset(), 3);
ASSERT_EQ(D.notes()[1].range().rCur().offset(), 7);
}

TEST_F(VLATest, EscapingWithButBuiltin) {
std::shared_ptr<Node> AST =
parse("with { a = 1; }; [ a true false null ]", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

ASSERT_EQ(Diags.size(), 0);
}

TEST_F(VLATest, InheritRec) {
// Make sure inheirt (expr), the expression is binded to "NewEnv".
std::shared_ptr<Node> AST =
Expand Down
10 changes: 5 additions & 5 deletions nixd/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For vscode users you should write `settings.json`[^settings] like this:
"nixd": {
"formatting": {
// This is the default if ommited.
"command": [ "nixpkgs-fmt" ]
"command": [ "nixfmt" ]
},
"options": {
// By default, this entriy will be read from `import <nixpkgs> { }`
Expand Down Expand Up @@ -94,7 +94,7 @@ nvim_lsp.nixd.setup({
expr = "import <nixpkgs> { }",
},
formatting = {
command = { "nixpkgs-fmt" },
command = { "nixfmt" },
},
options = {
nixos = {
Expand Down Expand Up @@ -130,7 +130,7 @@ nvim_lsp.nixd.setup({
},
"formatting": {
// Which command you would like to do formatting
"command": [ "nixpkgs-fmt" ]
"command": [ "nixfmt" ]
},
// Tell the language server your desired option set, for completion
// This is lazily evaluated.
Expand All @@ -149,7 +149,7 @@ nvim_lsp.nixd.setup({
// Control the diagnostic system
"diagnostic": {
"suppress": [
"sema-escaping-with"
"sema-extra-with"
]
}
}
Expand All @@ -167,7 +167,7 @@ prefer to suppress diagnostics altogether. This can be achieved by utilizing the
"diagnostic": {
// A list of diagnostic short names
"suppress": [
"sema-escaping-with"
"sema-extra-with"
]
}
}
Expand Down
Loading

0 comments on commit f7702f1

Please sign in to comment.