From 5364dc4ba247e15a9d1548a297f5101016e4e539 Mon Sep 17 00:00:00 2001 From: Yoni FIRROLONI Date: Thu, 13 Jul 2023 17:03:34 +0200 Subject: [PATCH] tried about 238472893764 ways to import rubocop and solargraph Have a look if you want, I give up --- modules/languages/ruby/Gemfile | 3 +- modules/languages/ruby/Gemfile.lock | 42 +---- modules/languages/ruby/format-derivation.nix | 41 +++++ modules/languages/ruby/format_derivation.nix | 38 ----- modules/languages/ruby/gemset.nix | 170 ++----------------- modules/languages/ruby/ruby.nix | 91 ++++++---- 6 files changed, 122 insertions(+), 263 deletions(-) create mode 100644 modules/languages/ruby/format-derivation.nix delete mode 100644 modules/languages/ruby/format_derivation.nix diff --git a/modules/languages/ruby/Gemfile b/modules/languages/ruby/Gemfile index a0f1cd8f..a96201bf 100644 --- a/modules/languages/ruby/Gemfile +++ b/modules/languages/ruby/Gemfile @@ -10,6 +10,5 @@ gem "rubocop-rake" gem "rubocop-graphql" gem "rubocop-capybara" gem "rubocop-factory_bot" -gem "solargraph" -gem "mini_portile2", "~> 2.8.2" +gem "rubocop-performance" # gem "rails" diff --git a/modules/languages/ruby/Gemfile.lock b/modules/languages/ruby/Gemfile.lock index 1fa84df6..b7f53e34 100644 --- a/modules/languages/ruby/Gemfile.lock +++ b/modules/languages/ruby/Gemfile.lock @@ -7,24 +7,12 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) ast (2.4.2) - backport (1.2.0) - benchmark (0.2.1) concurrent-ruby (1.2.2) - diff-lcs (1.5.0) - e2mmap (0.1.0) i18n (1.14.1) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.6) json (2.6.3) - kramdown (2.4.0) - rexml - kramdown-parser-gfm (1.1.0) - kramdown (~> 2.0) language_server-protocol (3.17.0.3) - mini_portile2 (2.8.2) minitest (5.18.1) - nokogiri (1.15.3-x86_64-linux) - racc (~> 1.4) parallel (1.23.0) parser (3.2.2.3) ast (~> 2.4.1) @@ -32,12 +20,9 @@ GEM racc (1.7.1) rack (3.0.8) rainbow (3.1.1) - rbs (2.8.4) regexp_parser (2.8.1) - reverse_markdown (2.1.1) - nokogiri rexml (3.2.5) - rubocop (1.54.1) + rubocop (1.54.2) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -58,6 +43,9 @@ GEM rubocop (>= 0.87, < 2) rubocop-minitest (0.31.0) rubocop (>= 1.39, < 2.0) + rubocop-performance (1.18.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) rubocop-rails (2.20.2) activesupport (>= 4.2.0) rack (>= 1.1) @@ -71,44 +59,24 @@ GEM rubocop-sequel (0.3.4) rubocop (~> 1.0) ruby-progressbar (1.13.0) - solargraph (0.49.0) - backport (~> 1.2) - benchmark - bundler (~> 2.0) - diff-lcs (~> 1.4) - e2mmap - jaro_winkler (~> 1.5) - kramdown (~> 2.3) - kramdown-parser-gfm (~> 1.1) - parser (~> 3.0) - rbs (~> 2.0) - reverse_markdown (~> 2.0) - rubocop (~> 1.38) - thor (~> 1.0) - tilt (~> 2.0) - yard (~> 0.9, >= 0.9.24) - thor (1.2.2) - tilt (2.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) - yard (0.9.34) PLATFORMS x86_64-linux DEPENDENCIES - mini_portile2 (~> 2.8.2) rubocop rubocop-capybara rubocop-factory_bot rubocop-graphql rubocop-minitest + rubocop-performance rubocop-rails rubocop-rake rubocop-rspec rubocop-sequel - solargraph BUNDLED WITH 2.4.14 diff --git a/modules/languages/ruby/format-derivation.nix b/modules/languages/ruby/format-derivation.nix new file mode 100644 index 00000000..0fa5672f --- /dev/null +++ b/modules/languages/ruby/format-derivation.nix @@ -0,0 +1,41 @@ +{ + pkgs, + stdenv, +}: let + #formatter-env = with pkgs; + # bundlerEnv { + # name = "Gem dependencies"; + # # inherit ruby_3_2; + # ruby = ruby_3_2; + # gemdir = ./.; + # gemConfig = + # pkgs.defaultGemConfig + # // { + # nokogiri = attrs: { + # buildFlags = ["--use-system-libraries"]; # "--with-zlib-include=${pkgs.zlib}/include/libxml2"]; + # }; + # }; + # }; +in + stdenv.mkDerivation { + name = "Format environment"; + + # nativeBuildInputs = [ + # pkgs.libxslt + # pkgs.zlib + # pkgs.libxml2 + # pkgs.pkg-config + # pkgs.rubocop + # pkgs.solargraph + # ]; + + # Add the derivation to the PATH + buildInputs = [ + pkgs.libxslt + pkgs.libxml2 + pkgs.rubocop + pkgs.solargraph + + # formatter-env + ]; + } diff --git a/modules/languages/ruby/format_derivation.nix b/modules/languages/ruby/format_derivation.nix deleted file mode 100644 index 656ec780..00000000 --- a/modules/languages/ruby/format_derivation.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ - pkgs, - stdenv, -}: let - formatter-env = with pkgs; - bundlerEnv { - name = "Gem dependencies"; - inherit self; - ruby = ruby_3_2; - gemdir = ./.; - - gemConfig = - pkgs.defaultGemConfig - // { - nokogiri = attrs: { - buildFlags = ["--use-system-libraries"]; # "--with-zlib-include=${pkgs.zlib}/include/libxml2"]; - }; - }; - }; -in - stdenv.mkDerivation { - name = "Format environment"; - nativeBuildInputs = [ - pkgs.libxslt - pkgs.zlib - pkgs.libxml2 - pkgs.pkg-config - ]; - - # Add the derivation to the PATH - buildInputs = [ - pkgs.libxslt - pkgs.zlib - pkgs.libxml2 - pkgs.pkg-config - formatter-env - ]; - } diff --git a/modules/languages/ruby/gemset.nix b/modules/languages/ruby/gemset.nix index 5fab4982..8d152dbe 100644 --- a/modules/languages/ruby/gemset.nix +++ b/modules/languages/ruby/gemset.nix @@ -20,26 +20,6 @@ }; version = "2.4.2"; }; - backport = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0xbzzjrgah0f8ifgd449kak2vyf30micpz6x2g82aipfv7ypsb4i"; - type = "gem"; - }; - version = "1.2.0"; - }; - benchmark = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "017jh2lx3z5hqjvnqclc5bfr5q0d3zk0nqjfz73909ybr4h20kmi"; - type = "gem"; - }; - version = "0.2.1"; - }; concurrent-ruby = { groups = ["default"]; platforms = []; @@ -50,26 +30,6 @@ }; version = "1.2.2"; }; - diff-lcs = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0rwvjahnp7cpmracd8x732rjgnilqv2sx7d1gfrysslc3h039fa9"; - type = "gem"; - }; - version = "1.5.0"; - }; - e2mmap = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0n8gxjb63dck3vrmsdcqqll7xs7f3wk78mw8w0gdk9wp5nx6pvj5"; - type = "gem"; - }; - version = "0.1.0"; - }; i18n = { dependencies = ["concurrent-ruby"]; groups = ["default"]; @@ -81,16 +41,6 @@ }; version = "1.14.1"; }; - jaro_winkler = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "10fd3i92897blalxfkgc0jjv0qqx31v7cm7j2b6a3b97an0bfz80"; - type = "gem"; - }; - version = "1.5.6"; - }; json = { groups = ["default"]; platforms = []; @@ -101,28 +51,6 @@ }; version = "2.6.3"; }; - kramdown = { - dependencies = ["rexml"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "1ic14hdcqxn821dvzki99zhmcy130yhv5fqfffkcf87asv5mnbmn"; - type = "gem"; - }; - version = "2.4.0"; - }; - kramdown-parser-gfm = { - dependencies = ["kramdown"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0a8pb3v951f4x7h968rqfsa19c8arz21zw1vaj42jza22rap8fgv"; - type = "gem"; - }; - version = "1.1.0"; - }; language_server-protocol = { groups = ["default"]; platforms = []; @@ -133,16 +61,6 @@ }; version = "3.17.0.3"; }; - mini_portile2 = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0z7f38iq37h376n9xbl4gajdrnwzq284c9v1py4imw3gri2d5cj6"; - type = "gem"; - }; - version = "2.8.2"; - }; minitest = { groups = ["default"]; platforms = []; @@ -153,17 +71,6 @@ }; version = "5.18.1"; }; - nokogiri = { - dependencies = ["racc"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "sha256-h2YxKVqFMV2sN+enE4bWLZ60UqiRCDz+dQXMpIBQiMs="; - type = "gem"; - }; - version = "1.15.3"; - }; parallel = { groups = ["default"]; platforms = []; @@ -215,16 +122,6 @@ }; version = "3.1.1"; }; - rbs = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0dgj5n7rj83981fvrhswfwsh88x42p7r00nvd80hkxmdcjvda2h6"; - type = "gem"; - }; - version = "2.8.4"; - }; regexp_parser = { groups = ["default"]; platforms = []; @@ -235,17 +132,6 @@ }; version = "2.8.1"; }; - reverse_markdown = { - dependencies = ["nokogiri"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0087vhw5ik50lxvddicns01clkx800fk5v5qnrvi3b42nrk6885j"; - type = "gem"; - }; - version = "2.1.1"; - }; rexml = { groups = ["default"]; platforms = []; @@ -262,10 +148,10 @@ platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "1vklabd0510isqhikx4bfx5qn9g8pyj8h9jxryayp2wj8mx4kg74"; + sha256 = "1hc469ahgpfwbvv2q3hqlhp7dlzcii8dlm8k6k324sq26lilv27r"; type = "gem"; }; - version = "1.54.1"; + version = "1.54.2"; }; rubocop-ast = { dependencies = ["parser"]; @@ -322,6 +208,17 @@ }; version = "0.31.0"; }; + rubocop-performance = { + dependencies = ["rubocop" "rubocop-ast"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0bp02784v0qm8qcswi169s0ar6216rwk516v3idzpbxznpqp97ac"; + type = "gem"; + }; + version = "1.18.0"; + }; rubocop-rails = { dependencies = ["activesupport" "rack" "rubocop"]; groups = ["default"]; @@ -376,37 +273,6 @@ }; version = "1.13.0"; }; - solargraph = { - dependencies = ["backport" "benchmark" "diff-lcs" "e2mmap" "jaro_winkler" "kramdown" "kramdown-parser-gfm" "parser" "rbs" "reverse_markdown" "rubocop" "thor" "tilt" "yard"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "18wpma2mgw82qzf1jwjalmz7nwdvn87b22wd5yy16jb67fqgrq78"; - type = "gem"; - }; - version = "0.49.0"; - }; - thor = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0k7j2wn14h1pl4smibasw0bp66kg626drxb59z7rzflch99cd4rg"; - type = "gem"; - }; - version = "1.2.2"; - }; - tilt = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0bmjgbv8158klwp2r3klxjwaj93nh1sbl4xvj9wsha0ic478avz7"; - type = "gem"; - }; - version = "2.2.0"; - }; tzinfo = { dependencies = ["concurrent-ruby"]; groups = ["default"]; @@ -428,14 +294,4 @@ }; version = "2.4.2"; }; - yard = { - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "013yrnwx1zhzhn1fnc19zck22a1qgimsaglp2iwgf5bz9l8h93js"; - type = "gem"; - }; - version = "0.9.34"; - }; } diff --git a/modules/languages/ruby/ruby.nix b/modules/languages/ruby/ruby.nix index aa7658ac..4335daea 100644 --- a/modules/languages/ruby/ruby.nix +++ b/modules/languages/ruby/ruby.nix @@ -6,19 +6,52 @@ }: with lib; with builtins; let - format-env = pkgs.callPackage ./format_derivation.nix {inherit pkgs;}; + formatter-env = with pkgs; + bundlerEnv { + name = "Gem dependencies"; + inherit ruby_3_2; + ruby = ruby_3_2; + gemdir = ./.; + #gemConfig = + # pkgs.defaultGemConfig + # // { + # nokogiri = attrs: { + # buildFlags = ["--use-system-libraries"]; # "--with-zlib-include=${pkgs.zlib}/include/libxml2"]; + #}; + # }; + }; + #format-env = pkgs.callPackage ./format-derivation.nix {inherit pkgs;}; cfg = config.vim.languages.ruby; defaultServer = "rubyserver"; servers = { rubyserver = { - package = pkgs.rubyPackages_3_2.solargraph; + package = pkgs.rubyPackages_3_2.solargraph.overrideAttrs ( + fa: oa: { + buildInputs = oa.buildInputs ++ [formatter-env]; + } + ); lspConfig = '' lspconfig.solargraph.setup { + capabilities = capabilities, on_attach = attach_keymaps, - cmd = { "${cfg.lsp.package}/bin/solargraph", "stdio" } + --cmd = { "${pkgs.ruby_3_2}/bin/bundle exec solargraph", "stdio" } + cmd = { "${cfg.lsp.package}/bin/solargraph", "stdio" }, + settings = { + solargraph = { + diagnostics = true, + autoformat = true, + -- bundlerPath = "${pkgs.ruby_3_2}/bin/bundler", + completion = true, + formatting = true, + logLevel = "debug", + references = true, + useBundler = false + } + } } + ''; }; }; @@ -27,33 +60,33 @@ with builtins; let defaultFormat = "rubocop"; formats = { rubocop = { - package = format-env; + package = pkgs.rubyPackages_3_2.rubocop.overrideAttrs ( + fa: oa: { + buildInputs = oa.buildInputs ++ [formatter-env]; + } + ); nullConfig = '' - lspconfig.rubocop.setup { - on_attach = attach_keymaps, - cmd = { "${cfg.format.package}/bin/rubocop", "--lsp", "--require", "${cfg.format.package}/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.20.2/lib/rubocop-rails.rb" } - } - -- local conditional = function(fn) - -- local utils = require("null-ls.utils").make_conditional_utils() - -- return fn(utils) - -- end - -- - -- table.insert( - -- ls_sources, - -- conditional(function(utils) - -- return utils.root_has_file("Gemfile") - -- and null_ls.builtins.formatting.rubocop.with({ - -- command = ", - -- args = vim.list_extend( - -- { "exec", "rubocop" }, - -- nls.builtins.formatting.rubocop._opts.args - -- ), - -- }) - -- or null_ls.builtins.formatting.rubocop.with({ - -- command = "${cfg.format.package}/bin/rubocop", - -- }) - -- end) - -- ) + lspconfig.rubocop.setup { + on_attach = attach_keymaps, + cmd = { "${cfg.format.package}/bin/rubocop", "--require", "${formatter-env}/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.20.2/lib/rubocop-rails.rb"} --, nls.builtins.formatting.rubocop._opts.args } + } + -- local conditional = function(fn) + -- local utils = require("null-ls.utils").make_conditional_utils() + -- return fn(utils) + -- end + -- + -- table.insert( + -- ls_sources, + -- null_ls.builtins.formatting.rubocop.with({ + -- command = "${cfg.format.package}/bin/rubocop", + -- args = { "--require", "${formatter-env}/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.20.2/lib/rubocop-rails.rb"} + -- }) + -- ) + -- or null_ls.builtins.formatting.rubocop.with({ + -- command = "${cfg.format.package}/bin/rubocop", + -- }) + -- end) + -- ) ''; }; };