Skip to content

Commit 4f55203

Browse files
committed
updates for tekichan, and any other commit readers
1 parent bbf0c73 commit 4f55203

7 files changed

Lines changed: 412 additions & 122 deletions

File tree

xdg_config/nvim/after/plugin/dap.lua

Lines changed: 58 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1+
-- Explore:
2+
-- - External terminal
3+
-- - make the virt lines thing available if ppl want it
4+
-- - find the nearest codelens above cursor
5+
16
local has_dap, dap = pcall(require, "dap")
27
if not has_dap then
38
return
49
end
510

6-
dap.set_log_level "TRACE"
11+
require("nvim-dap-virtual-text").setup {
12+
enabled = true,
13+
14+
-- DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, DapVirtualTextForceRefresh
15+
enabled_commands = false,
16+
17+
-- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText
18+
highlight_changed_variables = true,
19+
highlight_new_as_changed = true,
20+
21+
-- prefix virtual text with comment string
22+
commented = false,
23+
24+
show_stop_reason = true,
25+
26+
-- experimental features:
27+
virt_text_pos = "eol", -- position of virtual text, see `:h nvim_buf_set_extmark()`
28+
all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine.
29+
}
730

831
-- TODO: How does terminal work?
932
dap.defaults.fallback.external_terminal = {
1033
command = "/home/tjdevries/.local/bin/kitty",
1134
args = { "-e" },
1235
}
1336

