Skip to content

Commit

Permalink
nvim tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
viperML committed Aug 14, 2024
1 parent 06876c1 commit 369f7fe
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion modules/home-manager/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pkgs.nix-output-monitor
pkgs.nil
self'.packages.env
pkgs.nodePackages.bash-language-server
# pkgs.nodePackages.bash-language-server
];

# home.sessionVariables = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ local mapping = cmp.mapping.preset.insert {
fallback()
end
end, { "i", "s", "c" }),
["<Down>"] = cmp.mapping(function(callback)
["<Down>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
fallback()
if fallback ~= nil then
fallback()
end
end
end, {"i","s","c"}),
["<Up>"] = cmp.mapping(function(callback)
["<Up>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
else
fallback()
if fallback ~= nil then
fallback()
end
end
end, {"i","s","c"}),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- on_new_config = function(config, new_root_dir)
-- end,

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require("viper.dap")
require("viper.tree-sitter")
require("viper.format")
require("viper.org")
require("viper.direnv")

require("neovim-project").setup {
projects = {
Expand Down
88 changes: 69 additions & 19 deletions modules/wrapper-manager/neovim/viper-init-plugin/lua/viper/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ vim.filetype.add {
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local nvim_lsp = require("lspconfig")

nvim_lsp.util.on_setup = nvim_lsp.util.add_hook_before(nvim_lsp.util.on_setup, function(config)
local bin_name = config.cmd[1]

if bin_name ~= nil then
local bin_exists = vim.fn.executable(bin_name)

if bin_exists == 0 then
-- config.root_dir = nil -- doesn't work?
config.autostart = false
end
end
end)

local root_pattern = nvim_lsp.util.root_pattern

Expand Down Expand Up @@ -126,10 +114,6 @@ nvim_lsp.mesonlsp.setup {
capabilities = capabilities,
}

nvim_lsp.bashls.setup {
capabilities = capabilities,
}

nvim_lsp.hls.setup {
capabilities = capabilities,
}
Expand Down Expand Up @@ -169,9 +153,9 @@ nvim_lsp.pylsp.setup {

-- Schemas
-- https://www.arthurkoziel.com/json-schemas-in-neovim/
nvim_lsp.taplo.setup { -- toml
capabilities = capabilities,
}
-- nvim_lsp.taplo.setup { -- toml
-- capabilities = capabilities,
-- }
nvim_lsp.yamlls.setup {
capabilities = capabilities,
settings = {
Expand All @@ -192,3 +176,69 @@ nvim_lsp.yamlls.setup {
},
},
}

local configs = {
["taplo"] = {},
["bashls"] = {},
}


nvim_lsp.util.on_setup = nvim_lsp.util.add_hook_before(nvim_lsp.util.on_setup, function(config)
vim.notify("> setuphook " .. config.name)
local bin_name = config.cmd[1]

if bin_name ~= nil then
local bin_exists = vim.fn.executable(bin_name)

if bin_exists == 0 then
config.autostart = false
vim.notify("Disabling " .. config.name)
else
config.autostart = true
vim.notify("Enabling " .. config.name)
end
else
vim.notify("bin_name was nil")
end

vim.notify("< setuphook " .. config.name)
end)

local function setup_all()
for k, v in pairs(configs) do
nvim_lsp[k].setup(v)
end
end

setup_all()

local function stop_all()
-- local clients = vim.lsp.get_clients()
-- for _, client in ipairs(clients) do
-- vim.notify("Stopping client: " .. client.name)
-- client:stop()
-- end
vim.lsp.stop_client(vim.lsp.get_clients(), true)
local clients = vim.lsp.get_clients()
vim.notify("Clients left: " .. vim.inspect(clients))
end


vim.api.nvim_create_autocmd({ "DirChanged" }, {
pattern = "global",
callback = function()
local dir = vim.fn.getcwd()
vim.notify("> dirchanged " .. dir)

stop_all()

local obj = vim.system({"direnv", "export", "vim"},{}):wait()
vim.fn.execute(obj.stdout)

setup_all()

stop_all()

vim.notify("< dirchanged " .. dir)
end
})
5 changes: 5 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/env bash

set -x

(

0 comments on commit 369f7fe

Please sign in to comment.