diff --git a/6.-Configurasi.md b/6.-Configurasi.md index 8e18864..0b1fd7d 100644 --- a/6.-Configurasi.md +++ b/6.-Configurasi.md @@ -341,1088 +341,3 @@ https://github.com/folke/lazy.nvim#Examples ] } ``` - -# Contoh Custom Plugin -## Mini Animate -- buat file lua/plugin/mini_animate.lua -- masukan code berikut -```lua -return { - -- animations - { - "echasnovski/mini.animate", - event = "VeryLazy", - opts = function() - -- don't use animate when scrolling with the mouse - local mouse_scrolled = false - for _, scroll in ipairs({ "Up", "Down" }) do - local key = "" - vim.keymap.set({ "", "i" }, key, function() - mouse_scrolled = true - return key - end, { expr = true }) - end - - local animate = require("mini.animate") - return { - resize = { - timing = animate.gen_timing.linear({ duration = 100, unit = "total" }), - }, - scroll = { - timing = animate.gen_timing.linear({ duration = 150, unit = "total" }), - subscroll = animate.gen_subscroll.equal({ - predicate = function(total_scroll) - if mouse_scrolled then - mouse_scrolled = false - return false - end - return total_scroll > 1 - end, - }), - }, - } - end, - config = function(_, opts) - require("mini.animate").setup(opts) - end, - }, -} -``` -info detail silahkan kunjungi :
-https://github.com/echasnovski/mini.animate - -## JSON -- buat file lua/plugin/json.lua -- masukan code berikut : -```lua -return { - - -- add json to treesitter - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "json", "json5", "jsonc" }) - end - end, - }, - - -- correctly setup lspconfig - { - "neovim/nvim-lspconfig", - dependencies = { - "b0o/SchemaStore.nvim", - version = false, -- last release is way too old - }, - opts = { - -- make sure mason installs the server - servers = { - jsonls = { - -- lazy-load schemastore when needed - on_new_config = function(new_config) - new_config.settings.json.schemas = new_config.settings.json.schemas or {} - vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas()) - end, - settings = { - json = { - format = { - enable = true, - }, - validate = { enable = true }, - }, - }, - }, - }, - }, - }, -} -``` -## Markdown Preview -- buat file lua/plugin/markdown.lua -- tambahkan code berikut didalamnya: -```lua -return{ - "iamcco/markdown-preview.nvim", - event = "BufRead", - build = "cd app && npm install", - config = function() - vim.g.mkdp_filetypes = { "markdown" } - end, - ft = { "markdown" }, - cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" }, -} -``` -- detail kunjungi :
-https://github.com/iamcco/markdown-preview.nvim - -## Config Java (JDTLS) -- Intall java dan create java home -``` -echo export JAVA_HOME='$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")' | sudo tee /etc/profile.d/jdk_home.sh > /dev/null -echo $JAVA_HOME -``` -- Install Treesitter -``` -:TSInstall java -``` -- Install Mason -``` -:MasonInstall jdtls java-debug-adapter -``` -- Tambahkan plugin pada file lua/plugin/init.lua -``` -{ "mfussenegger/nvim-jdtls", event = "BufRead" }, -``` -- Buat file ~/.config/nvim/ftplugin/java.lua dan tambahkan code dibawah ini -``` lua --- more space in the neovim command line for displaying messages --- use this function notation to build some variables -vim.opt_local.shiftwidth = 4 -vim.opt_local.tabstop = 4 -vim.opt_local.softtabstop = 4 -vim.opt_local.ts = 4 -vim.opt_local.expandtab = true - -local status, jdtls = pcall(require, "jdtls") -if not status then - return -end - -local function capabilities() - local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") - if status_ok then - return cmp_nvim_lsp.default_capabilities() - end - - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true - capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - "documentation", - "detail", - "additionalTextEdits", - }, - } - - return capabilities -end - -local function directory_exists(path) - local f = io.popen("cd " .. path) - local ff = f:read("*all") - - if ff:find("ItemNotFoundException") then - return false - else - return true - end -end - -local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } -local root_dir = require("jdtls.setup").find_root(root_markers) - --- calculate workspace dir -local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") -local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name -if directory_exists(workspace_dir) then -else - os.execute("mkdir " .. workspace_dir) -end --- get the mason install path -local install_path = require("mason-registry").get_package("jdtls"):get_install_path() - --- get the current OS -local os -if vim.fn.has("macunix") then - os = "mac" -elseif vim.fn.has("win32") then - os = "win" -else - os = "linux" -end - -local bundles = {} -local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") -vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n")) -vim.list_extend( - bundles, - vim.split( - vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"), - "\n" - ) -) - -local config = { - cmd = { - "java", - "-Declipse.application=org.eclipse.jdt.ls.core.id1", - "-Dosgi.bundles.defaultStartLevel=4", - "-Declipse.product=org.eclipse.jdt.ls.core.product", - "-Dlog.protocol=true", - "-Dlog.level=ALL", - "-javaagent:" .. install_path .. "/lombok.jar", - "-Xms1g", - "--add-modules=ALL-SYSTEM", - "--add-opens", - "java.base/java.util=ALL-UNNAMED", - "--add-opens", - "java.base/java.lang=ALL-UNNAMED", - "-jar", - vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"), - "-configuration", - install_path .. "/config_" .. os, - "-data", - workspace_dir, - }, - capabilities = capabilities(), - root_dir = root_dir, - settings = { - java = {}, - }, - - init_options = { - bundles = { - vim.fn.glob( - mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar", - "\n" - ), - }, - }, -} - -config["on_attach"] = function(client, bufnr) - local _, _ = pcall(vim.lsp.codelens.refresh) - require("jdtls.dap").setup_dap_main_class_configs() - jdtls.setup_dap({ hotcodereplace = "auto" }) - require("user.lsp.handlers").on_attach(client, bufnr) -end - -vim.api.nvim_create_autocmd({ "BufWritePost" }, { - pattern = { "*.java" }, - callback = function() - local _, _ = pcall(vim.lsp.codelens.refresh) - end, -}) - -jdtls.start_or_attach(config) - -vim.cmd( - [[command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime()]] -) -``` -## Auto Save -```lua -{ - "Pocco81/auto-save.nvim", - event = "BufRead", - config = function() - require("auto-save").setup({ - trigger_events = { "InsertLeave", "BufWinLeave" }, - execution_message = { - message = function() -- message to print on save - return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) - end, - dim = 0.18, -- dim the color of `message` - cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea - }, - }) - end, - }, - -``` -Detail Silahkan Kunjungi :
-https://github.com/Pocco81/auto-save.nvim - -## Override Lualine -- buat file lua/plugin/lualine.lua -- Tambahkan code berikut : -```lua -return { - "nvim-lualine/lualine.nvim", - event = "BufWinEnter", - config = function() - local status_ok, lualine = pcall(require, "lualine") - if not status_ok then - return - end - local icons = require("user.icons") - local hide_in_width = function() - return vim.fn.winwidth(0) > 80 - end - - local conditions = { - buffer_not_empty = function() - return vim.fn.empty(vim.fn.expand("%:t")) ~= 1 - end, - hide_in_width = function() - return vim.fn.winwidth(0) > 80 - end, - check_git_workspace = function() - local filepath = vim.fn.expand("%:p:h") - local gitdir = vim.fn.finddir(".git", filepath .. ";") - return gitdir and #gitdir > 0 and #gitdir < #filepath - end, - } - - local diagnostics = { - "diagnostics", - sources = { "nvim_diagnostic" }, - sections = { "error", "warn" }, - -- symbols = { error = " ", warn = " " }, - symbols = { - error = icons.diagnostics.BoldError .. " ", - warn = icons.diagnostics.BoldWarning .. " ", - }, - colored = true, - update_in_insert = false, - always_visible = false, - } - - local diff = { - "diff", - colored = true, - -- symbols = { added = " ", modified = " ", removed = " " }, -- changes diff symbols - symbols = { - added = icons.git.LineAdded .. " ", - modified = icons.git.LineModified .. " ", - removed = icons.git.LineRemoved .. " ", - }, -- changes diff symbols - cond = hide_in_width, - } - - local mode = { - "mode", - fmt = function(str) - return " " .. str - -- return " " .. str - end, - } - - local filetype = { - "filetype", - icons_enabled = true, - icon = nil, - } - - local branch = { - "branch", - icons_enabled = true, - --icon = "", - icon = icons.git.Branch, - } - - local location = { - "location", - padding = 0, - } - - -- cool function for progress - local progress = function() - local current_line = vim.fn.line(".") - local total_lines = vim.fn.line("$") - local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } - local line_ratio = current_line / total_lines - local index = math.ceil(line_ratio * #chars) - return chars[index] - end - - local spaces = function() - -- return "->| " .. vim.api.nvim_buf_get_option(0, "shiftwidth") - return icons.ui.Tab .. " " .. vim.api.nvim_buf_get_option(0, "shiftwidth") - end - - local file_name = { - "filename", - cond = conditions.buffer_not_empty, - } - - -- start for lsp - local list_registered_providers_names = function(filetype) - local s = require("null-ls.sources") - local available_sources = s.get_available(filetype) - local registered = {} - for _, source in ipairs(available_sources) do - for method in pairs(source.methods) do - registered[method] = registered[method] or {} - table.insert(registered[method], source.name) - end - end - return registered - end - - local null_ls = require("null-ls") - -- for formatter - local list_registered = function(filetype) - local method = null_ls.methods.FORMATTING - local registered_providers = list_registered_providers_names(filetype) - return registered_providers[method] or {} - end - - --- for linter - local alternative_methods = { - null_ls.methods.DIAGNOSTICS, - null_ls.methods.DIAGNOSTICS_ON_OPEN, - null_ls.methods.DIAGNOSTICS_ON_SAVE, - } - - local linter_list_registered = function(filetype) - local registered_providers = list_registered_providers_names(filetype) - local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m) - return registered_providers[m] or {} - end, alternative_methods)) - - return providers_for_methods - end - -- end for lsp - - local lsp_info = { - function() - --local msg = "No Active Lsp" - local msg = "LS Inactive" - -- local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") - local buf_ft = vim.bo.filetype - local clients = vim.lsp.get_active_clients() - -- start register - local buf_clients = vim.lsp.buf_get_clients() - local buf_client_names = {} - if next(buf_clients) == nil then - -- TODO: clean up this if statement - if type(msg) == "boolean" or #msg == 0 then - return "LS Inactive" - end - return msg - end - -- add client - for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" and client.name ~= "copilot" then - table.insert(buf_client_names, client.name) - end - end - -- add formatter - local supported_formatters = list_registered(buf_ft) - vim.list_extend(buf_client_names, supported_formatters) - -- add linter - local supported_linters = linter_list_registered(buf_ft) - vim.list_extend(buf_client_names, supported_linters) - -- decomple - local unique_client_names = vim.fn.uniq(buf_client_names) - local msg = table.concat(unique_client_names, ", ") - return msg - end, - --icon = " ", - icon = icons.ui.Gear .. "", - } - - lualine.setup({ - options = { - icons_enabled = true, - theme = "auto", - --component_separators = { left = "", right = "" }, - --section_separators = { left = "", right = "" }, - -- component_separators = { left = "", right = "" }, - -- section_separators = { left = "", right = "" }, - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = " " }, - - disabled_filetypes = { - "TelescopePrompt", - "packer", - "alpha", - "dashboard", - "NvimTree", - "Outline", - "DressingInput", - "toggleterm", - "lazy", - "mason", - }, - always_divide_middle = true, - }, - sections = { - lualine_a = { branch }, - lualine_b = { mode }, - lualine_c = { diagnostics, lsp_info }, - -- lualine_c = { file_name, lsp_info }, - -- lualine_x = { "encoding", "fileformat", "filetype" }, - lualine_x = { diff, spaces, "encoding", filetype }, - lualine_y = { location }, - lualine_z = { progress }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - extensions = {}, - }) - end, -} -``` -## Config Neotree -- Buat file lua/plugin/neotree.lua -- Tambahkan code berikut -```lua -return { - { "kyazdani42/nvim-tree.lua", enabled = false }, - { - "nvim-neo-tree/neo-tree.nvim", - dependencies={"MunifTanjim/nui.nvim",}, - event="BufWinEnter", - cmd = "Neotree", - keys = { - { - "fE", - function() - require("neo-tree.command").execute({ toggle = true, dir = vim.loop.cwd() }) - end, - desc = "Explorer NeoTree (cwd)", - }, - { "n", "Neotree toggle", desc = "Explorer NeoTree (root dir)", remap = true }, - { "E", "fE", desc = "Explorer NeoTree (cwd)", remap = true }, - }, - deactivate = function() - vim.cmd([[Neotree close]]) - end, - init = function() - vim.g.neo_tree_remove_legacy_commands = 1 - if vim.fn.argc() == 1 then - local stat = vim.loop.fs_stat(vim.fn.argv(0)) - if stat and stat.type == "directory" then - require("neo-tree") - end - end - end, - opts = { - filesystem = { - bind_to_cwd = false, - follow_current_file = true, - }, - window = { - position = "left", - width = 30, - mappings = { - [""] = "none", - }, - }, - default_component_configs = { - icon = { - folder_closed = "", - folder_open = "", - folder_empty = "ﰊ", - -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there - -- then these will never be used. - default = "*", - highlight = "NeoTreeFileIcon" - }, - modified = { - symbol = "[+]", - highlight = "NeoTreeModified", - }, - git_status = { - symbols = { - -- Change type - added = "✚", -- or "✚", but this is redundant info if you use git_status_colors on the name - modified = "", -- or "", but this is redundant info if you use git_status_colors on the name - deleted = "✖",-- this can only be used in the git_status source - renamed = "",-- this can only be used in the git_status source - -- Status type - untracked = "", - ignored = "", - -- unstaged = "", - unstaged = "", - staged = "", - conflict = "", - } - }, - }, - }, - }, -} -``` -- Tambahkan key mapping pada file lua/custom/whichkey.lua -``` -return { - ["e"]={"Neotree toggle","Explorer"}, -} -``` -## Overide Bufferline -- buat file lua/plugin/bufferline.lua -- Tambahkan code berikut: -```lua -return { - "akinsho/bufferline.nvim", - event = "BufWinEnter", - config = function() - local status_ok, bufferline = pcall(require, "bufferline") - if not status_ok then - return - end - - local icons = require("user.icons") - local use_icons = true - - local function diagnostics_indicator(num, _, diagnostics, _) - local result = {} - local symbols = { - error = icons.diagnostics.Error, - warning = icons.diagnostics.Warning, - info = icons.diagnostics.Information, - } - if not use_icons then - return "(" .. num .. ")" - end - for name, count in pairs(diagnostics) do - if symbols[name] and count > 0 then - table.insert(result, symbols[name] .. " " .. count) - end - end - result = table.concat(result, " ") - return #result > 0 and result or "" - end - - bufferline.setup({ - options = { - color_icons = true, - numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string, - close_command = function(bufnum) - require("bufdelete").bufdelete(bufnum, true) - end, - right_mouse_command = function(bufnum) - require("bufdelete").bufdelete(bufnum, true) - end, - left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" - middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" - indicator_icon = nil, - indicator = { style = "icon", icon = "▎" }, - buffer_close_icon = icons.ui.Close, - modified_icon = icons.ui.Circle, - close_icon = icons.ui.BoldClose, - left_trunc_marker = icons.ui.ArrowCircleLeft, - right_trunc_marker = icons.ui.ArrowCircleRight, - max_name_length = 30, - max_prefix_length = 30, -- prefix used when a buffer is de-duplicated - tab_size = 21, - diagnostics = false, -- | "nvim_lsp" | "coc", - diagnostics_update_in_insert = false, - diagnostics_indicator = diagnostics_indicator, - offsets = { - { - filetype = "NvimTree", - text = "Explorer", - highlight = "Directory", - text_align = "left", - padding = 1, - }, - { - filetype = "neo-tree", - text = "Explorer", - highlight = "Directory", - text_align = "left", - padding = 1, - }, - }, - show_buffer_icons = true, - show_buffer_close_icons = true, - show_close_icon = true, - show_tab_indicators = true, - persist_buffer_sort = true, -- whether or not custom sorted buffers should persist - separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' }, - enforce_regular_tabs = true, - always_show_bufferline = true, - }, - highlights = { - fill = { - fg = { attribute = "fg", highlight = "#ff0000" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - background = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - buffer_visible = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - - close_button = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - close_button_visible = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - - tab_selected = { - fg = { attribute = "fg", highlight = "Normal" }, - bg = { attribute = "bg", highlight = "Normal" }, - }, - tab = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - tab_close = { - fg = { attribute = "fg", highlight = "TabLineSel" }, - bg = { attribute = "bg", highlight = "Normal" }, - }, - - duplicate_selected = { - fg = { attribute = "fg", highlight = "TabLineSel" }, - bg = { attribute = "bg", highlight = "TabLineSel" }, - underline = true, - }, - duplicate_visible = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - underline = true, - }, - duplicate = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - underline = true, - }, - - modified = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - modified_selected = { - fg = { attribute = "fg", highlight = "Normal" }, - bg = { attribute = "bg", highlight = "Normal" }, - }, - modified_visible = { - fg = { attribute = "fg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - - separator = { - fg = { attribute = "bg", highlight = "TabLine" }, - bg = { attribute = "bg", highlight = "TabLine" }, - }, - separator_selected = { - fg = { attribute = "bg", highlight = "Normal" }, - bg = { attribute = "bg", highlight = "Normal" }, - }, - indicator_selected = { - fg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" }, - bg = { attribute = "bg", highlight = "Normal" }, - }, - }, - }) - end, -} -``` -## Typescript (jose-elias-alvarez) -- Unregister LSP (buka file lua/custom/register_lsp.lua) tambahkan code berikut : -``` -skipreg = { - "tsserver", -}, -``` -- Lakukan install mason -``` -:MasonInstall typescript-language-server prettier -``` -- Lakukan Install Treesitter -``` -:TSInstall javascript typescript tsx -``` -- Buat file lua/plugin/typecript.lua -```lua -return { - "jose-elias-alvarez/typescript.nvim", - event = "BufRead", - dependencies = { "williamboman/mason-lspconfig.nvim" }, - config = function() - require("typescript").setup({ - disable_commands = false, -- prevent the plugin from creating Vim commands - debug = false, -- enable debug logging for commands - go_to_source_definition = { - fallback = true, -- fall back to standard LSP definition on failure - }, - server = { -- pass options to lspconfig's setup method - on_attach = require("user.lsp.handlers").on_attach, - capabilities = require("user.lsp.handlers").capabilities, - }, - }) - end, -} -``` -sumber :
-https://github.com/jose-elias-alvarez/typescript.nvim -## Denols (deno-nvim) -- Unregister LSP (buka file lua/custom/register_lsp.lua) tambahkan code berikut : -``` -skipreg = { - "denols", -}, -``` -- Lakukan install mason -``` -:MasonInstall deno prettier -``` -- Lakukan Install Treesitter -``` -:TSInstall javascript typescript tsx -``` -- Buat file lua/plugin/denols.lua -```lua -return { - "sigmasd/deno-nvim", - event = "BufRead", - dependencies = { "williamboman/mason-lspconfig.nvim" }, - config = function() - require("deno-nvim").setup({ - server = { - on_attach = require("user.lsp.handlers").on_attach, - capabilities = require("user.lsp.handlers").capabilities, - }, - }) - end, -} -``` -sumber: -https://github.com/sigmaSd/deno-nvim -## clangd (clangd_extensions.nvim) -- Unregister LSP (buka file lua/custom/register_lsp.lua) tambahkan code berikut : -``` -skipreg = { - "clangd", -}, -``` -- Lakukan install mason -``` -:MasonInstall clangd clang-format -``` -- Lakukan Install Treesitter -``` -:TSInstall cpp c -``` -- Buat file lua/plugin/clangd.lua -```lua -return { - "p00f/clangd_extensions.nvim", - dependencies = { "williamboman/mason-lspconfig.nvim" }, - event = "BufRead", - config = function() - require("clangd_extensions").setup({ - server = { - on_attach = require("user.lsp.handlers").on_attach, - capabilities = { - offsetEncoding = "utf-8", - require("user.lsp.handlers").capabilities, - }, - }, - }) - end, -} -``` -sumber :
-https://github.com/p00f/clangd_extensions.nvim - -## Config Flutter Tool -- Pastikan sudah install dart dan flutter sdk
-https://dart.dev/get-dart
-https://docs.flutter.dev/get-started/install
-- cek pastikan path terregistrasi -``` -which flutter dart -``` - -- install treesitter -``` -:TSInstall dart -``` -- Buat file lua/plugin/flutter-tool.lua -```lua -return { - "akinsho/flutter-tools.nvim", - dependencies = { "williamboman/mason-lspconfig.nvim", "nvim-lua/plenary.nvim" }, - event = "BufRead", - config = function() - require("flutter-tools").setup({ - server = { - color = { - enabled = true, - }, - settings = { - showTodos = true, - completeFunctionCalls = true, - }, - on_attach = require("user.lsp.handlers").on_attach, - capabilities = { - require("user.lsp.handlers").capabilities, - }, - }, - }) - end, -} -``` -- config formatter cari file lua/custom/null-ls.lua -``` lua -local null_ls = require("null-ls") -local formatting = null_ls.builtins.formatting -local diagnostics = null_ls.builtins.diagnostics -local m = { - sources = { - formatting.dart_format, - }, -} -return m - -``` -sumber :
-https://github.com/akinsho/flutter-tools.nvim -## Config rust-tools -- Pastikan sudah install Rust
-https://www.rust-lang.org/tools/install - -- Install Treesitter -``` -:TSInstall rust toml -``` -- Mason Install -``` -:MasonInstall rust-analizer codelldb rustfmt -``` -- Buat file lua/plugin/rust-analizer.lua -```lua -return { - "simrat39/rust-tools.nvim", - event = "BufRead", - dependencies = { - "mason-lspconfig.nvim", - { - "saecki/crates.nvim", - tag = "v0.3.0", - dependencies = { "nvim-lua/plenary.nvim" }, - config = function() - require("crates").setup({ - null_ls = { - enabled = true, - name = "crates.nvim", - }, - popup = { - border = "rounded", - }, - }) - end, - }, - }, - config = function() - local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") - local codelldb_adapter = { - type = "server", - port = "${port}", - executable = { - command = mason_path .. "bin/codelldb", - args = { "--port", "${port}" }, - -- On windows you may have to uncomment this: - -- detached = false, - }, - } - - local rt = require("rust-tools") - rt.setup({ - tools = { - executor = require("rust-tools/executors").termopen, -- can be quickfix or termopen - reload_workspace_from_cargo_toml = true, - runnables = { - use_telescope = true, - }, - inlay_hints = { - auto = true, - only_current_line = false, - show_parameter_hints = false, - parameter_hints_prefix = "<-", - other_hints_prefix = "=>", - max_len_align = false, - max_len_align_padding = 1, - right_align = false, - right_align_padding = 7, - highlight = "Comment", - }, - hover_actions = { - border = "rounded", - }, - on_initialized = function() - vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter", "CursorHold", "InsertLeave" }, { - pattern = { "*.rs" }, - callback = function() - local _, _ = pcall(vim.lsp.codelens.refresh) - end, - }) - end, - }, - dap = { - adapter = codelldb_adapter, - }, - server = { - on_attach = function(client, bufnr) - require("user.lsp.handlers").on_attach(client, bufnr) - local rt = require("rust-tools") - vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr }) - end, - capabilities = require("user.lsp.handlers").capabilities, - settings = { - ["rust-analyzer"] = { - lens = { - enable = true, - }, - checkOnSave = { - enable = true, - command = "clippy", - }, - }, - }, - }, - }) - local dap = require("dap") - dap.adapters.codelldb = codelldb_adapter - dap.configurations.rust = { - { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - }, - } - vim.api.nvim_set_keymap("n", "", "RustOpenExternalDocs", { noremap = true, silent = true }) - end, -} -``` -- Tambahkan whichkey lua/custom/whichkey.lua -```lua -return{ -["C"] = { - name = "Rust", - r = { "RustRunnables", "Runnables" }, - t = { "lua _CARGO_TEST()", "Cargo Test" }, - m = { "RustExpandMacro", "Expand Macro" }, - c = { "RustOpenCargo", "Open Cargo" }, - p = { "RustParentModule", "Parent Module" }, - d = { "RustDebuggables", "Debuggables" }, - v = { "RustViewCrateGraph", "View Crate Graph" }, - R = { - "lua require('rust-tools/workspace_refresh')._reload_workspace_from_cargo_toml()", - "Reload Workspace", - }, - o = { "RustOpenExternalDocs", "Open External Docs" }, - y = { "lua require'crates'.open_repository()", "[crates] open repository" }, - P = { "lua require'crates'.show_popup()", "[crates] show popup" }, - i = { "lua require'crates'.show_crate_popup()", "[crates] show info" }, - f = { "lua require'crates'.show_features_popup()", "[crates] show features" }, - D = { "lua require'crates'.show_dependencies_popup()", "[crates] show dependencies" }, - }, -} -``` -Sumber :
-https://github.com/simrat39/rust-tools.nvim