1
0
Fork 0

nvim: Switch to navic for statusline component

This commit is contained in:
Daniel Kempkens 2022-09-22 22:34:18 +02:00
parent f649e7af74
commit fff3e87a27
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
9 changed files with 105 additions and 161 deletions

View file

@ -79,11 +79,11 @@
"utils": "utils" "utils": "utils"
}, },
"locked": { "locked": {
"lastModified": 1663629861, "lastModified": 1663835995,
"narHash": "sha256-CjfQUyPfG/hkE4jnMcTvVJ0ubc84u8ySruZL+emXMjw=", "narHash": "sha256-XNHQ+mdHbjNR1Oit00SFAEcrAZoCS08E7uAFcVMtwhM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "41790ba656bafc023f48ccdbbe7816d30fd52d76", "rev": "bd83eab6220226085c82e637931a7ae3863d9893",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -102,11 +102,11 @@
}, },
"locked": { "locked": {
"dir": "contrib", "dir": "contrib",
"lastModified": 1663729599, "lastModified": 1663849534,
"narHash": "sha256-G0XDKMKDcBiVjPa+jJ6SIy+KezZVbynUJSetzqUXdl8=", "narHash": "sha256-jnq3slKrVKgB9GB0hJMM9yhd8bGpPetz08IhW5xQzlM=",
"owner": "neovim", "owner": "neovim",
"repo": "neovim", "repo": "neovim",
"rev": "37a71d1f28e5d7fd13f0ede69b4d2558157a9e4b", "rev": "2083c1771ad2de44c8e085062a0777e694b0fd4d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -125,11 +125,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1663748605, "lastModified": 1663850734,
"narHash": "sha256-1X93+V48aky84deB3EmP+OBGqDO2QOD5gqErgKMQXQQ=", "narHash": "sha256-CBadw7/b/xcup2fq4PKt6j+QrML3H+vF9PQeFwcD1oE=",
"owner": "nix-community", "owner": "nix-community",
"repo": "neovim-nightly-overlay", "repo": "neovim-nightly-overlay",
"rev": "11777416d08d58d0ca06eef9e62c920c02fae396", "rev": "23a4428b7f3fb269e0ff759e862c8e2c3ea92a21",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -145,11 +145,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1663749350, "lastModified": 1663835611,
"narHash": "sha256-Nb4YxjgwlUpN5pdsrEUIwynW8KoMvNmcv8OSNDZAcM0=", "narHash": "sha256-vlnm+Ns9kEU86fXEs5EbWS0W0Msrei/0XkF+Qwlkh4s=",
"owner": "nifoc", "owner": "nifoc",
"repo": "nix-overlay", "repo": "nix-overlay",
"rev": "324ba4f0d10e319391220b9e78742c645837508d", "rev": "6654eff049a1a3a30d80bcab6164274d5dccff0e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -160,11 +160,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1663669617, "lastModified": 1663846470,
"narHash": "sha256-yUrzkRDc6P3hsI5TdQ5+q8gnyjadNvaM3MMEsEVS8qk=", "narHash": "sha256-pXdsi67t8Ybk5rTALoIH8PHT9Lr4X/HFB9G1ucCDo2g=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "41ac0bd371618db6dd67fd952cc5b3d6a9955a15", "rev": "8fcb549a66d1996c88a63fb9b74a28e4663923c9",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -99,9 +99,7 @@
#(telescope-builtin.lsp_implementations telescope-dropdown) #(telescope-builtin.lsp_implementations telescope-dropdown)
{:buffer bufnr :desc "Find Implementations"}) {:buffer bufnr :desc "Find Implementations"})
(keymap.set :n :K vim.lsp.buf.hover (keymap.set :n :K vim.lsp.buf.hover
{:buffer bufnr :desc "Show Documentation"}) {:buffer bufnr :desc "Show Documentation"}))
(keymap.set :n :<leader>ddsc nifoc-lsp.symbols-under-cursor
{:buffer bufnr :desc "Document Symbols Under Cursor"}))
(fn mod.terminal-open [bufnr] (fn mod.terminal-open [bufnr]
(let [map-opts {:buffer bufnr}] (let [map-opts {:buffer bufnr}]

View file

@ -1,93 +1,6 @@
(let [mod {} (let [mod {}
current-function-symbols {:Array "ﴳ "
:Class " "
:Enum "ﴳ "
:Function " "
:Interface " "
:Method " "
:Module " "
:Namespace " "
:Package " "
:Struct "ﴳ "}
spinner-frames ["⣾" "⣽" "⣻" "⢿" "⡿" "⣟" "⣯" "⣷"] spinner-frames ["⣾" "⣽" "⣻" "⢿" "⡿" "⣟" "⣯" "⣷"]
client-notifications {} client-notifications {}]
lsp-proto vim.lsp.protocol
set-bufvar vim.api.nvim_buf_set_var
augroup (vim.api.nvim_create_augroup :NifocLsp {:clear true})
aucmd vim.api.nvim_create_autocmd]
(fn filter-sorted-table [test list]
(let [results []]
(each [_ item (ipairs list)]
(when (test item)
(table.insert results item)))
results))
;; Current LSP Context
;; Based on https://github.com/nvim-lua/lsp-status.nvim
(fn extract-symbols [acc items]
(if (= items nil)
acc
(do
(each [_ item (ipairs items)]
(local kind (or (. lsp-proto.SymbolKind item.kind) :Unknown))
(var sym-range nil)
(if item.location (set sym-range item.location.range)
item.range (set sym-range item.range))
(when sym-range
(do
(set sym-range.start.line (+ sym-range.start.line 1))
(set sym-range.end.line (+ sym-range.end.line 1))))
(table.insert acc {:range sym-range : kind :text item.name})
(when item.children
(extract-symbols acc item.children)))
acc)))
(fn current-function-symbol? [item]
(and item.range (not= (. current-function-symbols item.kind) nil)))
(fn cursor-in-range? [cursor sym]
(let [line (. cursor 1)
char (. cursor 2)]
(if (or (< line sym.start.line) (> line sym.end.line)) false
(and (= line sym.start.line) (< char sym.start.character)) false
(and (= line sym.end.line) (> char sym.end.character)) false
true)))
(fn handle-symbols-under-cursor [err result ctx config]
(when (and (= err nil) (= (type result) :table))
(let [symbols (extract-symbols [] result)
cursor-pos (vim.api.nvim_win_get_cursor 0)]
(print (.. "Symbols at under current position (" (. cursor-pos 1) ":"
(. cursor-pos 2) ")"))
(each [_ sym (ipairs symbols)]
(when (cursor-in-range? cursor-pos sym.range)
(print (.. sym.kind ": " sym.text " (" sym.range.start.line ":"
sym.range.start.character " - " sym.range.end.line ":"
sym.range.end.character ")")))))))
(fn handle-update-current-context [err result ctx config]
(var context-levels [])
(when (and (= err nil) (= (type result) :table))
(let [filtered-symbols (->> result (extract-symbols [])
(filter-sorted-table current-function-symbol?))
cursor-pos (vim.api.nvim_win_get_cursor 0)]
(each [_ sym (ipairs filtered-symbols)]
(when (cursor-in-range? cursor-pos sym.range)
(let [current-context (.. (. current-function-symbols sym.kind)
sym.text)]
(table.insert context-levels current-context))))))
(let [current-context vim.b.nifoc_lsp_current_context
new-context (table.concat context-levels "  ")]
(when (not= current-context new-context)
(set-bufvar ctx.bufnr :nifoc_lsp_current_context new-context)
(vim.api.nvim_cmd {:cmd :redrawstatus} []))))
(fn update-current-context [bufnr]
(let [params {:textDocument (vim.lsp.util.make_text_document_params bufnr)}]
(vim.lsp.buf_request bufnr :textDocument/documentSymbol params
handle-update-current-context)))
;; Progress Notifications ;; Progress Notifications
;; Based on: https://github.com/rcarriga/nvim-notify/wiki/Usage-Recipes#progress-updates ;; Based on: https://github.com/rcarriga/nvim-notify/wiki/Usage-Recipes#progress-updates
@ -157,18 +70,5 @@
(fn mod.register-progress-handler [] (fn mod.register-progress-handler []
(tset vim.lsp.handlers :$/progress handle-progress)) (tset vim.lsp.handlers :$/progress handle-progress))
(fn mod.symbols-under-cursor []
(let [params {:textDocument (vim.lsp.util.make_text_document_params 0)}]
(vim.lsp.buf_request 0 :textDocument/documentSymbol params
handle-symbols-under-cursor)))
(fn mod.on-attach [client bufnr]
(when (client.supports_method :textDocument/documentSymbol)
(aucmd [:CursorHold]
{:callback #(update-current-context bufnr)
:buffer bufnr
:group augroup
:desc "Update current function variable"})))
mod) mod)

View file

@ -7,7 +7,8 @@
web-devicons (require :nvim-web-devicons) web-devicons (require :nvim-web-devicons)
colors (. (require :nifoc.theme) :colors) colors (. (require :nifoc.theme) :colors)
formatting (require :nifoc.formatting) formatting (require :nifoc.formatting)
nifoc-treesitter (require :nifoc.treesitter)] nifoc-treesitter (require :nifoc.treesitter)
navic (require :nvim-navic)]
(fn buffer-variable-exists? [key] (fn buffer-variable-exists? [key]
(not= (. vim :b key) nil)) (not= (. vim :b key) nil))
@ -225,18 +226,11 @@
(set mod.current-function (set mod.current-function
{:condition heirline-conditions.lsp_attached {:condition heirline-conditions.lsp_attached
:init (fn [self] :init (fn [self]
(let [ctx vim.b.nifoc_lsp_current_context] (if (navic.is_available)
(if (and (not= ctx nil) (> (ctx:len) 0)) (set self.check-length 1)
(do (set self.check-length 0)))
(set self.current-ctx ctx)
(set self.check-length 1))
(do
(set self.current-ctx nil)
(set self.check-length 0)))))
1 mod.space-if-length 1 mod.space-if-length
2 {:provider (fn [self] 2 {:provider #(navic.get_location) :hl {:fg colors.white}}})
self.current-ctx)
:hl {:fg colors.white}}})
;; Buffer Options ;; Buffer Options
(set mod.buffer-options (set mod.buffer-options
{:static {:format {:dos "" :unix "" :mac ""}} {:static {:format {:dos "" :unix "" :mac ""}}

View file

@ -1,10 +1,11 @@
(let [lsp (require :lspconfig) (let [lsp (require :lspconfig)
cmp (require :cmp_nvim_lsp) cmp (require :cmp_nvim_lsp)
navic (require :nvim-navic)
nifoc-lsp (require :nifoc.lsp) nifoc-lsp (require :nifoc.lsp)
diagnostic (require :nifoc.diagnostic) diagnostic (require :nifoc.diagnostic)
formatting (require :nifoc.formatting)] formatting (require :nifoc.formatting)]
(fn custom-attach [client bufnr] (fn custom-attach [client bufnr]
(nifoc-lsp.on-attach client bufnr) (navic.attach client bufnr)
(diagnostic.maybe-enable-lsp client bufnr) (diagnostic.maybe-enable-lsp client bufnr)
(formatting.maybe-enable-lsp client bufnr)) (formatting.maybe-enable-lsp client bufnr))

View file

@ -0,0 +1,32 @@
(let [navic (require :nvim-navic)]
(navic.setup {:icons {:File " "
:Module " "
:Namespace " "
:Package " "
:Class " "
:Method " "
:Property " "
:Field " "
:Constructor " "
:Enum "練"
:Interface "練"
:Function " "
:Variable " "
:Constant " "
:String " "
:Number " "
:Boolean "◩ "
:Array " "
:Object " "
:Key " "
:Null "ﳠ "
:EnumMember " "
:Struct " "
:Event " "
:Operator " "
:TypeParameter " "}
:highlight false
:separator "  "
:depth_limit 0
:depth_limit_indicator ".."}))

View file

@ -14,14 +14,6 @@ in
withRuby = false; withRuby = false;
withPython3 = false; withPython3 = false;
extraConfig = ''
lua << EOF
require('nifoc.nix')
require('impatient')
require('configuration.init')
EOF
'';
extraLuaPackages = with pkgs; [ luarocks-jsregexp ]; extraLuaPackages = with pkgs; [ luarocks-jsregexp ];
extraPackages = with pkgs; [ extraPackages = with pkgs; [
@ -57,7 +49,16 @@ in
plugins = (with customPlugins; [ plugins = (with customPlugins; [
# Fixes # Fixes
impatient-nvim {
plugin = impatient-nvim;
config = ''
-- Nix init.lua workaround
require('nifoc.nix')
require('impatient')
require('configuration.init')
'';
type = "lua";
}
# Utils # Utils
popup-nvim popup-nvim
@ -176,6 +177,12 @@ in
lspkind-nvim lspkind-nvim
{
plugin = nvim-navic;
config = builtins.readFile ../../config/nvim/plugins/navic.fnl;
type = "fennel";
}
{ {
plugin = vim-illuminate; plugin = vim-illuminate;
config = builtins.readFile ../../config/nvim/plugins/illuminate.fnl; config = builtins.readFile ../../config/nvim/plugins/illuminate.fnl;

View file

@ -47,12 +47,12 @@ rec {
}; };
nvim-osc52 = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-osc52 = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-osc52"; pname = "nvim-osc52";
version = "2022-08-16"; version = "2022-09-22";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "ojroques"; owner = "ojroques";
repo = "nvim-osc52"; repo = "nvim-osc52";
rev = "6ebd6f3fec198b7b4d7aedd2b0619cd05ebcbaac"; rev = "64e0ddff70e5940c6a28f313c920e85aa6a4cfe1";
sha256 = "0jqglb3cpc5lrdxk5zpq7wpbccp94xydxdqs75r0mi9619lx9jkh"; sha256 = "09n418nnccihknns8bfq6m9cr6rnykzf0inzzsy8qdzbc6zggdbg";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
@ -241,34 +241,45 @@ rec {
}; };
lspkind-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { lspkind-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "lspkind.nvim"; pname = "lspkind.nvim";
version = "2022-09-13"; version = "2022-09-22";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "onsails"; owner = "onsails";
repo = "lspkind.nvim"; repo = "lspkind.nvim";
rev = "f46e3b5528e73347dc0678277460e5cea2a52b6a"; rev = "c68b3a003483cf382428a43035079f78474cd11e";
sha256 = "09kg1ax5xmy8jbi95bqngx0lrpc9mvl0cdkgmfzsr16p9mfbf5rl"; sha256 = "0qrfqajpbkb757vbcjz1g7v5rihsyhg1f1jxrbwg08dbxpw101av";
fetchSubmodules = false;
};
};
nvim-navic = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-navic";
version = "2022-09-05";
src = pkgs.fetchFromGitHub {
owner = "SmiteshP";
repo = "nvim-navic";
rev = "202312e93869213c574d200a40eafeff4b4caec2";
sha256 = "0dkxsrdzplg2a3gbgjv2ddwkqv80w870nzmq767f6j8ydb5ny3la";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
vim-illuminate = pkgs.vimUtils.buildVimPluginFrom2Nix { vim-illuminate = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "vim-illuminate"; pname = "vim-illuminate";
version = "2022-09-16"; version = "2022-09-22";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "RRethy"; owner = "RRethy";
repo = "vim-illuminate"; repo = "vim-illuminate";
rev = "b5452627d6ef9c04a27ac4edde0b00aa3a50f60f"; rev = "a2e8476af3f3e993bb0d6477438aad3096512e42";
sha256 = "1cvfsdc6ybhzlk1gjdm10d14sb957nd3p7b2kcyinn61nny8pszf"; sha256 = "1wk0gxvljzl6c0vrwb99mvxj755ck1c6jhvn16r1d68kva1f0nkj";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
nvim-lint = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-lint = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-lint"; pname = "nvim-lint";
version = "2022-08-25"; version = "2022-09-21";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "mfussenegger"; owner = "mfussenegger";
repo = "nvim-lint"; repo = "nvim-lint";
rev = "b551a7218c802a5b361dd46857af4945fe779dcd"; rev = "1b3468b07452e3736b67afd43547f766cc1db307";
sha256 = "09dlqcfgandw7v08w8nfs8b277z9za01l6zm80c4i2p8h9xpn6fc"; sha256 = "096yp2lpqkr7fv2nh3kk3v06d5mcy1lsr0x3d0y3j7zsy2xxn8fb";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
@ -454,8 +465,8 @@ rec {
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "andymass"; owner = "andymass";
repo = "vim-matchup"; repo = "vim-matchup";
rev = "62cbb1082fc3e3df039892a9ea76b3aca382f81a"; rev = "80ad7817e58755a602f993163f61f3500978ebe5";
sha256 = "1gpy4wqgpvil892iisgsg2348sw1mccwkj10glkzxaajbfafkyjf"; sha256 = "1q001rwqp04nl09xl32c328vbbdmm9n51i3a8wszqpz3blp4jl3s";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
@ -483,12 +494,12 @@ rec {
}; };
heirline-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { heirline-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "heirline.nvim"; pname = "heirline.nvim";
version = "2022-09-09"; version = "2022-09-22";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "rebelot"; owner = "rebelot";
repo = "heirline.nvim"; repo = "heirline.nvim";
rev = "8a8d66122ed05a47910b470ec3361258f6938798"; rev = "9179b71d9967057814e5920ecb3c8322073825ea";
sha256 = "18fbg3ha2yq0sb29pn2wb5v94y29ssqrqa8wq6dxm97s7pgvq6zk"; sha256 = "0xmg461vzwj85ayfhqzxdc3lvg55b2ywzrdh84k5lw6yszw1k2g4";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };
@ -549,12 +560,12 @@ rec {
}; };
nvim-notify = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-notify = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-notify"; pname = "nvim-notify";
version = "2022-09-19"; version = "2022-09-22";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "rcarriga"; owner = "rcarriga";
repo = "nvim-notify"; repo = "nvim-notify";
rev = "7a9be08986b4d98dd685a6b40a62fcba19c1ad27"; rev = "3a8ec89e1918ea2acbb9b22c5ac2006d31773052";
sha256 = "1qac3wfrc9hms18kh9ahqlj966d0zxjj9jvww1s83fhbihhf0453"; sha256 = "00ixzciwgzpi2sg6s5cyw8101nnwrv0ks8x77mcqrvpmqnlg6hky";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };

View file

@ -41,6 +41,7 @@
# LSP # LSP
- src: neovim/nvim-lspconfig - src: neovim/nvim-lspconfig
- src: onsails/lspkind.nvim - src: onsails/lspkind.nvim
- src: SmiteshP/nvim-navic
- src: RRethy/vim-illuminate - src: RRethy/vim-illuminate
# Linter # Linter