From 54f4fca0c0bf47c66fa2acb503a3b8fc22cbfcdc Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 25 Apr 2021 12:43:18 +1000 Subject: [PATCH] update doc and configuration for float win size --- README.md | 21 ++++++++++++++------- lua/navigator.lua | 21 ++++++++++++++++----- lua/navigator/codeAction.lua | 2 +- lua/navigator/gui.lua | 6 ++++-- lua/navigator/lspclient/attach.lua | 4 +++- lua/navigator/lspclient/clients.lua | 12 ++++++------ 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b22aa32..26f5737 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,17 @@ EOF Generally speaking, you could remove most part of your lspconfig.lua and use the hooks in navigator.lua +## Depency + +- lspconfig +- guihua (provides floating window, FZY) +- Optional: + - lsp-status + - lsp-signature + - vim-illuminate + +The plugin can be loaded lazily (packer `opt = true` ), And it will check if optional plugins existance and load those plugins only if they existed. + ## Usage Please refer to lua/navigator/lspclient/mapping.lua on key mappings. Should be able to work out-of-box. @@ -138,11 +149,7 @@ Treetsitter symbols in all buffers # Todo -- Early phase, bugs expected -- Async (some of the requests is slow on large codebase and might be good to use co-rountine) +- Early phase, bugs expected, PR and suggestions are welcome +- Async (some of the requests is slow on large codebases and might be good to use co-rountine) - More clients. I use go, python, js/ts, java, c/cpp, lua most of the time. Do not test other languages (e.g dart, swift etc) -- Configure options - -``` - -``` +- Configuration options diff --git a/lua/navigator.lua b/lua/navigator.lua index b187cb4..29e1e76 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -1,8 +1,14 @@ local M = {} - -M.config_values ={ +_NgConfigValues ={ debug = false, -- log output code_action_icon = ' ', + width = nil, -- valeu of cols TODO allow float e.g. 0.6 + height = nil, + on_attach = function(client, bufnr) + -- your on_attach will be called at end of navigator on_attach + end, + sumneko_root_path = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server", + sumneko_binary = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server/bin/macOS/lua-language-server", code_action_prompt = { enable = true, sign = true, @@ -11,6 +17,8 @@ M.config_values ={ }, } + + vim.cmd("command! -nargs=0 LspLog call v:lua.open_lsp_log()") vim.cmd("command! -nargs=0 LspRestart call v:lua.reload_lsp()") @@ -18,20 +26,23 @@ local extend_config = function(opts) opts = opts or {} if next(opts) == nil then return end for key,value in pairs(opts) do - if M.config_values[key] == nil then + if _NgConfigValues[key] == nil then error(string.format('[] Key %s not valid',key)) return end if type(M.config_values[key]) == 'table' then for k,v in pairs(value) do - M.config_values[key][k] = v + _NgConfigValues[key][k] = v end else - M.config_values[key] = value + _NgConfigValues[key] = value end end end + +M.config_values = function() return _NgConfigValues end + M.setup = function(cfg) extend_config(cfg) -- print("loading navigator") diff --git a/lua/navigator/codeAction.lua b/lua/navigator/codeAction.lua index 00498ce..64593f5 100644 --- a/lua/navigator/codeAction.lua +++ b/lua/navigator/codeAction.lua @@ -2,7 +2,7 @@ local util = require "navigator.util" local log = util.log local code_action = {} local gui = require "navigator.gui" -local config = require("navigator").config_values +local config = require("navigator").config_values() local api = vim.api function code_action.code_action_handler(err, _, actions, cid, bufnr, _, customSelectionHandler) log(cid, bufnr) diff --git a/lua/navigator/gui.lua b/lua/navigator/gui.lua index 44cbfb9..4ed9296 100644 --- a/lua/navigator/gui.lua +++ b/lua/navigator/gui.lua @@ -86,6 +86,8 @@ function M.preview_uri(opts) -- uri, width, line, col, offset_x, offset_y end function M.new_list_view(opts) + local config = require("navigator").config_values() + local items = opts.items local data = {} if opts.rawdata then @@ -94,8 +96,8 @@ function M.new_list_view(opts) data = require "guihua.util".aggregate_filename(items, opts) end local wwidth = api.nvim_get_option("columns") - local width = opts.width or math.floor(wwidth * 0.8) - local wheight = math.floor(api.nvim_get_option("lines") * 0.8) + local width = config.width or opts.width or math.floor(wwidth * 0.8) + local wheight = config.height or math.floor(api.nvim_get_option("lines") * 0.8) local prompt = opts.prompt or false if data and not vim.tbl_isempty(data) then -- replace diff --git a/lua/navigator/lspclient/attach.lua b/lua/navigator/lspclient/attach.lua index b964d0a..b0cde9d 100644 --- a/lua/navigator/lspclient/attach.lua +++ b/lua/navigator/lspclient/attach.lua @@ -66,7 +66,7 @@ M.on_attach = function(client, bufnr) require("navigator.lspclient.mapping").setup({client = client, bufnr = bufnr, cap = client.resolved_capabilities}) vim.cmd [[packadd vim-illuminate]] - local hasilm, ilm = pcall(require, "illuminate") + local hasilm, ilm = pcall(require, "illuminate") -- package.loaded["illuminate"] if hasilm then ilm.on_attach(client) end @@ -74,6 +74,8 @@ M.on_attach = function(client, bufnr) local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true + local config = require'navigator'.config_value + if config ~= nil then config.on_attach(client, bufnr) end end M.setup = function(cfg) diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index b016860..9a20190 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -26,6 +26,8 @@ local highlight = require "navigator.lspclient.highlight" if lspconfig == nil then error("loading lsp config") end +local config = require'navigator'.config_values() + local cap = vim.lsp.protocol.make_client_capabilities() local on_attach = require("navigator.lspclient.attach").on_attach local lsp_status_cfg = { @@ -154,8 +156,8 @@ local sqls_cfg = { } } -- lua setup -local sumneko_root_path = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server" -local sumneko_binary = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server/bin/macOS/lua-language-server" +local sumneko_root_path = config.sumneko_root_path +local sumneko_binary = config.sumneko_binary local lua_cfg = { cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, @@ -237,7 +239,6 @@ local function setup(user_opts) end lsp_status_setup() - for _, lspclient in ipairs(servers) do if lsp_status ~= nil and lsp_status.capabilitiess ~= nil then lspconfig[lspclient].setup { @@ -257,11 +258,10 @@ local function setup(user_opts) lspconfig.gopls.setup(golang_setup) lspconfig.sqls.setup(sqls_cfg) - lspconfig.sumneko_lua.setup(lua_cfg) - lspconfig.clangd.setup(clang_cfg) - lspconfig.rust_analyzer.setup(rust_cfg) + + end return {setup = setup, cap = cap}