[feat] nvim: highlight lua codesnippets
All checks were successful
/ check (push) Successful in 29s
/ build (docs) (push) Successful in 2s
/ build (nixosConfigurations.vm.config.system.build.toplevel) (push) Successful in 24s
/ build (nvim) (push) Successful in 16s

Adding a comment with the language will automatically highlight the
code:

```nix
luaCode = /*lua*/ ''
    function() return "look ma I'm highlighted!" end
'';
```

(May only work using treesitter)
This commit is contained in:
Jalil David Salamé Messina 2024-07-02 09:29:44 +02:00
parent 351e042a7c
commit dc130e4723
Signed by: jalil
GPG key ID: F016B9E770737A0B
4 changed files with 227 additions and 103 deletions

View file

@ -12,7 +12,12 @@ in {
group = "highlightOnYank"; group = "highlightOnYank";
event = "TextYankPost"; event = "TextYankPost";
pattern = "*"; pattern = "*";
callback = mkRaw '' callback =
mkRaw
/*
lua
*/
''
function() function()
vim.highlight.on_yank { vim.highlight.on_yank {
higroup = ( higroup = (
@ -27,7 +32,12 @@ in {
group = "restoreCursorPosition"; group = "restoreCursorPosition";
event = "BufReadPost"; event = "BufReadPost";
pattern = "*"; pattern = "*";
callback = mkRaw '' callback =
mkRaw
/*
lua
*/
''
function() function()
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
vim.cmd [[execute "normal! g'\""]] vim.cmd [[execute "normal! g'\""]]
@ -42,7 +52,11 @@ in {
callback = let callback = let
opts = "noremap = true, buffer = bufnr"; opts = "noremap = true, buffer = bufnr";
in in
mkRaw '' mkRaw
/*
lua
*/
''
function(opts) function(opts)
local bufnr = opts.buf local bufnr = opts.buf
local client = vim.lsp.get_client_by_id(opts.data.client_id) local client = vim.lsp.get_client_by_id(opts.data.client_id)

View file

@ -51,99 +51,180 @@ in {
{ {
mode = "n"; mode = "n";
key = "<leader>dj"; key = "<leader>dj";
action = mkRaw "vim.diagnostic.goto_next"; action =
mkRaw
# lua
''
vim.diagnostic.goto_next
'';
options.desc = "Diagnostics next [J]"; options.desc = "Diagnostics next [J]";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>dk"; key = "<leader>dk";
action = mkRaw "vim.diagnostic.goto_prev"; action =
mkRaw
# lua
''
vim.diagnostic.goto_prev
'';
options.desc = "Diagnostics previous [K]"; options.desc = "Diagnostics previous [K]";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>xx"; key = "<leader>xx";
action = mkRaw "require('trouble').toggle"; action =
mkRaw
# lua
''
require('trouble').toggle
'';
options.desc = "Toggle trouble"; options.desc = "Toggle trouble";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>xw"; key = "<leader>xw";
action = mkRaw "function() require('trouble').toggle('workspace_diagnostics') end"; action =
mkRaw
# lua
''
function() require('trouble').toggle('workspace_diagnostics') end
'';
options.desc = "Toggle Workspace trouble"; options.desc = "Toggle Workspace trouble";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>xd"; key = "<leader>xd";
action = mkRaw "function() require('trouble').toggle('document_diagnostics') end"; action =
mkRaw
# lua
''
function() require('trouble').toggle('document_diagnostics') end
'';
options.desc = "Toggle Document trouble"; options.desc = "Toggle Document trouble";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>xq"; key = "<leader>xq";
action = mkRaw "function() require('trouble').toggle('quickfix') end"; action =
mkRaw
# lua
''
function() require('trouble').toggle('quickfix') end
'';
options.desc = "Toggle Quickfix trouble"; options.desc = "Toggle Quickfix trouble";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>xl"; key = "<leader>xl";
action = mkRaw "function() require('trouble').toggle('loclist') end"; action =
mkRaw
# lua
''
function() require('trouble').toggle('loclist') end
'';
options.desc = "Toggle Loclist trouble"; options.desc = "Toggle Loclist trouble";
} }
{ {
mode = "n"; mode = "n";
key = "gR"; key = "gR";
action = mkRaw "function() require('trouble').toggle('lsp_references') end"; action =
mkRaw
# lua
''
function() require('trouble').toggle('lsp_references') end
'';
options.desc = "Toggle lsp References trouble"; options.desc = "Toggle lsp References trouble";
} }
# Telescope # Telescope
{ {
mode = "n"; mode = "n";
key = "<leader>ff"; key = "<leader>ff";
action = mkRaw "require('telescope.builtin').find_files"; action =
mkRaw
# lua
''
require('telescope.builtin').find_files
'';
options.desc = "Find Files"; options.desc = "Find Files";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>fg"; key = "<leader>fg";
action = mkRaw "require('telescope.builtin').live_grep"; action =
mkRaw
# lua
''
require('telescope.builtin').live_grep
'';
options.desc = "Find Grep"; options.desc = "Find Grep";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>fh"; key = "<leader>fh";
action = mkRaw "require('telescope.builtin').help_tags"; action =
mkRaw
# lua
''
require('telescope.builtin').help_tags
'';
options.desc = "Find Help"; options.desc = "Find Help";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>fb"; key = "<leader>fb";
action = mkRaw "require('telescope.builtin').buffers"; action =
mkRaw
# lua
''
require('telescope.builtin').buffers
'';
options.desc = "Find Buffer"; options.desc = "Find Buffer";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>fd"; key = "<leader>fd";
action = mkRaw "require('telescope.builtin').diagnostics"; action =
mkRaw
# lua
''
require('telescope.builtin').diagnostics
'';
options.desc = "Find Diagnostics"; options.desc = "Find Diagnostics";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>fq"; key = "<leader>fq";
action = mkRaw "require('telescope.builtin').quickfix"; action =
mkRaw
# lua
''
require('telescope.builtin').quickfix
'';
options.desc = "Find Quickfix"; options.desc = "Find Quickfix";
} }
{ {
mode = "n"; mode = "n";
key = "<leader>w"; key = "<leader>w";
action = mkRaw "require('conform').format"; action =
mkRaw
# lua
''
require('conform').format
'';
options.desc = "Format buffer"; options.desc = "Format buffer";
} }
# Nvim Silicon # Nvim Silicon
{ {
mode = "v"; mode = "v";
key = "<leader>sc"; key = "<leader>sc";
action = mkRaw "require('nvim-silicon').clip"; action =
mkRaw
# lua
''
require('nvim-silicon').clip
'';
options.desc = "Snap Code (to clipboard)"; options.desc = "Snap Code (to clipboard)";
} }
]; ];

View file

@ -15,14 +15,28 @@ in {
enable = true; enable = true;
cmdline = { cmdline = {
"/" = { "/" = {
mapping = mkRaw "cmp.mapping.preset.cmdline()"; mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.cmdline()
'';
sources = [ sources = [
{name = "rg";} {name = "rg";}
{name = "buffer";} {name = "buffer";}
]; ];
}; };
":" = { ":" = {
mapping = mkRaw "cmp.mapping.preset.cmdline()"; mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.cmdline()
'';
sources = [ sources = [
{name = "path";} {name = "path";}
{name = "cmdline";} {name = "cmdline";}
@ -31,7 +45,13 @@ in {
}; };
settings = { settings = {
# Snippets # Snippets
snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end"; snippet.expand =
/*
lua
*/
''
function(args) require('luasnip').lsp_expand(args.body) end
'';
# Completion Sources # Completion Sources
sources = [ sources = [
{ {
@ -83,7 +103,12 @@ in {
groupIndex = 1; groupIndex = 1;
} }
]; ];
mapping = mkRaw '' mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.insert({ cmp.mapping.preset.insert({
["<C-n>"] = function(fallback) ["<C-n>"] = function(fallback)
if cmp.visible() then if cmp.visible() then

View file

@ -55,7 +55,9 @@
pkgs.unstable.typos pkgs.unstable.typos
pkgs.unstable.yamlfmt pkgs.unstable.yamlfmt
]; ];
extraConfigLuaPre = '' extraConfigLuaPre =
# lua
''
-- Lua Pre Config -- Lua Pre Config
if vim.fn.has 'termguicolors' then if vim.fn.has 'termguicolors' then
-- Enable RGB colors -- Enable RGB colors
@ -71,7 +73,9 @@
end end
-- END: Lua Pre Config -- END: Lua Pre Config
''; '';
extraConfigLua = '' extraConfigLua =
# lua
''
-- Lua Config -- Lua Config
require("nvim-silicon").setup { require("nvim-silicon").setup {
theme = "gruvbox-dark", theme = "gruvbox-dark",