37+
dap.adapters.nlua = function(callback, config)
38+
callback { type = "server", host = config.host, port = config.port }
39+
end
40+
1441
dap.configurations.lua = {
1542
{
1643
type = "nlua",
@@ -28,25 +55,6 @@ dap.configurations.lua = {
2855
},
2956
}
3057

31-
dap.adapters.nlua = function(callback, config)
32-
callback { type = "server", host = config.host, port = config.port }
33-
end
34-
35-
vim.g.dap_virtual_text = true
36-
37-
-- dap.adapters.cpp = {
38-
-- type = 'executable',
39-
-- attach = {
40-
-- pidProperty = "pid",
41-
-- pidSelect = "ask"
42-
-- },
43-
-- command = 'lldb-vscode-11',
44-
-- env = {
45-
-- LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY = "YES"
46-
-- },
47-
-- name = "lldb"
48-
-- }
49-
5058
dap.adapters.c = {
5159
name = "lldb",
5260

@@ -175,6 +183,26 @@ dap.configurations.c = {
175183
cwd = vim.fn.expand "~/build/neovim",
176184
gdbpath = vim.fn.exepath "gdb",
177185
},
186+
-- {
187+
-- name = "Launch rust-analyzer lsif",
188+
-- type = "lldb",
189+
-- request = "launch",
190+
-- program = "/home/tjdevries/sourcegraph/rust-analyzer.git/monikers-1/target/debug/rust-analyzer",
191+
-- args = { "lsif", "/home/tjdevries/build/rmpv/" },
192+
-- cwd = "/home/tjdevries/sourcegraph/rust-analyzer.git/monikers-1/",
193+
-- stopOnEntry = false,
194+
-- runInTerminal = false,
195+
-- },
196+
{
197+
name = "Launch ./build/bin/nvim",
198+
type = "lldb",
199+
request = "launch",
200+
program = "/home/tjdevries/build/neovim.git/lua_autocmd/build/bin/nvim",
201+
args = { "--headless" },
202+
cwd = "/home/tjdevries/build/neovim.git/lua_autocmd/",
203+
stopOnEntry = false,
204+
runInTerminal = false,
205+
},
178206
}
179207

180208
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go-using-delve-directly
@@ -317,7 +345,7 @@ require("dap-python").setup("python", {
317345

318346
dap.adapters.lldb = {
319347
type = "executable",
320-
command = "/usr/bin/lldb-vscode-12",
348+
command = "/usr/bin/lldb-vscode-11",
321349
name = "lldb",
322350
}
323351

@@ -391,64 +419,6 @@ dap.adapters.rt_lldb = function(callback, _)
391419
end)
392420
end
393421

394-
-- function M.setup_adapter()
395-
-- local dap = require("dap")
396-
-- dap.adapters.rt_lldb = config.options.dap.adapter
397-
-- end
398-
399-
function StartRustServer(args)
400-
args = args or {}
401-
402-
if not pcall(require, "dap") then
403-
vim.notify "nvim-dap not found."
404-
return
405-
end
406-
407-
if not pcall(require, "plenary.job") then
408-
vim.notify "plenary not found."
409-
return
410-
end
411-
412-
local Job = require "plenary.job"
413-
414-
-- local cargo_args = get_cargo_args_from_runnables_args(args)
415-
416-
vim.notify "Compiling a debug build for debugging. This might take some time..."
417-
418-
Job
419-
:new({
420-
command = "cargo",
421-
args = { "build", "--message-format=json" },
422-
cwd = nil,
423-
on_exit = function(j, code)
424-
if code and code > 0 then
425-
vim.notify "An error occured while compiling. Please fix all compilation issues and try again."
426-
end
427-
vim.schedule(function()
428-
for _, value in pairs(j:result()) do
429-
local json = vim.fn.json_decode(value)
430-
if type(json) == "table" and json.executable ~= vim.NIL and json.executable ~= nil then
431-
local dap_config = {
432-
name = "Rust tools debug",
433-
type = "rt_lldb",
434-
request = "launch",
435-
program = json.executable,
436-
args = args.executableArgs or { "lsif", "/home/tjdevries/build/rmpv/" },
437-
cwd = args.workspaceRoot,
438-
stopOnEntry = false,
439-
runInTerminal = false,
440-
}
441-
dap.run(dap_config)
442-
443-
break
444-
end
445-
end
446-
end)
447-
end,
448-
})
449-
:start()
450-
end
451-
452422
dap.configurations.rust = {
453423
{
454424
name = "Launch",
@@ -485,6 +455,15 @@ dap.configurations.rust = {
485455
},
486456
}
487457

458+
vim.keymap.set("n", "<leader><F5>", function()
459+
if vim.bo.filetype ~= "rust" then
460+
vim.notify "This wasn't rust. I don't know what to do"
461+
return
462+
end
463+
464+
R("tj.dap").select_rust_runnable()
465+
end)
466+
488467
vim.cmd [[nnoremap <silent> <F5> :lua require'dap'.continue()<CR>]]
489468
vim.cmd [[nnoremap <silent> <F1> :lua require'dap'.step_into()<CR>]]
490469
vim.cmd [[nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>]]

xdg_config/nvim/lua/tj/dap.lua

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
local Job = require "plenary.job"
2+
local dap = require "dap"
3+
4+
local M = {}
5+
6+
--[[
7+
|| {
8+
|| args = {
9+
|| cargoArgs = { "test", "--package", "dap-tester", "--bin", "dap-tester" },
10+
|| cargoExtraArgs = {},
11+
|| executableArgs = { "test::can_i_debug_this", "--exact", "--nocapture" },
12+
|| workspaceRoot = "/home/tjdevries/tmp/dap-tester"
13+
|| },
14+
|| kind = "cargo",
15+
|| label = "test test::can_i_debug_this",
16+
|| location = {
17+
|| targetRange = {
18+
|| end = {
19+
|| character = 5,
20+
|| line = 22
21+
|| },
22+
|| start = {
23+
|| character = 4,
24+
|| line = 14
25+
|| }
26+
|| },
27+
|| targetSelectionRange = {
28+
|| end = {
29+
|| character = 23,
30+
|| line = 15
31+
|| },
32+
|| start = {
33+
|| character = 7,
34+
|| line = 15
35+
|| }
36+
|| },
37+
|| targetUri = "file:///home/tjdevries/tmp/dap-tester/src/main.rs"
38+
|| }
39+
|| }
40+
--]]
41+
42+
local get_cargo_args = function(args)
43+
local result = {}
44+
45+
assert(args.cargoArgs, vim.inspect(args))
46+
for idx, a in ipairs(args.cargoArgs) do
47+
table.insert(result, a)
48+
if idx == 1 and a == "test" then
49+
-- Don't run tests, just build
50+
table.insert(result, "--no-run")
51+
end
52+
end
53+
54+
table.insert(result, "--message-format=json")
55+
56+
-- TODO: handle cargoExtraArgs
57+
58+
return result
59+
end
60+
61+
M.select_rust_related = function(bufnr, win)
62+
bufnr = bufnr or vim.api.nvim_get_current_buf()
63+
win = win or vim.api.nvim_get_current_win()
64+
65+
vim.lsp.buf_request(bufnr, "rust-analyzer/relatedTests", vim.lsp.util.make_position_params(win), function(err, result)
66+
local runnables = {}
67+
for _, v in ipairs(result) do
68+
table.insert(runnables, v.runnable)
69+
end
70+
71+
vim.ui.select(runnables, {
72+
prompt = "Related Rust Runnables",
73+
format_item = function(item)
74+
return item.label
75+
end,
76+
}, function(item)
77+
M.debug_rust_runnable(item)
78+
end)
79+
end)
80+
end
81+
82+
M.select_rust_runnable = function(bufnr)
83+
bufnr = bufnr or vim.api.nvim_get_current_buf()
84+
85+
vim.lsp.buf_request(
86+
bufnr,
87+
"experimental/runnables",
88+
{ textDocument = vim.lsp.util.make_text_document_params(bufnr) },
89+
function(_, result)
90+
vim.ui.select(result, {
91+
prompt = "Rust Runnables",
92+
format_item = function(item)
93+
return item.label
94+
end,
95+
}, function(item)
96+
M.debug_rust_runnable(item)
97+
end)
98+
end
99+
)
100+
end
101+
102+
M.debug_rust_runnable = function(item)
103+
item = item or {}
104+
item = vim.deepcopy(item)
105+
106+
vim.notify("Debugging: " .. item.label)
107+
108+
Job
109+
:new({
110+
command = "cargo",
111+
args = get_cargo_args(item.args),
112+
cwd = item.args.workspaceRoot,
113+
on_exit = function(j, code)
114+
if code and code > 0 then
115+
vim.notify "An error occured while compiling. Please fix all compilation issues and try again."
116+
end
117+
118+
vim.schedule(function()
119+
for _, value in pairs(j:result()) do
120+
local json = vim.fn.json_decode(value)
121+
if type(json) == "table" and json.executable ~= vim.NIL and json.executable ~= nil then
122+
local dap_config = {
123+
name = "Rust tools debug",
124+
type = "rt_lldb",
125+
request = "launch",
126+
program = json.executable,
127+
args = item.args.executableArgs,
128+
cwd = item.workspaceRoot,
129+
stopOnEntry = false,
130+
runInTerminal = false,
131+
}
132+
133+
dap.run(dap_config)
134+
break
135+
end
136+
end
137+
end)
138+
end,
139+
})
140+
:start()
141+
end
142+
143+
return M

xdg_config/nvim/lua/tj/lsp/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ local custom_attach = function(client)
108108
]]
109109
end
110110

111-
if client.resolved_capabilities.code_lens and false then
111+
if client.resolved_capabilities.code_lens then
112112
vim.cmd [[
113113
augroup lsp_document_codelens
114114
au! * <buffer>

xdg_config/nvim/lua/tj/telescope/custom/multi_rg.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ local flatten = vim.tbl_flatten
1111
return function(opts)
1212
opts = opts or {}
1313
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
14-
opts.shortcuts = opts.shortcuts or {
15-
["l"] = "*.lua",
16-
["v"] = "*.vim",
17-
["n"] = "*.{vim,lua}",
18-
}
14+
opts.shortcuts = opts.shortcuts
15+
or {
16+
["l"] = "*.lua",
17+
["v"] = "*.vim",
18+
["n"] = "*.{vim,lua}",
19+
["c"] = "*.c",
20+
}
1921
opts.pattern = opts.pattern or "%s"
2022

2123
local custom_grep = finders.new_async_job {

0 commit comments

Comments
 (0)