Skip to content

Commit

Permalink
Merge pull request #20 from TonyWu20/ayamir-main
Browse files Browse the repository at this point in the history
ayamir main
  • Loading branch information
TonyWu20 authored Jun 19, 2023
2 parents 4b2fe46 + bfe73c8 commit 5c58276
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 537 deletions.
454 changes: 93 additions & 361 deletions lazy-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ settings["format_notify"] = true
-- Set it to false if diagnostics virtual text is annoying.
-- If disabled, you may browse lsp diagnostics using trouble.nvim (press `gt` to toggle it).
---@type boolean
settings["diagnostics_virtual_text"] = false
settings["diagnostics_virtual_text"] = true

-- Set it to one of the values below if you want to change the visible severity level of lsp diagnostics.
-- Priority: `Error` > `Warning` > `Information` > `Hint`.
Expand All @@ -31,7 +31,6 @@ settings["format_disabled_dirs"] = {
home .. "/format_disabled_dir_under_home",
}

-- NOTE: The startup time will be slowed down when it's true.
-- Set it to false if you don't use nvim to open big files.
---@type boolean
settings["load_big_files_faster"] = true
Expand Down Expand Up @@ -105,4 +104,14 @@ settings["null_ls_deps"] = {
"vint",
}

-- Set the Debug Adapter Protocol (DAP) clients that will be installed and configured during bootstrap here.
-- Check the below link for all supported DAPs:
-- https://github.com/jay-babu/mason-nvim-dap.nvim/blob/main/lua/mason-nvim-dap/mappings/source.lua
---@type string[]
settings["dap_deps"] = {
"codelldb", -- C-Family
"delve", -- Go
"python", -- Python (debugpy)
}

return settings
4 changes: 2 additions & 2 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ return function()
},
performance = {
async_budget = 1,
max_view_entries = 150,
max_view_entries = 120,
},
-- You can set mappings if you want
mapping = cmp.mapping.preset.insert({
Expand Down Expand Up @@ -142,7 +142,7 @@ return function()
},
-- You should specify your *installed* sources.
sources = {
{ name = "nvim_lsp" },
{ name = "nvim_lsp", max_item_count = 350 },
{ name = "nvim_lua" },
{ name = "luasnip" },
{ name = "path" },
Expand Down
16 changes: 8 additions & 8 deletions lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
return function()
local diagnostics_virtual_text = require("core.settings").diagnostics_virtual_text
local diagnostics_level = require("core.settings").diagnostics_level
local is_windows = require("core.global").is_windows

local nvim_lsp = require("lspconfig")
local mason = require("mason")
local mason_registry = require("mason-registry")
local mason_lspconfig = require("mason-lspconfig")
require("lspconfig.ui.windows").default_options.border = "single"
require("lspconfig.ui.windows").default_options.border = "rounded"

local icons = {
ui = require("modules.utils.icons").get("ui", true),
Expand Down Expand Up @@ -34,8 +35,6 @@ return function()
},
})

local is_win = require("core.global").is_windows

