This commit is contained in:
Nathan Lebrun
2025-07-11 18:36:55 +02:00
parent 91836e8063
commit 6fc940320c
1511 changed files with 674 additions and 102348 deletions

17
nvim/lua/chadrc.lua Normal file
View File

@@ -0,0 +1,17 @@
-- This file needs to have same structure as nvconfig.lua
-- https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua
-- Please read that file to know all available options :(
---@type ChadrcConfig
local M = {}
M.base46 = {
theme = "github_dark",
-- hl_override = {
-- Comment = { italic = true },
-- ["@comment"] = { italic = true },
-- },
}
return M

View File

@@ -0,0 +1,15 @@
local options = {
formatters_by_ft = {
lua = { "stylua" },
-- css = { "prettier" },
-- html = { "prettier" },
},
-- format_on_save = {
-- -- These options will be passed to conform.format()
-- timeout_ms = 500,
-- lsp_fallback = true,
-- },
}
return options

47
nvim/lua/configs/lazy.lua Normal file
View File

@@ -0,0 +1,47 @@
return {
defaults = { lazy = true },
install = { colorscheme = { "nvchad" } },
ui = {
icons = {
ft = "",
lazy = "󰂠 ",
loaded = "",
not_loaded = "",
},
},
performance = {
rtp = {
disabled_plugins = {
"2html_plugin",
"tohtml",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
},
},
},
}

View File

@@ -0,0 +1,20 @@
-- load defaults i.e lua_lsp
require("nvchad.configs.lspconfig").defaults()
local lspconfig = require "lspconfig"
local on_attach = require("nvchad.configs.lspconfig").on_attach
local capabilities = require("nvchad.configs.lspconfig").capabilities
lspconfig.clangd.setup{
on_attach = on_attach,
capabilities = capabilities,
}
-- configuring single server, example: typescript
-- lspconfig.ts_ls.setup {
-- on_attach = nvlsp.on_attach,
-- on_init = nvlsp.on_init,
-- capabilities = nvlsp.capabilities,
-- }

View File

@@ -0,0 +1,13 @@
M.nvimtree = {
git = {
enable = false,
},
renderer = {
highlight_git = false,
icons = {
show = {
git = false,
},
},
},
}

145
nvim/lua/custom/cpp_gen.lua Normal file
View File

@@ -0,0 +1,145 @@
local M = {}
-- Helper function to trim whitespace.
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
-- Main function:
-- filename: The header file name, e.g. "MyClass.hpp"
function M.generate_cpp_file(header_file)
-- Read the header file contents.
if header_file == nil or header_file == "" then
header_file = vim.api.nvim_buf_get_name(0)
end
local file = io.open(header_file, "r")
if not file then
print("Error: could not open file " .. header_file)
return
end
local content = file:read("*a")
file:close()
-- Extract the class name.
-- In this example, we assume the header file name is the same as the class name.
local class_name = header_file:match("([^/\\]+)%.hpp$")
if not class_name then
print("Error: could not determine class name from header file name.")
return
end
-- Prepare a table to store function definitions.
local functions = {}
-- A very simple parser: we assume each function is declared on a single line.
-- Look for setters (e.g., void setSomething(...);)
for line in content:gmatch("[^\r\n]+") do
line = trim(line)
-- Match setters: assume declaration is like "void setX(type x);" (ignoring qualifiers).
local set_func, args = line:match("void%s+(set%u%w*)%s*%(([^)]*)%)")
if set_func then
table.insert(functions, {name = set_func, args = trim(args), return_type = "void"})
end
-- Match getters: assume declaration is like "type getX(void) const;" or similar.
-- We capture the return type, function name and arguments.
local ret_type, get_func, args = line:match("([%w_:<>]+)%s+(get%u%w*)%s*%(([^)]*)%)")
if ret_type and get_func then
table.insert(functions, {name = get_func, args = trim(args), return_type = ret_type})
end
end
-- Start building the content for the .cpp file.
local cpp_lines = {}
table.insert(cpp_lines, '#include "' .. class_name .. '.hpp"')
table.insert(cpp_lines, "") -- blank line
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ CONSTRUCTOR ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
-- Default constructor.
table.insert(cpp_lines, class_name .. "::" .. class_name .. "() {")
table.insert(cpp_lines, "}")
table.insert(cpp_lines, "")
-- Copy constructor.
table.insert(cpp_lines, class_name .. "::" .. class_name .. "(const " .. class_name .. " &other) { *this = other; }")
table.insert(cpp_lines, "")
-- Assignment operator.
table.insert(cpp_lines, class_name .. " &" .. class_name .. "::operator=(const " .. class_name .. " &other) {")
table.insert(cpp_lines, " if (this == &other) { return *this; }")
table.insert(cpp_lines, "")
table.insert(cpp_lines, " // copy")
table.insert(cpp_lines, " return *this;")
table.insert(cpp_lines, "}")
table.insert(cpp_lines, "")
-- Destructor.
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ DESTRUCTOR ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
table.insert(cpp_lines, class_name .. "::~" .. class_name .. "() {")
table.insert(cpp_lines, "}")
table.insert(cpp_lines, "")
-- Generate stubs for other member functions (e.g., set and get functions).
if #functions > 0 then
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ GET() ┃ SET() ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
for _, func in ipairs(functions) do
-- If no arguments, we insert void explicitly.
local args = func.args
if args == "" then
args = "void"
end
local line = func.return_type .. " " .. class_name .. "::" .. func.name .. "(" .. args .. ")"
-- For getters, you might want to mark the function as const.
if func.name:sub(1, 3) == "get" then
line = line .. " const"
end
table.insert(cpp_lines, line .. " {")
if func.name:sub(1, 3) == "get" then
local string = ""
table.insert(cpp_lines, " return this->" .. string.lower(func.name:sub(4, 4)) .. func.name:sub(5, func.name.len(func.name)) .. ";")
end
if func.name:sub(1, 3) == "set" then
local string = ""
table.insert(cpp_lines, " this->" .. string.lower(func.name:sub(4, 4)) .. func.name:sub(5, func.name.len(func.name)) .. " = " .. func.args:gsub('.*% ', '') .. ";")
end
table.insert(cpp_lines, "}")
table.insert(cpp_lines, "")
end
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ MEMBER ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
else
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ GET() ┃ SET() ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
table.insert(cpp_lines, "// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓")
table.insert(cpp_lines, "// ┃ MEMBER ┃")
table.insert(cpp_lines, "// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛")
table.insert(cpp_lines, "")
end
-- Write the generated content to the .cpp file.
local cpp_file = class_name .. ".cpp"
local dir = header_file:match("^(.*[/\\])") or ""
local out = io.open(dir .. cpp_file, "w")
if not out then
print("Error: could not write to file " .. cpp_file)
return
end
out:write(table.concat(cpp_lines, "\n"))
out:close()
print("Generated " .. cpp_file)
end
return M

View File

@@ -0,0 +1,93 @@
local function show_function_lines()
local bufnr = vim.api.nvim_get_current_buf()
local ft = vim.bo[bufnr].filetype
local lang = vim.treesitter.language.get_lang(ft) or ft
local parser = vim.treesitter.get_parser(bufnr, lang)
if not parser then
return
end
local ns = vim.api.nvim_create_namespace('function_lines')
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
-- Tree-sitter query for C functions, with three cases:
-- Case 1: Regular function (no pointer)
-- Case 2: Function returning a pointer (one pointer_declarator)
-- Case 3: Function returning a double pointer (two pointer_declarator nodes)
local query = vim.treesitter.query.parse(lang, [[
; Case 1: Regular function (no pointer)
(function_definition
declarator: (function_declarator
declarator: (identifier) @func_name
)
body: (compound_statement) @func_body
) @func;
; Case 2: Function returning a pointer (one pointer_declarator)
(function_definition
declarator: (pointer_declarator
declarator: (function_declarator
declarator: (identifier) @func_name
)
)
body: (compound_statement) @func_body
) @func;
; Case 3: Function returning a double pointer (two pointer_declarator nodes)
(function_definition
declarator: (pointer_declarator
declarator: (pointer_declarator
declarator: (function_declarator
declarator: (identifier) @func_name
)
)
)
body: (compound_statement) @func_body
) @func
]])
for _, tree in ipairs(parser:parse()) do
local root = tree:root()
-- Iterate over each capture from the query
for id, node, _ in query:iter_captures(root, bufnr, 0, -1) do
if query.captures[id] == "func_body" then
-- Get the range of the compound statement.
-- The range includes the braces, so we subtract 2 to get the interior.
local start_line, _, end_line, _ = node:range()
local total_lines = end_line - start_line - 1
if total_lines < 0 then
total_lines = 0
end
-- Get the lines between the braces.
local lines = vim.api.nvim_buf_get_lines(bufnr, start_line + 1, end_line, false)
local comment_lines = 0
for _, line in ipairs(lines) do
-- Adjust this pattern as needed for your comment style.
if line:match("^%s*//") then
comment_lines = comment_lines + 1
end
end
local non_comment_lines = total_lines - comment_lines
-- Prepare the virtual text.
local virt_text = nil
if comment_lines > 0 then
-- If there are comment lines, display two numbers:
-- Total lines / non-comment lines.
virt_text = {{ ' 󰆧 ' .. total_lines .. ' / ' .. non_comment_lines, 'Comment' }}
else
-- If no comments, display only the total line count.
virt_text = {{ ' 󰆧 ' .. total_lines, 'Comment' }}
end
-- Place the virtual text on the closing brace line.
vim.api.nvim_buf_set_extmark(bufnr, ns, end_line, -1, {
virt_text = virt_text,
virt_text_pos = 'eol',
})
end
end
end
end
-- Auto-command to run the function for C files on buffer enter or after writing.
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost' }, {
pattern = '*.c',
callback = show_function_lines,
})-- Auto-command to run the function for C files on buffer enter or after writing.
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost' }, {
pattern = '*.c',
callback = show_function_lines,
})

