1
0
Fork 1
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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
local T = require('toolchain')
local M = {}
M.setup = function()
function M.setup()
T.add_highlighter_autoinstalls('html', 'css', 'scss', 'javascript', 'typescript')
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)
if entry == ".." or entry == "." then
return true
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
FINDER.project_dir = vim.fn.expand('%:p:h')
if FINDER.project_dir == '' then
FINDER.project_dir = vim.fn.getcwd()
end
local function read_dir(dir)
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
return FINDER