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

View file

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

View file

@ -15,14 +15,28 @@ in {
enable = true;
cmdline = {
"/" = {
mapping = mkRaw "cmp.mapping.preset.cmdline()";
mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.cmdline()
'';
sources = [
{name = "rg";}
{name = "buffer";}
];
};
":" = {
mapping = mkRaw "cmp.mapping.preset.cmdline()";
mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.cmdline()
'';
sources = [
{name = "path";}
{name = "cmdline";}
@ -31,7 +45,13 @@ in {
};
settings = {
# 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
sources = [
{
@ -83,7 +103,12 @@ in {
groupIndex = 1;
}
];
mapping = mkRaw ''
mapping =
mkRaw
/*
lua
*/
''
cmp.mapping.preset.insert({
["<C-n>"] = function(fallback)
if cmp.visible() then

View file

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