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

View file

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

View file

@ -1,93 +1,6 @@
(let [mod {}
current-function-symbols {:Array "ﴳ "
:Class " "
:Enum "ﴳ "
:Function " "
:Interface " "
:Method " "
:Module " "
:Namespace " "
:Package " "
:Struct "ﴳ "}
spinner-frames ["⣾" "⣽" "⣻" "⢿" "⡿" "⣟" "⣯" "⣷"]
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)))
client-notifications {}]
;; Progress Notifications
;; Based on: https://github.com/rcarriga/nvim-notify/wiki/Usage-Recipes#progress-updates
@ -157,18 +70,5 @@
(fn mod.register-progress-handler []
(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)

View file

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

View file

@ -1,10 +1,11 @@
(let [lsp (require :lspconfig)
cmp (require :cmp_nvim_lsp)
navic (require :nvim-navic)
nifoc-lsp (require :nifoc.lsp)
diagnostic (require :nifoc.diagnostic)
formatting (require :nifoc.formatting)]
(fn custom-attach [client bufnr]
(nifoc-lsp.on-attach client bufnr)
(navic.attach client bufnr)
(diagnostic.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;
withPython3 = false;
extraConfig = ''
lua << EOF
require('nifoc.nix')
require('impatient')
require('configuration.init')
EOF
'';
extraLuaPackages = with pkgs; [ luarocks-jsregexp ];
extraPackages = with pkgs; [
@ -57,7 +49,16 @@ in
plugins = (with customPlugins; [
# Fixes
impatient-nvim
{
plugin = impatient-nvim;
config = ''
-- Nix init.lua workaround
require('nifoc.nix')
require('impatient')
require('configuration.init')
'';
type = "lua";
}
# Utils
popup-nvim
@ -176,6 +177,12 @@ in
lspkind-nvim
{
plugin = nvim-navic;
config = builtins.readFile ../../config/nvim/plugins/navic.fnl;
type = "fennel";
}
{
plugin = vim-illuminate;
config = builtins.readFile ../../config/nvim/plugins/illuminate.fnl;

View file

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

View file

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