View File

@@ -0,0 +1,42 @@
local M = {}
function M.generate_hpp_file(class_name)
local class = class_name
local hpp_lines = {}
table.insert(hpp_lines, "#ifndef " .. class.upper(class) .. "_HPP")
table.insert(hpp_lines, "# define " .. class.upper(class) .. "_HPP")
table.insert(hpp_lines, "")
table.insert(hpp_lines, "class " .. class .. " {")
table.insert(hpp_lines, " protected:")
table.insert(hpp_lines, "")
table.insert(hpp_lines, " private:")
table.insert(hpp_lines, "")
table.insert(hpp_lines, " public:")
table.insert(hpp_lines, " " .. cCass .. "();")
table.insert(hpp_lines, "")
table.insert(hpp_lines, " ~" .. class .. "();")
table.insert(hpp_lines, "")
table.insert(hpp_lines, " " .. class .. "(const " .. class .. " &other);")
table.insert(hpp_lines, " " .. class .. " &operator=(const " .. class .. " &other);")
table.insert(hpp_lines, "")
table.insert(hpp_lines, "};")
table.insert(hpp_lines, " // Member")
table.insert(hpp_lines, "")
table.insert(hpp_lines, "#endif")
local hpp_file = class .. ".hpp"
local out = io.open(hpp_file, "w")
if not out then
print("Error: Could not create hpp file")
return
end
out:write(table.concat(hpp_lines, "\n"))
out:close()
print("Generated " .. hpp_file)
end
return M

