From fba0ef8038c4541da57d7a9dc177558cd2d38b72 Mon Sep 17 00:00:00 2001 From: spike Date: Tue, 11 Oct 2022 00:12:27 +0200 Subject: [PATCH] rust-tools --- after/plugin/theme.lua | 8 + custom_snippets/rust.snippets | 3 + lua/core/mappings.lua | 3 +- lua/core/packer.lua | 1 + lua/custom/chadrc.lua | 68 ++++---- lua/custom/plugins/configs/navigator.lua | 2 +- lua/custom/plugins/configs/rust-tools.lua | 182 ++++++++++++++++++++++ lua/custom/plugins/init.lua | 14 +- lua/plugins/init.lua | 2 +- queries/lua/textobjects.scm | 2 + 10 files changed, 245 insertions(+), 40 deletions(-) create mode 100644 custom_snippets/rust.snippets create mode 100644 lua/custom/plugins/configs/rust-tools.lua diff --git a/after/plugin/theme.lua b/after/plugin/theme.lua index 333c6e5..4505493 100644 --- a/after/plugin/theme.lua +++ b/after/plugin/theme.lua @@ -8,10 +8,18 @@ local theme = require("base46").get_theme_tb "base_16" local ts_context_hl = c.change_hex_saturation(colors["yellow"], -20) local ts_context_hl = c.change_hex_lightness(ts_context_hl, -55) + + local highlights = { TreesitterContext = { bg = ts_context_hl, }, + InlayHint = { + fg = "#a9a19a", + }, + Comment = { + fg = c.change_hex_lightness(colors["one_bg"], 20), + }, } function set_hl() diff --git a/custom_snippets/rust.snippets b/custom_snippets/rust.snippets new file mode 100644 index 0000000..25b922f --- /dev/null +++ b/custom_snippets/rust.snippets @@ -0,0 +1,3 @@ + +snippet lnd + println!("{:?}", $1); diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index bf7c75f..ff0ffa5 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -591,7 +591,8 @@ M.general = { --{{{ -- [""] = { " Telescope find_files ", "find files" }, -- ["fa"] = { " Telescope find_files follow=true no_ignore=true hidden=true ", "find all" }, - [""] = { function () + [""] = { + function () local ignored_bufs = { "qf", } diff --git a/lua/core/packer.lua b/lua/core/packer.lua index 33bfa38..20c49a0 100644 --- a/lua/core/packer.lua +++ b/lua/core/packer.lua @@ -2,6 +2,7 @@ local M = {} M.options = { auto_clean = true, + -- log = { level = 'debug'}, compile_on_sync = true, git = { clone_timeout = 6000 }, display = { diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index ba29b32..0e4e105 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -37,58 +37,58 @@ M.ui = { }, }, hl_add = { - Visual = { - bg = "blue", - fg = "black", - }, - BookmarkSign = { - fg = "blue", - }, - BookmarkAnnotationSign = { - fg = "yellow", - }, - BookmarkAnnotationLine = { - fg = "black", - bg = "yellow" - }, - DiagnosticInfo = { -- nvchad uses DiagnosticInformation wrong hi group for lsp + Visual = { + bg = "blue", + fg = "black", + }, + BookmarkSign = { + fg = "blue", + }, + BookmarkAnnotationSign = { + fg = "yellow", + }, + BookmarkAnnotationLine = { + fg = "black", + bg = "yellow" + }, + DiagnosticInfo = { -- nvchad uses DiagnosticInformation wrong hi group for lsp fg = "white", italic = true, - }, - DiagnosticFloatingInfo = { + }, + DiagnosticFloatingInfo = { fg="white", italic=true, - }, - DiagnosticUnderlineError = { + }, + DiagnosticUnderlineError = { fg="black", bg="pink", - }, - -- Code Lens related colors - LspCodeLens = { + }, + -- Code Lens related colors + LspCodeLens = { fg = "vibrant_green", underline = true, - }, - LspDiagnosticsSignHint = { -- LspDiagnostics Code Action - fg = "vibrant_green", - italic = true, + }, + LspDiagnosticsSignHint = { -- LspDiagnostics Code Action + fg = "vibrant_green", + italic = true, }, -- end of code lens colors DiffText = { - bg = "vigrant_green" + bg = "vigrant_green" }, St_DapMode = { - fg = "black2", - bg = "baby_pink", + fg = "black2", + bg = "baby_pink", }, St_DapModeSep = { - fg = "baby_pink", - bg = "one_bg3", + fg = "baby_pink", + bg = "one_bg3", }, St_DapModeSep2 = { - fg = "grey", - bg = "baby_pink", + fg = "grey", + bg = "baby_pink", }, - }, +}, -- hl_override = { -- CursorLine = { -- underline = 1 diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua index 379604a..2941e3e 100644 --- a/lua/custom/plugins/configs/navigator.lua +++ b/lua/custom/plugins/configs/navigator.lua @@ -143,7 +143,7 @@ local config = { diagnostic_scrollbar_sign = false, - disable_lsp = {"clangd"}, + disable_lsp = {"clangd", "rust_analyzer"}, -- disable auto start of lsp per language -- set global default on lspconfig (see lspconfig doc) diff --git a/lua/custom/plugins/configs/rust-tools.lua b/lua/custom/plugins/configs/rust-tools.lua new file mode 100644 index 0000000..0bc1ef8 --- /dev/null +++ b/lua/custom/plugins/configs/rust-tools.lua @@ -0,0 +1,182 @@ +local M = {} +local opts = { + tools = { -- rust-tools options + + -- how to execute terminal commands + -- options right now: termopen / quickfix + executor = require("rust-tools/executors").termopen, + + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, + + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, + + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = true, + + -- Only show inlay hints for the current line + only_current_line = false, + + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, + + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "  ", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "  ", + + -- whether to align to the length of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "InlayHint", + }, + + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, + }, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false, + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + + -- List of backends found on: https://graphviz.org/docs/outputs/ + -- Is used for input validation and autocompletion + -- Last updated: 2021-08-26 + enabled_graphviz_backends = { + "bmp", + "cgimage", + "canon", + "dot", + "gv", + "xdot", + "xdot1.2", + "xdot1.4", + "eps", + "exr", + "fig", + "gd", + "gd2", + "gif", + "gtk", + "ico", + "cmap", + "ismap", + "imap", + "cmapx", + "imap_np", + "cmapx_np", + "jpg", + "jpeg", + "jpe", + "jp2", + "json", + "json0", + "dot_json", + "xdot_json", + "pdf", + "pic", + "pct", + "pict", + "plain", + "plain-ext", + "png", + "pov", + "ps", + "ps2", + "psd", + "sgi", + "svg", + "svgz", + "tga", + "tiff", + "tif", + "tk", + "vml", + "vmlz", + "wbmp", + "webp", + "xlib", + "x11", + }, + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- standalone file support + -- setting it to false may improve startup time + standalone = true, + cmd = {"run-rust-analyzer"}, -- use my wrapper script to see separate input/output log + on_attach = function(client, bufnr) + require('navigator.lspclient.mapping').setup({client=client, bufnr=bufnr}) -- setup navigator keymaps here, + require("navigator.dochighlight").documentHighlight(bufnr) + require('navigator.codeAction').code_action_prompt(bufnr) + -- otherwise, you can define your own commands to call navigator functions + end + }, -- rust-analyzer options + + -- debugging stuff + dap = { + adapter = { + type = "executable", + command = "lldb-vscode", + name = "rt_lldb", + }, + }, +} + +function M.setup() + require("rust-tools").setup(opts) +end + +return M diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index c61676a..9f6fd0f 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,4 +1,4 @@ --- vim: foldlevel=1 +-- vim: foldlevel=1 foldmethod=marker -- -- TODO: interesting plugins to install -- - neovim minisurround to replace vim-surround @@ -188,7 +188,6 @@ return { -- lock = true, after = "vim-hardtime", - tag = "*", disable = false, }, ["tom-anders/telescope-vim-bookmarks.nvim"] = { @@ -325,7 +324,6 @@ return { "fugitive", "guihua*", } - vim.g.hardtime_maxcount = 2 end, }, @@ -493,6 +491,16 @@ return { config = function() require("custom.plugins.configs.gonvim").setup() end + },-- }}} + + -- Rust dev + ["simrat39/rust-tools.nvim"] = {-- {{{ + lock = true, + ft = {"rust"}, + opt = true, + config = function() + require("custom.plugins.configs.rust-tools").setup() + end }-- }}} } diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index c492ecc..1732729 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -26,7 +26,7 @@ local plugins = { }, ["NvChad/ui"] = { - lock = false, + lock = true, after = "base46", config = function() require("plugins.configs.others").nvchad_ui() diff --git a/queries/lua/textobjects.scm b/queries/lua/textobjects.scm index 37babd0..2d3bf08 100644 --- a/queries/lua/textobjects.scm +++ b/queries/lua/textobjects.scm @@ -1 +1,3 @@ (field) @field.outer + +(function_declaration) @function.outer