This commit is contained in:
Snoweuph 2024-09-08 01:50:39 +02:00
parent f3710a46b7
commit d594d6f447
No known key found for this signature in database
GPG key ID: 4550DEC769DB1E76
26 changed files with 229 additions and 260 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
lazy-lock.json lazy-lock.json
.idea/

8
.idea/.gitignore vendored
View file

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/nvim.iml" filepath="$PROJECT_DIR$/.idea/nvim.iml" />
</modules>
</component>
</project>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -1,36 +1,24 @@
# [Dotfiles](https://git.euph.dev/Snoweuph/Dotfiles)/nvim # [Dotfiles](https://git.euph.dev/Snoweuph/Dotfiles)/nvim
## Setup ## Requirements
- [neovim](https://neovim.io/)
### Fedora - [go](https://go.dev/doc/install)
- [gcc](https://www.gnu.org/software/gcc/)
#### Enable Coprs - [curl](https://github.com/curl/curl/blob/master/docs/INSTALL.md)
```sh - [wget](https://www.gnu.org/software/wget/)
dnf copr enable yorickpeterse/stylua -y - [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
``` - unzip
- [tar](https://www.gnu.org/software/tar/)
#### Add YUM Repos - [gzip](https://www.gnu.org/software/gzip/)
```sh - codespell
echo '[charm] - [ripgrep](https://github.com/BurntSushi/ripgrep#installation)
name=Charm - [php](https://www.php.net/manual/en/install.php)
baseurl=https://repo.charm.sh/yum/ - [composer](https://www.php.net/manual/en/install.php)
enabled=1 - [node](https://nodejs.org/en/download/package-manager)
gpgcheck=1 - [npm](https://nodejs.org/en/download/package-manager)
gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo - [stylua](https://github.com/JohnnyMorganz/StyLua#installation)
``` - [glow](https://github.com/charmbracelet/glow#installation)
- [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
#### Install System Packages - [delve](https://github.com/go-delve/delve/tree/master/Documentation/installation)
```sh - [prettierd](https://github.com/fsouza/prettierd#installation-guide)
dnf install -y neovim lua gcc curl wget git unzip tar gzip ripgrep php composer go nodejs npm delve stylua codespell glow cargo - [eslint_d](https://github.com/mantoni/eslint_d.js#setup)
```
#### Install Cargo packages
```sh
cargo install selene
```
#### Install NPM packages
```sh
npm install -g @fsouza/prettierd
npm install -g eslint_d
```

View file

@ -1,5 +1,81 @@
local K = {}
--[[ Leader ]]
vim.g.mapleader = ' ' vim.g.mapleader = ' '
--[[ Indentation ]] --[[ Indentation ]]
vim.keymap.set('n', '<Tab>', '>>') vim.keymap.set('n', '<Tab>', '>>')
vim.keymap.set('n', '<S-Tab>', '<<') vim.keymap.set('n', '<S-Tab>', '<<')
--[[ Markdown ]]
K.MARKDOWN_PREVIEW = {
mode = 'n',
shortcut = '<Leader>mp',
description = 'Show Markdown Preview'
}
--[[ Git ]]
K.GIT = {
OPEN = {
mode = 'n',
shortcut = '<Leader>go',
description = 'Open Git'
},
HUNK = {
mode = 'n',
shortcut = '<Leader>gh',
description = 'Toggle Inline Git Diff'
},
BLAME = {
mode = 'n',
shortcut = '<Leader>gb',
description = 'Toggle Inline Git Blame'
}
}
--[[ Terminal ]]
K.TOGGLE_TERMINAL = {
mode = { 'n', 't' },
shortcut = '<F6>',
description = 'Toggle Terminal'
}
--[[ Snippets ]]
K.SNIPPETS = {
ACCEPT_OR_JUMP = {
mode = { 'i', 's' },
shortcut = '<Tab>',
},
JUMP_BACKWARDS = {
mode = { 'i', 's' },
shortcut = '<S-Tab>',
}
}
--[[ Search ]]
K.SEARCH = {
FIND_FILE = {
mode = 'n',
shortcut = '<leader>ff',
description = 'Find File'
},
FUZZY_FIND = {
mode = 'n',
shortcut = '<leader>fz',
description = 'Fuzzy File'
},
GLOBAL_FIND_FILE = {
mode = 'n',
shortcut = '<leader>gff',
description = 'Global Find File'
},
GLOBAL_FUZZY_FIND = {
mode = 'n',
shortcut = '<leader>gfz',
description = 'Global Fuzzy File'
},
}
--TODO: Port the rest of the Keybindings to here
return K

View file

@ -1,3 +1,4 @@
local K = require('core.keymap')
return { return {
'nvim-telescope/telescope.nvim', 'nvim-telescope/telescope.nvim',
tag = '0.1.5', tag = '0.1.5',
@ -18,11 +19,9 @@ return {
-- Keybinding -- -- Keybinding --
local function setTelescopeBinding( local function setTelescopeBinding(
mode, mapping,
keymap,
method, method,
search_global, search_global
description
) )
local function binding() local function binding()
local path = search_global and '~' local path = search_global and '~'
@ -31,38 +30,30 @@ return {
).path ).path
method({ search_dirs = { path } }) method({ search_dirs = { path } })
end end
vim.keymap.set(mode, keymap, binding, { desc = description }) vim.keymap.set(mapping.mode, mapping.shortcut, binding, { desc = mapping.description })
end end
local telescope = require('telescope.builtin') local telescope = require('telescope.builtin')
setTelescopeBinding( setTelescopeBinding(
'n', K.SEARCH.FIND_FILE,
'<leader>ff',
telescope.find_files, telescope.find_files,
false, false
'Find File'
) )
setTelescopeBinding( setTelescopeBinding(
'n', K.SEARCH.FUZZY_FIND,
'<leader>fz',
telescope.live_grep, telescope.live_grep,
false, false
'Fuzzy Find'
) )
setTelescopeBinding( setTelescopeBinding(
'n', K.SEARCH.GLOBAL_FIND_FILE,
'<leader>gff',
telescope.find_files, telescope.find_files,
true, true
'Global Find File'
) )
setTelescopeBinding( setTelescopeBinding(
'n', K.SEARCH.GLOBAL_FUZZY_FIND,
'<leader>gfz',
telescope.live_grep, telescope.live_grep,
true, true
'Global Fuzzy Find'
) )
end, end,
} }

View file

@ -1,3 +1,4 @@
local K = require('core.keymap')
return { return {
{ {
'L3MON4D3/LuaSnip', 'L3MON4D3/LuaSnip',
@ -32,17 +33,22 @@ return {
}) })
-- Keybinding -- -- Keybinding --
vim.keymap.set({ 'i', 's' }, '<Tab>', function() vim.keymap.set(
if luasnip.expand_or_jumpable() then K.SNIPPETS.ACCEPT_OR_JUMP.mode,
luasnip.expand_or_jump() K.SNIPPETS.ACCEPT_OR_JUMP.shortcut,
else function()
vim.api.nvim_input('<C-V><Tab>') if luasnip.expand_or_jumpable() then
end luasnip.expand_or_jump()
end, { silent = true }) else
vim.api.nvim_input('<C-V><Tab>') --Jump Placeholder of Snippets
end
end,
{ silent = true }
)
vim.keymap.set( vim.keymap.set(
{ 'i', 's' }, K.SNIPPETS.JUMP_BACKWARDS.mode,
'<S-Tab>', K.SNIPPETS.JUMP_BACKWARDS.shortcut,
function() luasnip.jump(-1) end, function() luasnip.jump(-1) end,
{ silent = true } { silent = true }
) )

View file

@ -1,3 +1,5 @@
local K = require('core.keymap')
return { return {
'rebelot/terminal.nvim', 'rebelot/terminal.nvim',
config = function() config = function()
@ -6,11 +8,11 @@ return {
layout = { layout = {
open_cmd = 'vertical new', open_cmd = 'vertical new',
}, },
cmd = { 'bash' }, cmd = { 'zsh' },
autoclose = true, autoclose = true,
}) })
local project_dir = require('util.finder').get_opened_folder() local project_dir = require('util.finder').project_dir
local term local term
local function toggle() local function toggle()
if term == nil then if term == nil then
@ -21,10 +23,10 @@ return {
end end
vim.keymap.set( vim.keymap.set(
{ 'n', 't' }, K.TOGGLE_TERMINAL.mode,
'<F6>', K.TOGGLE_TERMINAL.shortcut,
toggle, toggle,
{ desc = 'Toggle Terminal' } { desc = K.TOGGLE_TERMINAL.description }
) )
end, end,
} }

View file

@ -1,8 +1,8 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('json', 'xml', 'yaml', 'toml') T.add_highlighter_autoinstalls( 'json', 'xml', 'yaml', 'toml' )
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)
return { return {

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('sql') T.add_highlighter_autoinstalls('sql')
T.add_lsp_autoinstalls('sqlls') T.add_lsp_autoinstalls('sqlls')
T.add_lsps(function(lspconfig, capabilities) T.add_lsps(function(lspconfig, capabilities)

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('svelte', 'vue') T.add_highlighter_autoinstalls('svelte', 'vue')
T.add_lsp_autoinstalls('svelte', 'volar') T.add_lsp_autoinstalls('svelte', 'volar')
T.add_lsps(function(lspconfig, capabilities) T.add_lsps(function(lspconfig, capabilities)

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)
return { return {
-- Actions -- Actions

View file

@ -1,7 +1,8 @@
local T = require('toolchain') local T = require('toolchain')
local K = require('core.keymap')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('gitcommit', 'gitignore', 'gitattributes', 'git_rebase', 'git_config') T.add_highlighter_autoinstalls('gitcommit', 'gitignore', 'gitattributes', 'git_rebase', 'git_config')
T.add_plugins( T.add_plugins(
@ -16,22 +17,22 @@ M.setup = function()
-- Keybinding -- -- Keybinding --
vim.keymap.set( vim.keymap.set(
'n', K.GIT.HUNK.mode,
'<leader>gh', K.GIT.HUNK.shortcut,
':Gitsigns preview_hunk_inline<CR>', ':Gitsigns preview_hunk_inline<CR>',
{ desc = 'Toggle Inline Git Diff' } { desc = K.GIT.HUNK.description }
) )
vim.keymap.set( vim.keymap.set(
'n', K.GIT.BLAME.mode,
'<leader>gb', K.GIT.BLAME.shortcut,
':Gitsigns toggle_current_line_blame<CR>', ':Gitsigns toggle_current_line_blame<CR>',
{ desc = 'Toggle Inline Git Blame' } { desc = K.GIT.BLAME.description }
) )
vim.keymap.set( vim.keymap.set(
'n', K.GIT.OPEN.mode,
'<leader>go', K.GIT.OPEN.shortcut,
':Git <CR>', ':Git <CR>',
{ desc = 'Open Git' } { desc = K.GIT.OPEN.description }
) )
end, end,
}, },

View file

@ -1,7 +1,9 @@
local T = require('toolchain') local T = require('toolchain')
local C = require('util.const')
local CONFIG = require('util.config')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('go', 'gomod', 'gosum', 'gotmpl') T.add_highlighter_autoinstalls('go', 'gomod', 'gosum', 'gotmpl')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)
return { return {
@ -23,14 +25,17 @@ M.setup = function()
T.add_plugins({ T.add_plugins({
'leoluz/nvim-dap-go', 'leoluz/nvim-dap-go',
config = function() config = function()
local dir = require('util.finder').find_project_dir( local args = CONFIG.get(C.CONFIG_DAP_MODULE, C.CONFIG_DAP_KEY_ARGS)
'go.mod', if args ~= nil then
3, args = vim.split(args, "")
{ 'src', 'app', 'pkg' }, end
{ 'test' }, require('dap-go').setup({
true delve = {
) cwd = CONFIG.get(C.CONFIG_DAP_MODULE, C.CONFIG_DAP_KEY_DIR),
require('dap-go').setup({ delve = { cwd = dir } }) build_flags = CONFIG.get(C.CONFIG_DAP_MODULE, C.CONFIG_DAP_KEY_BUILD_FLAGS),
args = args
}
})
end, end,
}) })
end end

View file

@ -7,13 +7,13 @@ local TOOLCHAINS = {}
local plugins = {} local plugins = {}
--- @param ... LazySpec --- @param ... LazySpec
TOOLCHAINS.add_plugins = function(...) function TOOLCHAINS.add_plugins(...)
for _, spec in ipairs({...}) do for _, spec in ipairs({...}) do
table.insert(plugins, spec) table.insert(plugins, spec)
end end
end end
TOOLCHAINS.get_plugins = function() function TOOLCHAINS.get_plugins()
return plugins return plugins
end end
--------- ---------
@ -23,24 +23,24 @@ local lsp_autoinstalls = {}
local lsp_setups = {} local lsp_setups = {}
--- @param ... string --- @param ... string
TOOLCHAINS.add_lsp_autoinstalls = function(...) function TOOLCHAINS.add_lsp_autoinstalls(...)
for _, lsp in ipairs({...}) do for _, lsp in ipairs({...}) do
table.insert(lsp_autoinstalls, lsp) table.insert(lsp_autoinstalls, lsp)
end end
end end
TOOLCHAINS.get_lsp_autoinstalls = function() function TOOLCHAINS.get_lsp_autoinstalls()
return lsp_autoinstalls return lsp_autoinstalls
end end
--- @param setup SetupLSPs --- @param setup SetupLSPs
TOOLCHAINS.add_lsps = function(setup) function TOOLCHAINS.add_lsps(setup)
table.insert(lsp_setups, setup) table.insert(lsp_setups, setup)
end end
--- @param lspconfig any --- @param lspconfig any
--- @param capabilities any --- @param capabilities any
TOOLCHAINS.setup_lsps = function(lspconfig, capabilities) function TOOLCHAINS.setup_lsps(lspconfig, capabilities)
for _, setup in ipairs(lsp_setups) do for _, setup in ipairs(lsp_setups) do
setup(lspconfig, capabilities) setup(lspconfig, capabilities)
end end
@ -53,12 +53,12 @@ end
local null_ls_setups = {} local null_ls_setups = {}
--- @param setup SetupNullLsModule --- @param setup SetupNullLsModule
TOOLCHAINS.add_null_ls_module = function(setup) function TOOLCHAINS.add_null_ls_module(setup)
table.insert(null_ls_setups, setup) table.insert(null_ls_setups, setup)
end end
TOOLCHAINS.get_null_ls_source = function(null_ls) function TOOLCHAINS.get_null_ls_source(null_ls)
local null_ls_sources = {} local null_ls_sources = {}
for _, setup_function in ipairs(null_ls_setups) do for _, setup_function in ipairs(null_ls_setups) do
local conf = setup_function(null_ls) local conf = setup_function(null_ls)
@ -78,20 +78,20 @@ end
local highlighter_autoinstalls = {} local highlighter_autoinstalls = {}
--- @param ... string --- @param ... string
TOOLCHAINS.add_highlighter_autoinstalls = function(...) function TOOLCHAINS.add_highlighter_autoinstalls(...)
for _, highlighter in ipairs({...}) do for _, highlighter in ipairs({...}) do
table.insert(highlighter_autoinstalls, highlighter) table.insert(highlighter_autoinstalls, highlighter)
end end
end end
TOOLCHAINS.get_highlighter_autoinstalls = function() function TOOLCHAINS.get_highlighter_autoinstalls()
return highlighter_autoinstalls return highlighter_autoinstalls
end end
---------------- ----------------
-- Init - -- Init -
---------------- ----------------
TOOLCHAINS.init = function() function TOOLCHAINS.init()
require('toolchain.config').setup() require('toolchain.config').setup()
require('toolchain.database').setup() require('toolchain.database').setup()
require('toolchain.frontend').setup() require('toolchain.frontend').setup()

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('lua','luadoc') T.add_highlighter_autoinstalls('lua','luadoc')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('php', 'phpdoc', 'twig') T.add_highlighter_autoinstalls('php', 'phpdoc', 'twig')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('bash', 'dockerfile', 'make', 'just') T.add_highlighter_autoinstalls('bash', 'dockerfile', 'make', 'just')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)

View file

@ -1,7 +1,8 @@
local T = require('toolchain') local T = require('toolchain')
local K = require('core.keymap')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('markdown') T.add_highlighter_autoinstalls('markdown')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)
@ -51,10 +52,10 @@ M.setup = function()
}) })
vim.keymap.set( vim.keymap.set(
'n', K.MARKDOWN_PREVIEW.mode,
'<Leader>mp', K.MARKDOWN_PREVIEW.shortcut,
':Mdpreview<CR>', ':Mdpreview<CR>',
{ desc = 'Show Markdown Preview' } { desc = K.MARKDOWN_PREVIEW.description }
) )
end, end,
}) })

View file

@ -1,7 +1,7 @@
local T = require('toolchain') local T = require('toolchain')
local M = {} local M = {}
M.setup = function() function M.setup()
T.add_highlighter_autoinstalls('html', 'css', 'scss', 'javascript', 'typescript') T.add_highlighter_autoinstalls('html', 'css', 'scss', 'javascript', 'typescript')
T.add_null_ls_module(function(null_ls) T.add_null_ls_module(function(null_ls)

30
lua/util/config.lua Normal file
View file

@ -0,0 +1,30 @@
local C = require('util.const')
local F = require('util.finder')
local CONFIG = {}
CONFIG.config_dir = F.project_dir .. "/" .. C.CONFIG_DIR
function CONFIG.get(module, name)
local config_file_path = CONFIG.config_dir .. module .. ".json"
if vim.fn.filereadable(config_file_path) == 0 then
return nil
end
local config_file = vim.fn.readfile(config_file_path, "")
local succes, data = pcall(function()
return vim.json.decode(table.concat(config_file, ""))
end)
if not succes or data then
return nil
end
return table.concat(
vim.split(data[name], C.PROJECT_DIR_PLACEHOLDER, { plain = true}),
F.project_dir
)
end
return CONFIG

9
lua/util/const.lua Normal file
View file

@ -0,0 +1,9 @@
local CONST = {}
CONST.PROJECT_DIR_PLACEHOLDER = "$PROJECT_DIR"
CONST.CONFIG_DIR = ".nvim"
CONST.CONFIG_DAP_MODULE = "debugging"
CONST.CONFIG_DAP_KEY_DIR = "dir"
CONST.CONFIG_DAP_KEY_ARGS = "args"
CONST.CONFIG_DAP_KEY_BUILD_FLAGS = "build_flags"
return CONST

View file

@ -1,112 +1,8 @@
local Finder = {} local FINDER = {}
local function is_ignored(entry, ignore_dot_dirs, ignored_dirs) FINDER.project_dir = vim.fn.expand('%:p:h')
if entry == ".." or entry == "." then if FINDER.project_dir == '' then
return true FINDER.project_dir = vim.fn.getcwd()
end
if ignore_dot_dirs and string.match(entry, "^%.") then
return true
end
for _, dir in ipairs(ignored_dirs) do
if entry == dir or string.find(entry, dir, 1, true) then
return true
end
end
return false
end end
local function read_dir(dir) return FINDER
local handle = io.popen('ls -a "' .. dir .. '"')
if not handle then
return nil
end
local result = handle:read("*a")
handle:close()
return result
end
local function is_dir(path)
local f = io.open(path, "r")
if f == nil then
return false
end
local _, _, code = f:read(1)
f:close()
return code == 21
end
local function find_path_recursive(_dir, options)
-- Check max Depth
if options.current_depth > options.max_depth then
return nil
end
local entries = read_dir(_dir)
if entries == nil then
return nil
end
for entry in string.gmatch(entries, "[^\r\n]+") do
-- Check Ignored
if is_ignored(entry, options.ignore_dot_dirs, options.ignored_dirs) then
goto continue
end
local full_path = _dir .. "/" .. entry
-- Check for File
if entry == options.needle_file then
return full_path
end
-- Check is Dir
if not is_dir(full_path) then
goto continue
end
-- Recursive Call
options.current_depth = options.current_depth + 1
local result = find_path_recursive(full_path, options)
if result ~= nil then
return result
end
-- Cleanup
options.current_depth = options.current_depth - 1
:: continue ::
end
return nil
end
function Finder.get_opened_folder()
local cwd = vim.fn.getcwd()
local file_path = vim.fn.expand('%:p:h')
if file_path ~= '' then
return file_path
end
return cwd
end
function Finder.find_project_dir(needle_file, max_depth, priority_dirs, ignored_dirs, ignore_dot_dirs)
local options = {
needle_file = needle_file,
max_depth = max_depth,
priority_dirs = priority_dirs,
ignored_dirs = ignored_dirs,
ignore_dot_dirs = ignore_dot_dirs,
current_depth = 0
}
local dir = Finder.get_opened_folder()
local file = find_path_recursive(dir, options)
if file == nil then
return nil
end
return file:match("(.*/)")
end
return Finder