From 3034aa64aac022796886c6db467e119d40112b05 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Sat, 5 Oct 2024 21:45:06 -0400 Subject: [PATCH] Added node support --- README.md | 41 ++++--- config/javascript/debugging.nix | 28 +++++ config/javascript/default.nix | 16 +++ config/javascript/language.nix | 52 ++++++++ config/language.nix | 4 - flake.nix | 210 ++++++++++++++++---------------- 6 files changed, 222 insertions(+), 129 deletions(-) create mode 100644 config/javascript/debugging.nix create mode 100644 config/javascript/default.nix create mode 100644 config/javascript/language.nix diff --git a/README.md b/README.md index dec92ac..eb45ead 100644 --- a/README.md +++ b/README.md @@ -30,23 +30,24 @@ The default configuration performs editing without settings for any particular l ## Technology Support -| Technology | Formatter | Language Server | Debugger | Nix Configuration | -| ---------- | ------------ | ---------------------------------- | ---------- | ----------------- | -| Nix | alejandra | nil-ls, nixd | | default | -| Just | just | | | default | -| SQL | sqlformat | | | default | -| Lua | stylua | | | default | -| YAML | yamlfmt | yamllint, yamlls | | default | -| CSS | prettier | | | default | -| HTML | prettier | | | default | -| Javascript | prettier | | | default | -| Typescript | prettier | | | default | -| JSON | prettier | jsonls | | default | -| Markdown | prettier | marksman | | default | -| Ruby | rubyfmt | | | default | -| Terraform | tofu_fmt | | | default | -| TOML | taplo | taplo | | default | -| C# | csharpier | csharp-ls | netcoredbg | csharp | -| Go | golines | gopls | delve | golang | -| Python | black, isort | flake8, jedi, pylint, rope, mccabe | dap-python | python | -| Rust | rustfmt | clippy | lldb | rust | +| Technology | Formatter | Language Server | Debugger | Nix Configuration | +| ---------- | ------------ | ---------------------------------- | --------------- | ----------------- | +| Nix | alejandra | nil-ls, nixd | | default | +| Just | just | | | default | +| SQL | sqlformat | | | default | +| Lua | stylua | | | default | +| YAML | yamlfmt | yamllint, yamlls | | default | +| CSS | prettier | | | default | +| HTML | prettier | | | default | +| Javascript | prettier | | | default | +| Typescript | prettier | | | default | +| JSON | prettier | jsonls | | default | +| Markdown | prettier | marksman | | default | +| Ruby | rubyfmt | | | default | +| Terraform | tofu_fmt | | | default | +| TOML | taplo | taplo | | default | +| C# | csharpier | csharp-ls | netcoredbg | csharp | +| Go | golines | gopls | delve | golang | +| Python | black, isort | flake8, jedi, pylint, rope, mccabe | dap-python | python | +| Rust | rustfmt | clippy | lldb | rust | +| Node | prettier | tsserver | vscode-js-debug | javascript | diff --git a/config/javascript/debugging.nix b/config/javascript/debugging.nix new file mode 100644 index 0000000..f094e1a --- /dev/null +++ b/config/javascript/debugging.nix @@ -0,0 +1,28 @@ +{pkgs, ...}: { + plugins = { + dap = { + enable = true; + adapters.servers = { + "pwa-node" = { + host = "localhost"; + port = 8123; + executable = { + command = "${pkgs.vscode-js-debug}/bin/js-debug"; + }; + }; + }; + }; + }; + + extraConfigLua = '' + require("dap").configurations.javascript = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "''${file}", + cwd = "''${workspaceFolder}", + }, + } + ''; +} diff --git a/config/javascript/default.nix b/config/javascript/default.nix new file mode 100644 index 0000000..3d7eebc --- /dev/null +++ b/config/javascript/default.nix @@ -0,0 +1,16 @@ +let + # Read all files in the current directory + files = builtins.readDir ./.; + + # Filter out default.nix and non-.nix files + nixFiles = builtins.filter + (name: name != "default.nix" && builtins.match ".*\\.nix" name != null) + (builtins.attrNames files); + + # Create a list of import statements + imports = map (name: ./. + "/${name}") nixFiles; +in { + # Import all configuration modules automatically + imports = imports; +} + diff --git a/config/javascript/language.nix b/config/javascript/language.nix new file mode 100644 index 0000000..b339bec --- /dev/null +++ b/config/javascript/language.nix @@ -0,0 +1,52 @@ +{ + plugins = { + conform-nvim = { + settings = { + formatters_by_ft.javascript = ["prettier"]; + formatters_by_ft.typescript = ["prettier"]; + formatters_by_ft.javascriptreact = ["prettier"]; + formatters_by_ft.typescriptreact = ["prettier"]; + }; + }; + lsp.servers.ts-ls = { + enable = true; + filetypes = [ + "javascript" + "javascriptreact" + "typescript" + "typescriptreact" + ]; + extraOptions = { + settings = { + javascript = { + inlayHints = { + includeInlayEnumMemberValueHints = true; + includeInlayFunctionLikeReturnTypeHints = true; + includeInlayFunctionParameterTypeHints = true; + includeInlayParameterNameHints = "all"; + includeInlayParameterNameHintsWhenArgumentMatchesName = true; + includeInlayPropertyDeclarationTypeHints = true; + includeInlayVariableTypeHints = true; + }; + }; + typescript = { + inlayHints = { + includeInlayEnumMemberValueHints = true; + includeInlayFunctionLikeReturnTypeHints = true; + includeInlayFunctionParameterTypeHints = true; + includeInlayParameterNameHints = "all"; + includeInlayParameterNameHintsWhenArgumentMatchesName = true; + includeInlayPropertyDeclarationTypeHints = true; + includeInlayVariableTypeHints = true; + }; + }; + }; + }; + }; + lsp.servers.eslint.enable = true; + none-ls.sources.formatting.prettier = { + enable = true; + disableTsServerFormatter = false; + }; + }; +} diff --git a/config/language.nix b/config/language.nix index 18045ed..9935796 100644 --- a/config/language.nix +++ b/config/language.nix @@ -175,8 +175,6 @@ in formatters_by_ft = { css = ["prettier"]; html = ["prettier"]; - javascript = ["prettier"]; - javascriptreact = ["prettier"]; json = ["prettier"]; just = ["just"]; lua = ["stylua"]; @@ -185,8 +183,6 @@ in ruby = ["rubyfmt"]; terraform = ["tofu_fmt"]; tf = ["tofu_fmt"]; - typescript = ["prettier"]; - typescriptreact = ["prettier"]; yaml = ["yamlfmt"]; }; }; diff --git a/flake.nix b/flake.nix index 4b53866..46da18f 100644 --- a/flake.nix +++ b/flake.nix @@ -6,118 +6,118 @@ flake-parts.url = "github:hercules-ci/flake-parts"; rust-overlay.url = "github:oxalica/rust-overlay"; }; - outputs = - { - nixvim, - flake-parts, - rust-overlay, - ... - }@inputs: - flake-parts.lib.mkFlake { inherit inputs; } { + outputs = { + nixvim, + flake-parts, + rust-overlay, + ... + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - perSystem = - { system, ... }: - let - overlays = [ (import rust-overlay) ]; - nixvimLib = nixvim.lib.${system}; - nixvim' = nixvim.legacyPackages.${system}; - baseNixvimModule = { - inherit pkgs; - module = - { pkgs, ... }: - { - imports = [ ./config ]; - extraPackages = with pkgs; [ sops ]; - }; - extraSpecialArgs = { }; - }; - rustNixvimModule = { - inherit pkgs; - module = - { pkgs, ... }: - { - imports = [ - ./config - ./config/rust - ]; - extraPackages = with pkgs; [ - sops - rust-bin.stable.latest.default - ]; - }; - extraSpecialArgs = { }; - }; - csharpNixvimModule = { - inherit pkgs; - module = - { pkgs, ... }: - { - imports = [ - ./config - ./config/csharp - ]; - extraPackages = with pkgs; [ sops ]; - }; - extraSpecialArgs = { }; - }; - goNixvimModule = { - inherit pkgs; - module = - { pkgs, ... }: - { - imports = [ - ./config - ./config/golang - ]; - extraPackages = with pkgs; [ sops ]; - }; - extraSpecialArgs = { }; - }; - pythonNixvimModule = { - inherit pkgs; - module = - { pkgs, ... }: - { - imports = [ - ./config - ./config/python - ]; - extraPackages = with pkgs; [ sops ]; - }; - extraSpecialArgs = { }; - }; - pkgs = import inputs.nixpkgs { - inherit system overlays; - config.allowUnfree = true; - }; - baseNvim = nixvim'.makeNixvimWithModule baseNixvimModule; - rustNvim = nixvim'.makeNixvimWithModule rustNixvimModule; - csharpNvim = nixvim'.makeNixvimWithModule csharpNixvimModule; - goNvim = nixvim'.makeNixvimWithModule goNixvimModule; - pythonNvim = nixvim'.makeNixvimWithModule pythonNixvimModule; - in - { - checks = { - # Run `nix flake check .` to verify that your config is not broken - default = nixvimLib.check.mkTestDerivationFromNixvimModule baseNixvimModule; - }; - packages = { - # Lets you run `nix run .` to start nixvim - default = baseNvim; - # Lets you run `nix run .#rust` to start nixvim with Rust configuration - rust = rustNvim; - # Lets you run `nix run .#csharp` to start nixvim with C# configuration - csharp = csharpNvim; - # Lets you run `nix run .#golang` to start nixvim with Go configuration - golang = goNvim; - # Lets you run `nix run .#python` to start nixvim with Python configuration - python = pythonNvim; + perSystem = {system, ...}: let + overlays = [(import rust-overlay)]; + nixvimLib = nixvim.lib.${system}; + nixvim' = nixvim.legacyPackages.${system}; + baseNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [./config]; + extraPackages = with pkgs; [sops]; }; + extraSpecialArgs = {}; }; + rustNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [ + ./config + ./config/rust + ]; + extraPackages = with pkgs; [ + sops + rust-bin.stable.latest.default + ]; + }; + extraSpecialArgs = {}; + }; + csharpNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [ + ./config + ./config/csharp + ]; + extraPackages = with pkgs; [sops]; + }; + extraSpecialArgs = {}; + }; + goNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [ + ./config + ./config/golang + ]; + extraPackages = with pkgs; [sops]; + }; + extraSpecialArgs = {}; + }; + pythonNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [ + ./config + ./config/python + ]; + extraPackages = with pkgs; [sops]; + }; + extraSpecialArgs = {}; + }; + javascriptNixvimModule = { + inherit pkgs; + module = {pkgs, ...}: { + imports = [ + ./config + ./config/javascript + ]; + extraPackages = with pkgs; [sops]; + }; + extraSpecialArgs = {}; + }; + pkgs = import inputs.nixpkgs { + inherit system overlays; + config.allowUnfree = true; + }; + baseNvim = nixvim'.makeNixvimWithModule baseNixvimModule; + rustNvim = nixvim'.makeNixvimWithModule rustNixvimModule; + csharpNvim = nixvim'.makeNixvimWithModule csharpNixvimModule; + goNvim = nixvim'.makeNixvimWithModule goNixvimModule; + pythonNvim = nixvim'.makeNixvimWithModule pythonNixvimModule; + javascriptNvim = nixvim'.makeNixvimWithModule javascriptNixvimModule; + in { + checks = { + # Run `nix flake check .` to verify that your config is not broken + default = nixvimLib.check.mkTestDerivationFromNixvimModule baseNixvimModule; + }; + packages = { + # Lets you run `nix run .` to start nixvim + default = baseNvim; + # Lets you run `nix run .#rust` to start nixvim with Rust configuration + rust = rustNvim; + # Lets you run `nix run .#csharp` to start nixvim with C# configuration + csharp = csharpNvim; + # Lets you run `nix run .#golang` to start nixvim with Go configuration + golang = goNvim; + # Lets you run `nix run .#python` to start nixvim with Python configuration + python = pythonNvim; + # Lets you run `nix run .#javascript` to start nixvim with JS/TS configuration + javascript = javascriptNvim; + }; + }; }; }