Skip to content

Commit

Permalink
feat: Telescope will now use ripgrep with special options for sveltek…
Browse files Browse the repository at this point in the history
…it releated projects, else it uses FD
  • Loading branch information
JustBarnt committed Feb 27, 2024
1 parent 5bb48a4 commit 03a175a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
2 changes: 2 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-- Mapleader should be set as quick as possible. There is no reason to not set it at the very top of your initial init.lua
vim.g.mapleader = " "
vim.g.maplocalleader = " "


if not vim.g.vscode then
require "core"
if vim.g.loaded_undotree then
Expand Down
91 changes: 52 additions & 39 deletions lua/core/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,78 @@ local api = vim.api
local M = {}

local vim_options = function(options)
if options ~= nil then
for scope, table in pairs(options) do
for setting, value in pairs(table) do
vim[scope][setting] = value
end
end
end
end

--- Closes empty windows from neovim
--- returns current listed windows and a list of closed windows
---@param windows any[]
---@return {windows:any[], deleted: any[]}
function M.close_empty_wins(windows)
local closed_win
for i = 1, #windows do
if vim.tbl_isempty(windows[i]) then
vim.api.nvim_win_close(windows[1], true)
table.insert(closed_win, windows[1])
if options ~= nil then
for scope, table in pairs(options) do
for setting, value in pairs(table) do
vim[scope][setting] = value
end
end
end
end

vim.print("Windows Closed: " .. tostring(closed_win))
-- Telescope Find non sveltekit dir
--find_command = vim.fn.executable == 1 and { "fd", "--strip-cwd-prefix", "--type", "f" } or nil,
function M.select_find_command()
local rg_command = {
hidden = true,
find_command = {
"rg",
"--files",
"--color=never",
"--no-heading",
"--line-number",
"--column",
"--smart-case",
"--hidden",
"--glob",
"!{.git/*,.svelte-kit/*,target/*,node_modules/*}",
"--path-separator",
"/",
},
}
local fd_command = {
find_command = vim.fn.executable == 1 and { "fd", "--strip-cwd-prefix", "--type", "f" } or nil,
}

return {windows, closed = closed_win}
if vim.fn.glob(vim.fn.getcwd() .. "/.svelte-kit"):match('%.svelte%-kit') then
return rg_command
else
return fd_command
end
end

local map = function(mode, lhs, rhs, opts)
local options = { noremap = true, silent = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.keymap.set(mode, lhs, rhs, options)
local options = { noremap = true, silent = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.keymap.set(mode, lhs, rhs, options)
end

local enabled = function(group, opt)
return group == nil or group[opt] == nil or group[opt] == true
return group == nil or group[opt] == nil or group[opt] == true
end

local autocmd = function(args)
local event = args[1]
local group = args[2]
local callback = args[3]
local event = args[1]
local group = args[2]
local callback = args[3]

vim.api.nvim_create_autocmd(event, {
group = group,
buffer = args[4],
callback = function()
callback()
end,
once = args.once,
})
vim.api.nvim_create_autocmd(event, {
group = group,
buffer = args[4],
callback = function()
callback()
end,
once = args.once,
})
end

local lsp_hover_debug = function()
local clients = vim.lsp.get_active_clients()

for _, client in ipairs(clients) do
vim.cmd([[redir >> lsp_log.txt]])
vim.cmd [[redir >> lsp_log.txt]]
vim.inspect(client)
local result, err = vim.lsp.buf_request_sync(0, "textDocument/hover", vim.lsp.util.make_position_params(), 1000)
vim.inspect(result)
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
return {
{
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
-- event = { "BufReadPre", "BufNewFile" },
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
Expand Down
4 changes: 1 addition & 3 deletions lua/user/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ M.telescope = {
}
},
},
find_files = {
find_command = vim.fn.executable == 1 and { "fd", "--strip-cwd-prefix", "--type", "f" } or nil,
},
find_files = require('core.utils').select_find_command(),--vim.fn.executable == 1 and { "fd", "--strip-cwd-prefix", "--type", "f" } or nil,
},
}

Expand Down

0 comments on commit 03a175a

Please sign in to comment.