From d594d6f447b0a3fba0d70317fb44e0eccda369fe Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 8 Sep 2024 01:50:39 +0200 Subject: [PATCH] Refactor --- .gitignore | 3 +- .idea/.gitignore | 8 --- .idea/misc.xml | 6 -- .idea/modules.xml | 8 --- .idea/nvim.iml | 9 --- .idea/vcs.xml | 6 -- Readme.md | 56 +++++++----------- lua/core/keymap.lua | 76 +++++++++++++++++++++++++ lua/editor/search.lua | 33 ++++------- lua/editor/snippets.lua | 24 +++++--- lua/editor/terminal.lua | 12 ++-- lua/toolchain/config.lua | 4 +- lua/toolchain/database.lua | 2 +- lua/toolchain/frontend.lua | 2 +- lua/toolchain/generic.lua | 2 +- lua/toolchain/git.lua | 21 +++---- lua/toolchain/go.lua | 23 +++++--- lua/toolchain/init.lua | 24 ++++---- lua/toolchain/lua.lua | 2 +- lua/toolchain/php.lua | 2 +- lua/toolchain/scripts.lua | 2 +- lua/toolchain/text.lua | 9 +-- lua/toolchain/web.lua | 2 +- lua/util/config.lua | 30 ++++++++++ lua/util/const.lua | 9 +++ lua/util/finder.lua | 114 ++----------------------------------- 26 files changed, 229 insertions(+), 260 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/nvim.iml delete mode 100644 .idea/vcs.xml create mode 100644 lua/util/config.lua create mode 100644 lua/util/const.lua diff --git a/.gitignore b/.gitignore index 2fcefc7..225fd51 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -lazy-lock.json \ No newline at end of file +lazy-lock.json +.idea/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -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 diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1b2d693..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 1412a4d..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/nvim.iml b/.idea/nvim.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/nvim.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Readme.md b/Readme.md index ca79bd6..df556ed 100644 --- a/Readme.md +++ b/Readme.md @@ -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) \ No newline at end of file diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua index 652ca1e..5fa70cb 100644 --- a/lua/core/keymap.lua +++ b/lua/core/keymap.lua @@ -1,5 +1,81 @@ +local K = {} + +--[[ Leader ]] vim.g.mapleader = ' ' --[[ Indentation ]] vim.keymap.set('n', '', '>>') vim.keymap.set('n', '', '<<') + +--[[ Markdown ]] +K.MARKDOWN_PREVIEW = { + mode = 'n', + shortcut = 'mp', + description = 'Show Markdown Preview' +} + +--[[ Git ]] +K.GIT = { + OPEN = { + mode = 'n', + shortcut = 'go', + description = 'Open Git' + }, + HUNK = { + mode = 'n', + shortcut = 'gh', + description = 'Toggle Inline Git Diff' + }, + BLAME = { + mode = 'n', + shortcut = 'gb', + description = 'Toggle Inline Git Blame' + } +} + +--[[ Terminal ]] +K.TOGGLE_TERMINAL = { + mode = { 'n', 't' }, + shortcut = '', + description = 'Toggle Terminal' +} + +--[[ Snippets ]] +K.SNIPPETS = { + ACCEPT_OR_JUMP = { + mode = { 'i', 's' }, + shortcut = '', + }, + JUMP_BACKWARDS = { + mode = { 'i', 's' }, + shortcut = '', + } +} + +--[[ Search ]] +K.SEARCH = { + FIND_FILE = { + mode = 'n', + shortcut = 'ff', + description = 'Find File' + }, + FUZZY_FIND = { + mode = 'n', + shortcut = 'fz', + description = 'Fuzzy File' + }, + GLOBAL_FIND_FILE = { + mode = 'n', + shortcut = 'gff', + description = 'Global Find File' + }, + GLOBAL_FUZZY_FIND = { + mode = 'n', + shortcut = 'gfz', + description = 'Global Fuzzy File' + }, +} + +--TODO: Port the rest of the Keybindings to here + +return K diff --git a/lua/editor/search.lua b/lua/editor/search.lua index 64cb3bb..327ff8c 100644 --- a/lua/editor/search.lua +++ b/lua/editor/search.lua @@ -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', - 'ff', + K.SEARCH.FIND_FILE, telescope.find_files, - false, - 'Find File' + false ) setTelescopeBinding( - 'n', - 'fz', + K.SEARCH.FUZZY_FIND, telescope.live_grep, - false, - 'Fuzzy Find' + false ) setTelescopeBinding( - 'n', - 'gff', + K.SEARCH.GLOBAL_FIND_FILE, telescope.find_files, - true, - 'Global Find File' + true ) setTelescopeBinding( - 'n', - 'gfz', + K.SEARCH.GLOBAL_FUZZY_FIND, telescope.live_grep, - true, - 'Global Fuzzy Find' + true ) end, } diff --git a/lua/editor/snippets.lua b/lua/editor/snippets.lua index 00b6589..fdee73b 100644 --- a/lua/editor/snippets.lua +++ b/lua/editor/snippets.lua @@ -1,3 +1,4 @@ +local K = require('core.keymap') return { { 'L3MON4D3/LuaSnip', @@ -32,17 +33,22 @@ return { }) -- Keybinding -- - vim.keymap.set({ 'i', 's' }, '', function() - if luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - vim.api.nvim_input('') - 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('') --Jump Placeholder of Snippets + end + end, + { silent = true } + ) vim.keymap.set( - { 'i', 's' }, - '', + K.SNIPPETS.JUMP_BACKWARDS.mode, + K.SNIPPETS.JUMP_BACKWARDS.shortcut, function() luasnip.jump(-1) end, { silent = true } ) diff --git a/lua/editor/terminal.lua b/lua/editor/terminal.lua index 398b680..dabc321 100644 --- a/lua/editor/terminal.lua +++ b/lua/editor/terminal.lua @@ -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' }, - '', + K.TOGGLE_TERMINAL.mode, + K.TOGGLE_TERMINAL.shortcut, toggle, - { desc = 'Toggle Terminal' } + { desc = K.TOGGLE_TERMINAL.description } ) end, } diff --git a/lua/toolchain/config.lua b/lua/toolchain/config.lua index adf82c5..38d3605 100644 --- a/lua/toolchain/config.lua +++ b/lua/toolchain/config.lua @@ -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 { diff --git a/lua/toolchain/database.lua b/lua/toolchain/database.lua index 2491d87..2e52c3d 100644 --- a/lua/toolchain/database.lua +++ b/lua/toolchain/database.lua @@ -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) diff --git a/lua/toolchain/frontend.lua b/lua/toolchain/frontend.lua index 42165d1..f2ce72f 100644 --- a/lua/toolchain/frontend.lua +++ b/lua/toolchain/frontend.lua @@ -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) diff --git a/lua/toolchain/generic.lua b/lua/toolchain/generic.lua index fd83a45..2aaac7f 100644 --- a/lua/toolchain/generic.lua +++ b/lua/toolchain/generic.lua @@ -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 diff --git a/lua/toolchain/git.lua b/lua/toolchain/git.lua index 9a800a6..cd0006e 100644 --- a/lua/toolchain/git.lua +++ b/lua/toolchain/git.lua @@ -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', - 'gh', + K.GIT.HUNK.mode, + K.GIT.HUNK.shortcut, ':Gitsigns preview_hunk_inline', - { desc = 'Toggle Inline Git Diff' } + { desc = K.GIT.HUNK.description } ) vim.keymap.set( - 'n', - 'gb', + K.GIT.BLAME.mode, + K.GIT.BLAME.shortcut, ':Gitsigns toggle_current_line_blame', - { desc = 'Toggle Inline Git Blame' } + { desc = K.GIT.BLAME.description } ) vim.keymap.set( - 'n', - 'go', + K.GIT.OPEN.mode, + K.GIT.OPEN.shortcut, ':Git ', - { desc = 'Open Git' } + { desc = K.GIT.OPEN.description } ) end, }, diff --git a/lua/toolchain/go.lua b/lua/toolchain/go.lua index 363a0cc..919bf2e 100644 --- a/lua/toolchain/go.lua +++ b/lua/toolchain/go.lua @@ -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 diff --git a/lua/toolchain/init.lua b/lua/toolchain/init.lua index 7625c73..2427e8e 100644 --- a/lua/toolchain/init.lua +++ b/lua/toolchain/init.lua @@ -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 \ No newline at end of file diff --git a/lua/toolchain/lua.lua b/lua/toolchain/lua.lua index 728a426..49a3c01 100644 --- a/lua/toolchain/lua.lua +++ b/lua/toolchain/lua.lua @@ -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) diff --git a/lua/toolchain/php.lua b/lua/toolchain/php.lua index e0365d1..eab3cd6 100644 --- a/lua/toolchain/php.lua +++ b/lua/toolchain/php.lua @@ -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) diff --git a/lua/toolchain/scripts.lua b/lua/toolchain/scripts.lua index bf4646a..02d56d6 100644 --- a/lua/toolchain/scripts.lua +++ b/lua/toolchain/scripts.lua @@ -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) diff --git a/lua/toolchain/text.lua b/lua/toolchain/text.lua index 3400356..1f3b3df 100644 --- a/lua/toolchain/text.lua +++ b/lua/toolchain/text.lua @@ -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', - 'mp', + K.MARKDOWN_PREVIEW.mode, + K.MARKDOWN_PREVIEW.shortcut, ':Mdpreview', - { desc = 'Show Markdown Preview' } + { desc = K.MARKDOWN_PREVIEW.description } ) end, }) diff --git a/lua/toolchain/web.lua b/lua/toolchain/web.lua index a836888..a3e71b3 100644 --- a/lua/toolchain/web.lua +++ b/lua/toolchain/web.lua @@ -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) diff --git a/lua/util/config.lua b/lua/util/config.lua new file mode 100644 index 0000000..293d72a --- /dev/null +++ b/lua/util/config.lua @@ -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 \ No newline at end of file diff --git a/lua/util/const.lua b/lua/util/const.lua new file mode 100644 index 0000000..62ae3a6 --- /dev/null +++ b/lua/util/const.lua @@ -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 \ No newline at end of file diff --git a/lua/util/finder.lua b/lua/util/finder.lua index a6f04c6..875221f 100644 --- a/lua/util/finder.lua +++ b/lua/util/finder.lua @@ -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 \ No newline at end of file