-- Additional plugins for pylsp
mason_registry:on(
"package:install:success",
Expand All @@ -45,9 +44,10 @@ return function()
end

local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv"
local python = is_win and venv .. "/Scripts/python.exe" or venv .. "/bin/python"
local black = is_win and venv .. "/Scripts/black.exe" or venv .. "/bin/black"
local ruff = is_win and venv .. "/Scripts/ruff.exe" or venv .. "/bin/ruff"
local python = is_windows and venv .. "/Scripts/python.exe" or venv .. "/bin/python"
local black = is_windows and venv .. "/Scripts/black.exe" or venv .. "/bin/black"
local ruff = is_windows and venv .. "/Scripts/ruff.exe" or venv .. "/bin/ruff"

require("plenary.job")
:new({
command = python,
Expand Down Expand Up @@ -129,7 +129,7 @@ return function()

---A handler to setup all servers defined under `completion/servers/*.lua`
---@param lsp_name string
local function mason_handler(lsp_name)
local function mason_lsp_handler(lsp_name)
local ok, custom_handler = pcall(require, "completion.servers." .. lsp_name)
if not ok then
-- Default to use factory config for server(s) that doesn't include a spec
Expand All @@ -155,7 +155,7 @@ return function()
end
end

mason_lspconfig.setup_handlers({ mason_handler })
mason_lspconfig.setup_handlers({ mason_lsp_handler })

-- Setup lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here.
if vim.fn.executable("dart") == 1 then
Expand Down
3 changes: 1 addition & 2 deletions lua/modules/configs/completion/servers/clangd.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local global = require("core.global")
local function switch_source_header_splitcmd(bufnr, splitcmd)
bufnr = require("lspconfig").util.validate_bufnr(bufnr)
local clangd_client = require("lspconfig").util.get_active_client_by_name(bufnr, "clangd")
Expand Down Expand Up @@ -54,7 +53,7 @@ return function(options)
"--header-insertion-decorators",
"--header-insertion=iwyu",
"--limit-references=3000",
"--limit-results=270",
"--limit-results=350",
},
commands = {
ClangdSwitchSourceHeader = {
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/editor/bigfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return function()
end,
}

require("bigfile").config({
require("bigfile").setup({
filesize = 1, -- size of the file in MiB
pattern = { "*" }, -- autocmd pattern
features = { -- features to disable
Expand Down
29 changes: 29 additions & 0 deletions lua/modules/configs/tool/dap/clients/codelldb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- https://github.com/mfussenegger/nvim-dap/wiki/C-C---Rust-(via--codelldb)
return function()
local dap = require("dap")
local utils = require("modules.utils.dap")
local is_windows = require("core.global").is_windows

dap.adapters.codelldb = {
type = "server",
port = "${port}",
executable = {
command = vim.fn.exepath("codelldb"), -- Find codelldb on $PATH
args = { "--port", "${port}" },
detached = is_windows and false or true,
},
}
dap.configurations.c = {
{
name = "Launch the debugger",
type = "codelldb",
request = "launch",
program = utils.input_exec_path(),
args = utils.input_args(),
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
dap.configurations.cpp = dap.configurations.c
dap.configurations.rust = dap.configurations.c
end
66 changes: 66 additions & 0 deletions lua/modules/configs/tool/dap/clients/delve.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go-using-delve-directly
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
return function()
local dap = require("dap")
local utils = require("modules.utils.dap")

dap.adapters.go = function(callback)
local stdout = vim.loop.new_pipe(false)
local handle
local pid_or_err
local port = 28695
local opts = {
stdio = { nil, stdout },
args = { "dap", "-l", "127.0.0.1:" .. port },
detached = true,
}
handle, pid_or_err = vim.loop.spawn(vim.fn.exepath("dlv"), opts, function(code)
stdout:close()
handle:close()
if code ~= 0 then
vim.notify(
string.format('"dlv" exited with code: %d, please check your configs for correctness.', code),
vim.log.levels.WARN,
{ title = "[go] DAP Warning!" }
)
end
end)
assert(handle, "Error running dlv: " .. tostring(pid_or_err))
stdout:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require("dap.repl").append(chunk)
end)
end
end)
-- Wait for delve to start
vim.defer_fn(function()
callback({ type = "server", host = "127.0.0.1", port = port })
end, 100)
end
dap.configurations.go = {
{ type = "go", name = "Debug", request = "launch", program = "${file}" },
{
type = "go",
name = "Debug with args",
request = "launch",
program = "${file}",
args = utils.input_args(),
},
{
type = "go",
name = "Debug test", -- configuration for debugging test files
request = "launch",
mode = "test",
program = "${file}",
}, -- works with go.mod packages and sub packages
{
type = "go",
name = "Debug test (go.mod)",
request = "launch",
mode = "test",
program = "./${relativeFileDirname}",
},
}
end
37 changes: 37 additions & 0 deletions lua/modules/configs/tool/dap/clients/lldb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#ccrust-via-lldb-vscode
return function()
local dap = require("dap")
local utils = require("modules.utils.dap")

dap.adapters.lldb = {
type = "executable",
command = "lldb-vscode",
name = "lldb",
}
dap.configurations.c = {
{
name = "Launch",
type = "lldb",
request = "launch",
program = utils.input_exec_path(),
cwd = "${workspaceFolder}",
args = utils.input_args(),
env = utils.get_env(),

-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
--
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
--
-- Otherwise you might get the following error:
--
-- Error on launch: Failed to attach to the target process
--
-- But you should be aware of the implications:
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
runInTerminal = false,
},
}

dap.configurations.cpp = dap.configurations.c
dap.configurations.rust = dap.configurations.c
end
64 changes: 64 additions & 0 deletions lua/modules/configs/tool/dap/clients/python.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#python
return function()
local dap = require("dap")
local debugpy = vim.fn.exepath("debugpy-adapter")

local function is_empty(s)
return s == nil or s == ""
end

dap.adapters.python = function(callback, config)
if config.request == "attach" then
---@diagnostic disable-next-line: undefined-field
local port = (config.connect or config).port
---@diagnostic disable-next-line: undefined-field
local host = (config.connect or config).host or "127.0.0.1"
callback({
type = "server",
port = assert(port, "`connect.port` is required for a python `attach` configuration"),
host = host,
options = { source_filetype = "python" },
})
else
callback({
type = "executable",
command = debugpy,
options = { source_filetype = "python" },
})
end
end
dap.configurations.python = {
{
-- The first three options are required by nvim-dap
type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python`
request = "launch",
name = "Launch file",
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
program = "${file}", -- This configuration will launch the current file if used.
pythonPath = function()
if not is_empty(vim.env.CONDA_PREFIX) then
return vim.env.CONDA_PREFIX .. "/bin/python"
else
return "python3"
end
end,
},
}

-- NOTE: This setting is for people using venv
-- pythonPath = function()
-- -- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
-- -- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
-- -- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
-- local cwd, venv = vim.fn.getcwd(), os.getenv("VIRTUAL_ENV")
-- if venv and vim.fn.executable(venv .. "/bin/python") == 1 then
-- return venv .. "/bin/python"
-- elseif vim.fn.executable(cwd .. "/venv/bin/python") == 1 then
-- return cwd .. "/venv/bin/python"
-- elseif vim.fn.executable(cwd .. "/.venv/bin/python") == 1 then
-- return cwd .. "/.venv/bin/python"
-- else
-- return "python3"
-- end
-- end,
end
46 changes: 0 additions & 46 deletions lua/modules/configs/tool/dap/dap-debugpy.lua

This file was deleted.

Loading

0 comments on commit 5c58276

Please sign in to comment.