Skip to content

Commit 62b1de0

Browse files
committed
updates for chat :)
1 parent cf973aa commit 62b1de0

22 files changed

Lines changed: 766 additions & 141 deletions

xdg_config/nvim/after/plugin/dap.lua

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ dap.configurations.c = {
178178
"executable": "<path to the elf/exe file relativ to workspace root in order to load the symbols>",
179179
"target": "X.X.X.X:9999",
180180
"remote": true,
181-
"cwd": "${workspaceRoot}",
181+
"cwd": "${workspaceRoot}",
182182
"gdbpath": "path/to/your/gdb",
183183
"autorun": [
184184
"any gdb commands to initiate your environment, if it is needed"
@@ -525,25 +525,45 @@ augroup END
525525
local dap_ui = require "dapui"
526526

527527
local _ = dap_ui.setup {
528-
-- You can change the order of elements in the sidebar
529-
sidebar = {
530-
elements = {
531-
-- Provide as ID strings or tables with "id" and "size" keys
532-
{
533-
id = "scopes",
534-
size = 0.75, -- Can be float or integer > 1
528+
layouts = {
529+
{
530+
elements = {
531+
"scopes",
532+
"breakpoints",
533+
"stacks",
534+
"watches",
535535
},
536-
{ id = "watches", size = 00.25 },
536+
size = 40,
537+
position = "left",
538+
},
539+
{
540+
elements = {
541+
"repl",
542+
"console",
543+
},
544+
size = 10,
545+
position = "bottom",
537546
},
538-
size = 50,
539-
position = "left", -- Can be "left" or "right"
540-
},
541-
542-
tray = {
543-
elements = {},
544-
size = 15,
545-
position = "bottom", -- Can be "bottom" or "top"
546547
},
548+
-- -- You can change the order of elements in the sidebar
549+
-- sidebar = {
550+
-- elements = {
551+
-- -- Provide as ID strings or tables with "id" and "size" keys
552+
-- {
553+
-- id = "scopes",
554+
-- size = 0.75, -- Can be float or integer > 1
555+
-- },
556+
-- { id = "watches", size = 00.25 },
557+
-- },
558+
-- size = 50,
559+
-- position = "left", -- Can be "left" or "right"
560+
-- },
561+
--
562+
-- tray = {
563+
-- elements = {},
564+
-- size = 15,
565+
-- position = "bottom", -- Can be "bottom" or "top"
566+
-- },
547567
}
548568

549569
local original = {}

xdg_config/nvim/after/plugin/diagnostic.lua

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@ vim.diagnostic.config {
1515
-- border = "rounded",
1616
-- source = "always",
1717
format = function(d)
18+
if not d.code and not d.user_data then
19+
return d.message
20+
end
21+
1822
local t = vim.deepcopy(d)
19-
local code = d.code or d.user_data.lsp.code
23+
local code = d.code
24+
if not code then
25+
if not d.user_data.lsp then
26+
return d.message
27+
end
28+
29+
code = d.user_data.lsp.code
30+
end
2031
if code then
2132
t.message = string.format("%s [%s]", t.message, code):gsub("1. ", "")
2233
end
@@ -29,22 +40,43 @@ vim.diagnostic.config {
2940
update_in_insert = false,
3041
}
3142

32-
local goto_opts = {
33-
wrap = true,
34-
float = true,
43+
-- Go to the next diagnostic, but prefer going to errors first
44+
-- In general, I pretty much never want to go to the next hint
45+
local severity_levels = {
46+
vim.diagnostic.severity.ERROR,
47+
vim.diagnostic.severity.WARN,
48+
vim.diagnostic.severity.INFO,
49+
vim.diagnostic.severity.HINT,
3550
}
3651

52+
local get_highest_error_severity = function()
53+
for _, level in ipairs(severity_levels) do
54+
local diags = vim.diagnostic.get(0, { severity = { min = level } })
55+
if #diags > 0 then
56+
return level, diags
57+
end
58+
end
59+
end
60+
3761
nmap {
3862
"<space>dn",
3963
function()
40-
vim.diagnostic.goto_next(goto_opts)
64+
vim.diagnostic.goto_next {
65+
severity = get_highest_error_severity(),
66+
wrap = true,
67+
float = true,
68+
}
4169
end,
4270
}
4371

4472
nmap {
4573
"<space>dp",
4674
function()
47-
vim.diagnostic.goto_prev(goto_opts)
75+
vim.diagnostic.goto_prev {
76+
severity = get_highest_error_severity(),
77+
wrap = true,
78+
float = true,
79+
}
4880
end,
4981
}
5082

xdg_config/nvim/after/plugin/luasnip.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ls.config.set_config {
2424
ext_opts = {
2525
[types.choiceNode] = {
2626
active = {
27-
virt_text = { { " <- Current Choice", "NonTest" } },
27+
virt_text = { { " « ", "NonTest" } },
2828
},
2929
},
3030
},

xdg_config/nvim/after/plugin/sourcegraph.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ local dbs = vim.g.dbs
66
dbs["sg-local"] = "postgres://sourcegraph:sourcegraph@localhost:5432/sourcegraph"
77

88
vim.g.dbs = dbs
9+
10+
require("sg").setup {
11+
on_attach = require("tj.lsp").on_attach,
12+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
local query = vim.treesitter.parse_query(
2+
"rust",
3+
[[
4+
(
5+
(macro_invocation
6+
(scoped_identifier
7+
path: (identifier) @_path
8+
name: (identifier) @_identifier)
9+
10+
(token_tree (raw_string_literal) @raw))
11+
12+
(#eq? @_path "sqlx")
13+
(#eq? @_identifier "query")
14+
(#offset! @raw 1 0 -1 0)
15+
)
16+
]]
17+
)
18+
19+
local Job = require "plenary.job"
20+
21+
local format_dat_sql = function(bufnr)
22+
if not bufnr then
23+
bufnr = vim.api.nvim_get_current_buf()
24+
end
25+
26+
if vim.bo[bufnr].filetype ~= "rust" then
27+
vim.notify "can only be used in rust"
28+
return
29+
end
30+
31+
local parser = vim.treesitter.get_parser(bufnr, "rust", {})
32+
local tree = parser:parse()[1]
33+
34+
-- Finds sql-format-via-python somewhere in your nvim config path
35+
local bin = vim.api.nvim_get_runtime_file("bin/sql-format-via-python.py", false)[1]
36+
37+
local changes = {}
38+
for id, node, metadata in query:iter_captures(tree:root(), bufnr, 0, -1) do
39+
if id == 3 then
40+
local text = vim.treesitter.get_node_text(node, bufnr)
41+
local split = vim.split(text, "\n")
42+
local result = table.concat(vim.list_slice(split, 2, #split - 1), "\n")
43+
44+
local j = Job:new {
45+
command = "python",
46+
args = { bin },
47+
writer = { result },
48+
}
49+
50+
local range = { node:range() }
51+
52+
local formatted = j:sync()
53+
local rep = string.rep(" ", range[2])
54+
for idx, line in ipairs(formatted) do
55+
formatted[idx] = rep .. line
56+
end
57+
58+
table.insert(changes, 1, { start = range[1] + 1, final = range[3], formatted = formatted })
59+
end
60+
end
61+
62+
for _, change in ipairs(changes) do
63+
vim.api.nvim_buf_set_lines(bufnr, change.start, change.final, false, change.formatted)
64+
end
65+
end
66+
67+
vim.api.nvim_create_user_command("SqlMagic", function()
68+
format_dat_sql()
69+
end, {})
70+
71+
local group = vim.api.nvim_create_augroup("rust-sql-magic", { clear = true })
72+
vim.api.nvim_create_autocmd("BufWritePre", {
73+
group = group,
74+
pattern = "*.rs",
75+
callback = function()
76+
format_dat_sql()
77+
end,
78+
})

xdg_config/nvim/after/plugin/statusline.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ require("el").reset_windows()
1010

1111
vim.opt.laststatus = 3
1212

13+
if false then
14+
-- Disappearing statusline for commands
15+
vim.opt.cmdheight = 0
16+
vim.api.nvim_create_autocmd("ModeChanged", {
17+
group = vim.api.nvim_create_augroup("StatusDisappear", { clear = true }),
18+
callback = function()
19+
if vim.v.event.new_mode == "c" then
20+
vim.opt.laststatus = 0
21+
elseif vim.v.event.old_mode == "c" then
22+
vim.opt.laststatus = 3
23+
end
24+
25+
pcall(vim.cmd, [[silent! redraw]])
26+
end,
27+
})
28+
end
29+
1330
local builtin = require "el.builtin"
1431
local extensions = require "el.extensions"
1532
local sections = require "el.sections"

xdg_config/nvim/after/plugin/treesitter.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ list.rsx = {
2929

3030
-- :h nvim-treesitter-query-extensions
3131
local custom_captures = {
32-
["function.call"] = "LuaFunctionCall",
32+
["function.call.lua"] = "LuaFunctionCall",
3333
["function.bracket"] = "Type",
3434
["namespace.type"] = "TSNamespaceType",
3535
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import sqlparse
3+
4+
5+
# TODO: Decide what to do about $/?
6+
# contents = contents.replace(f"${identifier}", f"__id_{identifier}")
7+
8+
contents = sys.stdin.read()
9+
for identifier in range(10):
10+
contents = contents.replace(f"?{identifier}", f"__id_{identifier}")
11+
12+
# for nightshadedude
13+
comma_first = True
14+
15+
result = sqlparse.format(contents
16+
, indent_columns=True
17+
, keyword_case='upper'
18+
, identifier_case='lower'
19+
, reindent=True
20+
, output_format='sql'
21+
, indent_after_first=True
22+
, wrap_after=80
23+
, comma_first=comma_first
24+
)
25+
26+
for identifier in range(10):
27+
result = result.replace(f"__id_{identifier}", f"?{identifier}")
28+
29+
print(result.strip())

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ local filetype_attach = setmetatable({
7272
end,
7373

7474
typescript = function()
75-
autocmd_format(false, function(clients)
76-
return vim.tbl_filter(function(client)
77-
return client.name ~= "tsserver"
78-
end, clients)
75+
autocmd_format(false, function(client)
76+
return client.name ~= "tsserver"
7977
end)
8078
end,
8179
}, {
@@ -144,7 +142,7 @@ local custom_attach = function(client)
144142
]]
145143
end
146144

147-
if client.server_capabilities.codeLensProvider then
145+
if false and client.server_capabilities.codeLensProvider then
148146
if filetype ~= "elm" then
149147
vim.cmd [[
150148
augroup lsp_document_codelens
@@ -173,13 +171,17 @@ updated_capabilities.textDocument.completion.completionItem.insertReplaceSupport
173171
-- vim.lsp.buf_request(0, "textDocument/codeLens", { textDocument = vim.lsp.util.make_text_document_params() })
174172

175173
local servers = {
174+
175+
-- Also uses `shellcheck` and `explainshell`
176+
bashls = true,
177+
178+
eslint = true,
176179
gdscript = true,
177-
graphql = true,
180+
-- graphql = true,
178181
html = true,
179182
pyright = true,
180183
vimls = true,
181184
yamlls = true,
182-
eslint = true,
183185

184186
cmake = (1 == vim.fn.executable "cmake-language-server"),
185187
dartls = pcall(require, "flutter-tools"),
@@ -200,18 +202,18 @@ local servers = {
200202
},
201203

202204
gopls = {
203-
root_dir = function(fname)
204-
local Path = require "plenary.path"
205-
206-
local absolute_cwd = Path:new(vim.loop.cwd()):absolute()
207-
local absolute_fname = Path:new(fname):absolute()
208-
209-
if string.find(absolute_cwd, "/cmd/", 1, true) and string.find(absolute_fname, absolute_cwd, 1, true) then
210-
return absolute_cwd
211-
end
212-
213-
return lspconfig_util.root_pattern("go.mod", ".git")(fname)
214-
end,
205+
-- root_dir = function(fname)
206+
-- local Path = require "plenary.path"
207+
--
208+
-- local absolute_cwd = Path:new(vim.loop.cwd()):absolute()
209+
-- local absolute_fname = Path:new(fname):absolute()
210+
--
211+
-- if string.find(absolute_cwd, "/cmd/", 1, true) and string.find(absolute_fname, absolute_cwd, 1, true) then
212+
-- return absolute_cwd
213+
-- end
214+
--
215+
-- return lspconfig_util.root_pattern("go.mod", ".git")(fname)
216+
-- end,
215217

216218
settings = {
217219
gopls = {
@@ -230,11 +232,11 @@ local servers = {
230232

231233
rust_analyzer = {
232234
cmd = { "rustup", "run", "nightly", "rust-analyzer" },
235+
-- cmd = { "rust-analyzer" },
233236
},
234237

235238
elmls = true,
236239
cssls = true,
237-
238240
tsserver = {
239241
init_options = ts_util.init_options,
240242
cmd = { "typescript-language-server", "--stdio" },
@@ -369,13 +371,6 @@ for server, config in pairs(servers) do
369371
setup_server(server, config)
370372
end
371373

372-
if pcall(require, "sg.lsp") then
373-
require("sg.lsp").setup {
374-
on_init = custom_init,
375-
on_attach = custom_attach,
376-
}
377-
end
378-
379374
--[ An example of using functions...
380375
-- 0. nil -> do default (could be enabled or disabled)
381376
-- 1. false -> disable it

0 commit comments

Comments
 (0)