82
nvim/lua/header.lua Normal file
View File

@@ -0,0 +1,82 @@
local M = {}
local HEADER_LINE_LENGTH = 80
local function pad_text(content, total_length)
local padding = total_length - #content
if padding > 0 then
return content .. string.rep(" ", padding)
else
return content:sub(1, total_length)
end
end
local function get_comment_style()
local filetype = vim.bo.filetype
if filetype == "c" or filetype == "cpp" then
return { block_start = "/*", block_end = "*/", line = " * " }
elseif filetype == "bash" or filetype == "sh" or filetype == "python" then
return { block_start = "#", block_end = "#", line = "#" }
else
return { block_start = "/*", block_end = "*/", line = " * " }
end
end
function M.insert_header()
local filename = vim.fn.expand('%:t') or ""
local author = "nalebrun" -- Replace with your name
local email = "<nalebrun@student.s19.be>" -- Replace with your email
local updated_date = os.date('%Y/%m/%d %H:%M:%S')
local created_date = updated_date
-- Check if header already exists and extract Created and By lines
local existing_created_date, existing_author = nil, nil
for i = 1, vim.fn.line('$') do
local line = vim.fn.getline(i)
if line:find("Created:") then
existing_created_date = line:match("Created: (%d+/%d+/%d+ %d+:%d+:%d+)")
existing_author = line:match("by ([^ ]+)$")
end
if line:find("By:") then
existing_author = line:match("By: ([^ ]+) ")
end
if existing_created_date and existing_author then break end
end
-- Use existing values if found, otherwise use defaults
created_date = existing_created_date or created_date
author = existing_author or author
local comment = get_comment_style()
-- Construct the header lines
local header = {}
table.insert(header, comment.block_start .. " ************************************************************************** " .. comment.block_end)
table.insert(header, comment.block_start .. " " .. comment.block_end)
table.insert(header, comment.block_start .. " ::: :::::::: " .. comment.block_end)
table.insert(header, string.format(comment.block_start .. " %-51s:+: :+: :+: " .. comment.block_end, filename))
table.insert(header, comment.block_start .. " +:+ +:+ +:+ " .. comment.block_end)
table.insert(header, string.format(comment.block_start .. " By: %s %-33s+#+ +:+ +#+ " .. comment.block_end, author, email))
table.insert(header, comment.block_start .. " +#+#+#+#+#+ +#+ " .. comment.block_end)
table.insert(header, string.format(comment.block_start .. " Created: %-20sby %-18s#+# #+# " .. comment.block_end, created_date, author))
table.insert(header, string.format(comment.block_start .. " Updated: %-20sby %-17s### ########.fr " .. comment.block_end, updated_date, author))
table.insert(header, comment.block_start .. " " .. comment.block_end)
table.insert(header, comment.block_start .. " ************************************************************************** " .. comment.block_end)
-- Check for an existing header and replace it; otherwise insert at the top
local first_line_of_header_found = false
for i = 1, vim.fn.line('$') do
local line = vim.fn.getline(i)
if line:find("By:") then
first_line_of_header_found = true
vim.api.nvim_buf_set_lines(0, 0, #header, false, header) -- Replace the header block
break
end
end
if not first_line_of_header_found then
vim.api.nvim_buf_set_lines(0, 0, 0, false, header) -- Insert new header at the top if none exists
end
end
return M

15
nvim/lua/mappings.lua Normal file
View File

@@ -0,0 +1,15 @@
require "nvchad.mappings"
-- add yours here
local map = vim.keymap.set
local mp = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
map("n", ";", ":", { desc = "CMD enter command mode" })
map("i", "jk", "<ESC>")
mp("n", "<leader>pf", "<cmd>FzfLua files winopts.treesitter=true<cr>", opts)
mp("n", "<leader>pg", "<cmd>FzfLua live_grep<cr>", opts) -- Live grep
mp("n", "<leader>pb", "<cmd>FzfLua buffers<cr>", opts) -- Open buffers
-- map({ "n", "i", "v" }, "<C-s>", "<cmd> w <cr>")

21
nvim/lua/options.lua Normal file
View File

@@ -0,0 +1,21 @@
require "nvchad.options"
-- add yours here!
local o = vim.o
local opt = vim.opt
o.cursorlineopt ='both'
o.expandtab = false
o.smartindent = true
o.smarttab = true
o.tabstop = 4
o.shiftwidth = 4
o.softtabstop = 0
o.relativenumber = true
o.ignorecase = true
o.smartcase = true
o.mouse = "a"
opt.fillchars = { eob = " " }
opt.whichwrap:append "<>[]hl"

52
nvim/lua/plugins/init.lua Normal file
View File

@@ -0,0 +1,52 @@
return {
{
"ibhagwan/fzf-lua",
lazy = false,
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("fzf-lua").setup({
fzf_colors = true,
grep = {
cmd = "grep",
grep_opts = "-n -r --color=always --ignore-case --exclude-dir=.git --exclude-dir=.objs",
silent = true,
},
files = {
prompt = "Files ",
},
})
end,
},
{
"stevearc/conform.nvim",
-- event = 'BufWritePre', -- uncomment for format on save
opts = require "configs.conform",
},
-- These are some examples, uncomment them if you want to see them work!
{
"neovim/nvim-lspconfig",
config = function()
require "configs.lspconfig"
end,
},
-- markdown viewer install with yarn or npm
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
build = "cd app && yarn install",
init = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
ft = { "markdown" },
},
-- {
-- "nvim-treesitter/nvim-treesitter",
-- opts = {
-- ensure_installed = {
-- "vim", "lua", "vimdoc",
-- "html", "css"
-- },
-- },
-- },
}