From 970179400d1f98834f7cf4454481c795f82c3dd4 Mon Sep 17 00:00:00 2001 From: afranco Date: Wed, 1 May 2024 18:52:16 +0100 Subject: [PATCH] chore(nvim): autopairs bs map and harpoon and tpipeline fix --- .config/nvim/lua/plugins/autopairs.lua | 2 +- .config/nvim/lua/plugins/harpoon.lua | 13 ++++ .config/nvim/lua/plugins/lazy.lua | 14 +++- .config/nvim/lua/plugins/lspconfig.lua | 7 +- .config/nvim/lua/plugins/telescope.lua | 6 +- .config/nvim/queries/go/injections.scm | 103 +++++++++++++++++++++++++ 6 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 .config/nvim/lua/plugins/harpoon.lua create mode 100644 .config/nvim/queries/go/injections.scm diff --git a/.config/nvim/lua/plugins/autopairs.lua b/.config/nvim/lua/plugins/autopairs.lua index ca961a5..c24b33d 100644 --- a/.config/nvim/lua/plugins/autopairs.lua +++ b/.config/nvim/lua/plugins/autopairs.lua @@ -3,7 +3,7 @@ local npairs = require('nvim-autopairs') npairs.setup({ map_cr = true, - map_bs = false, + map_bs = true, check_ts = true, enable_check_bracket_line = true, ignored_next_char = "[%w]" diff --git a/.config/nvim/lua/plugins/harpoon.lua b/.config/nvim/lua/plugins/harpoon.lua new file mode 100644 index 0000000..4c9bd84 --- /dev/null +++ b/.config/nvim/lua/plugins/harpoon.lua @@ -0,0 +1,13 @@ +local harpoon = require("harpoon") + +-- REQUIRED +harpoon:setup() +-- REQUIRED + +vim.keymap.set("n", "a", function() harpoon:list():add() end) +vim.keymap.set("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) + +vim.keymap.set("n", "", function() harpoon:list():select(1) end) +vim.keymap.set("n", "", function() harpoon:list():select(2) end) +vim.keymap.set("n", "", function() harpoon:list():select(3) end) +vim.keymap.set("n", "", function() harpoon:list():select(4) end) diff --git a/.config/nvim/lua/plugins/lazy.lua b/.config/nvim/lua/plugins/lazy.lua index efd8d00..6273cfa 100644 --- a/.config/nvim/lua/plugins/lazy.lua +++ b/.config/nvim/lua/plugins/lazy.lua @@ -29,6 +29,13 @@ lazy.setup({ end, }, + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + ft = { "markdown" }, + build = function() vim.fn["mkdp#util#install"]() end, + }, + { "ThePrimeagen/harpoon", branch = "harpoon2", @@ -38,7 +45,12 @@ lazy.setup({ end }, - "vimpostor/vim-tpipeline", + { + "vimpostor/vim-tpipeline", + config = function() + vim.g.tpipeline_restore = 1 + end + }, { "TobinPalmer/pastify.nvim", diff --git a/.config/nvim/lua/plugins/lspconfig.lua b/.config/nvim/lua/plugins/lspconfig.lua index bde13ae..33adb2d 100644 --- a/.config/nvim/lua/plugins/lspconfig.lua +++ b/.config/nvim/lua/plugins/lspconfig.lua @@ -12,7 +12,7 @@ vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" - vim.opt_local.signcolumn=numbers + vim.opt_local.signcolumn = numbers local telescope = require("telescope.builtin") local conform = require("conform") @@ -106,6 +106,11 @@ mason_lspconfig.setup_handlers({ -- rest of your on_attach process. require("ltex_extra").setup() end, + settings = { + ltex = { + language = "en-US", + }, + }, }) end, ["basedpyright"] = function() diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index 49aaf80..375ad2f 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -13,10 +13,10 @@ telescope.setup { pickers = { find_files = { previewer = false, - layout_strategy = "vertical", - layout_config = { + layout_strategy = "center", + layout_config = { height = 0.7, - width = 0.5 + width = 0.5 }, }, live_grep = { diff --git a/.config/nvim/queries/go/injections.scm b/.config/nvim/queries/go/injections.scm new file mode 100644 index 0000000..2ce05b0 --- /dev/null +++ b/.config/nvim/queries/go/injections.scm @@ -0,0 +1,103 @@ +; extends + +; inject sql in single line strings +; e.g. db.GetContext(ctx, "SELECT * FROM users WHERE name = 'John'") + +((call_expression + (selector_expression + field: (field_identifier) @_field) + (argument_list + (interpreted_string_literal) @sql)) + (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" + "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx") + (#offset! @sql 0 1 0 -1)) + +; still buggy for nvim 0.10 +((call_expression + (selector_expression + field: (field_identifier) @_field (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx")) + (argument_list + (interpreted_string_literal) @injection.content)) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "sql")) + +; neovim nightly 0.10 +([ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + (#match? @injection.content "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") +(#set! injection.language "sql")) + +; a general query injection +([ + (interpreted_string_literal) + (raw_string_literal) + ] @sql + (#match? @sql "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") + (#offset! @sql 0 1 0 -1)) + +; ---------------------------------------------------------------- +; fallback keyword and comment based injection + +([ + (interpreted_string_literal) + (raw_string_literal) + ] @sql + (#contains? @sql "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" + "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" + "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" + "not null" "primary key" "update set" "truncate table" "left join") + (#offset! @sql 0 1 0 -1)) + +; nvim 0.10 +([ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + (#contains? @injection.content "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" + "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" + "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" + "not null" "primary key" "update set" "truncate table" "left join") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "sql")) + + +; should I use a more exhaustive list of keywords? +; "ADD" "ADD CONSTRAINT" "ALL" "ALTER" "AND" "ASC" "COLUMN" "CONSTRAINT" "CREATE" "DATABASE" "DELETE" "DESC" "DISTINCT" "DROP" "EXISTS" "FOREIGN KEY" "FROM" "JOIN" "GROUP BY" "HAVING" "IN" "INDEX" "INSERT INTO" "LIKE" "LIMIT" "NOT" "NOT NULL" "OR" "ORDER BY" "PRIMARY KEY" "SELECT" "SET" "TABLE" "TRUNCATE TABLE" "UNION" "UNIQUE" "UPDATE" "VALUES" "WHERE" + +; json + +((const_spec + name: (identifier) @_const + value: (expression_list (raw_string_literal) @json)) + (#lua-match? @_const ".*[J|j]son.*")) + +; jsonStr := `{"foo": "bar"}` + +((short_var_declaration + left: (expression_list + (identifier) @_var) + right: (expression_list + (raw_string_literal) @json)) + (#lua-match? @_var ".*[J|j]son.*") + (#offset! @json 0 1 0 -1)) + +; nvim 0.10 + +(const_spec + name: ((identifier) @_const(#lua-match? @_const ".*[J|j]son.*")) + value: (expression_list (raw_string_literal) @injection.content + (#set! injection.language "json"))) + +(short_var_declaration + left: (expression_list (identifier) @_var (#lua-match? @_var ".*[J|j]son.*")) + right: (expression_list (raw_string_literal) @injection.content) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "json")) + +(var_spec + name: ((identifier) @_const(#lua-match? @_const ".*[J|j]son.*")) + value: (expression_list (raw_string_literal) @injection.content + (#set! injection.language "json"))) +