From 26012cf9c172aa788a2e53018d94b32c5c75af75 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 9 Sep 2021 12:59:58 +1000 Subject: [PATCH] Merge vim.loop changes (replacing vim.fn.getcwd) --- README.md | 2 ++ lua/navigator/cclshierarchy.lua | 2 +- lua/navigator/diagnostics.lua | 2 +- lua/navigator/gui.lua | 4 ++++ lua/navigator/hierarchy.lua | 2 +- lua/navigator/lspwrapper.lua | 2 +- lua/navigator/reference.lua | 20 +++++++++++++++----- lua/navigator/signature.lua | 2 +- lua/navigator/symbols.lua | 4 ++-- lua/navigator/treesitter.lua | 2 +- tests/reference_spec.lua | 6 +++--- 11 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b40f6fe..363264e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ included for LSP clients. all features(handler) provided by LSP from commonly used search reference, to less commonly used search for interface implementation. +- Luv async job + - Edit your code in preview window - Async request with lsp.buf_request for reference search diff --git a/lua/navigator/cclshierarchy.lua b/lua/navigator/cclshierarchy.lua index c139bcd..5a84de3 100644 --- a/lua/navigator/cclshierarchy.lua +++ b/lua/navigator/cclshierarchy.lua @@ -3,7 +3,7 @@ local util = require "navigator.util" local log = util.log local partial = util.partial local lsphelper = require "navigator.lspwrapper" -local cwd = vim.fn.getcwd(0) +local cwd = vim.loop.cwd() local path_sep = require"navigator.util".path_sep() local path_cur = require"navigator.util".path_cur() diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 74465d6..35c3144 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -106,7 +106,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config) log(err, config) return end - local cwd = vim.fn.getcwd(0) + local cwd = vim.loop.cwd() local ft = vim.bo.filetype if diagnostic_list[ft] == nil then diagnostic_list[vim.bo.filetype] = {} diff --git a/lua/navigator/gui.lua b/lua/navigator/gui.lua index ea53c2c..ec62b70 100644 --- a/lua/navigator/gui.lua +++ b/lua/navigator/gui.lua @@ -90,6 +90,7 @@ function M._preview_location(opts) -- location, width, pos_x, pos_y end function M.preview_uri(opts) -- uri, width, line, col, offset_x, offset_y + -- local handle = vim.loop.new_async(vim.schedule_wrap(function() local line_beg = opts.lnum - 1 if line_beg >= _NgConfigValues.preview_lines_before then line_beg = line_beg - _NgConfigValues.preview_lines_before @@ -104,6 +105,9 @@ function M.preview_uri(opts) -- uri, width, line, col, offset_x, offset_y trace("uri", opts.uri, opts.lnum, opts.location.range.start.line, opts.location.range['end'].line) return M._preview_location(opts) + -- handle:close() + -- end)) + -- handle:send() end function M.new_list_view(opts) diff --git a/lua/navigator/hierarchy.lua b/lua/navigator/hierarchy.lua index 7cc6a85..26ebdd9 100644 --- a/lua/navigator/hierarchy.lua +++ b/lua/navigator/hierarchy.lua @@ -6,7 +6,7 @@ local lsphelper = require "navigator.lspwrapper" local path_sep = require"navigator.util".path_sep() local path_cur = require"navigator.util".path_cur() -local cwd = vim.fn.getcwd(0) +local cwd = vim.loop.cwd() local M = {} local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message) diff --git a/lua/navigator/lspwrapper.lua b/lua/navigator/lspwrapper.lua index 01f917e..3595e48 100644 --- a/lua/navigator/lspwrapper.lua +++ b/lua/navigator/lspwrapper.lua @@ -10,7 +10,7 @@ local log = require"navigator.util".log local lerr = require"navigator.util".error local trace = require"navigator.util".trace local symbol_kind = require"navigator.lspclient.lspkind".symbol_kind -local cwd = vim.fn.getcwd(0) +local cwd = vim.loop.cwd() local is_win = vim.loop.os_uname().sysname:find("Windows") diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index bcee432..5536501 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -6,14 +6,14 @@ local gui = require "navigator.gui" local lsp = require "navigator.lspwrapper" local trace = require"navigator.util".trace -- local partial = util.partial --- local cwd = vim.fn.getcwd(0) +-- local cwd = vim.loop.cwd() -- local lsphelper = require "navigator.lspwrapper" local locations_to_items = lsphelper.locations_to_items -local ref_hdlr = mk_handler(function(err, locations, ctx, cfg) +local ref_view = function(err, locations, ctx, cfg) local opts = {} trace("arg1", err, ctx, locations) - log(api) + log(ctx.api) trace(locations) -- log("num", num) -- log("bfnr", bufnr) @@ -49,8 +49,18 @@ local ref_hdlr = mk_handler(function(err, locations, ctx, cfg) enable_preview_edit = true }) return listview, items, width -end) +end +local M = {} +local ref_hdlr = mk_handler(function(err, locations, ctx, cfg) + + trace(err, locations, ctx, cfg) + M.async_hdlr = vim.loop.new_async(vim.schedule_wrap(function() + ref_view(err, locations, ctx, cfg) + M.async_hdlr:close() + end)) + M.async_hdlr:send() +end) local async_reference_request = function() local ref_params = vim.lsp.util.make_position_params() ref_params.context = {includeDeclaration = true} @@ -58,4 +68,4 @@ local async_reference_request = function() lsp.call_async("textDocument/definition", ref_params, ref_hdlr) -- return asyncresult, canceller end -return {reference_handler = ref_hdlr, show_reference = async_reference_request} +return {reference_handler = ref_hdlr, show_reference = async_reference_request, ref_view = ref_view} diff --git a/lua/navigator/signature.lua b/lua/navigator/signature.lua index 285d811..e649de2 100644 --- a/lua/navigator/signature.lua +++ b/lua/navigator/signature.lua @@ -4,7 +4,7 @@ local mk_handler = util.mk_handler local log = util.log local partial = util.partial local lsphelper = require "navigator.lspwrapper" -local cwd = vim.fn.getcwd(0) +local cwd = vim.loop.cwd() local M = {} --- navigator signature diff --git a/lua/navigator/symbols.lua b/lua/navigator/symbols.lua index 4a6cfcc..6a3cf3b 100644 --- a/lua/navigator/symbols.lua +++ b/lua/navigator/symbols.lua @@ -144,7 +144,7 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx) -- for i, item in pairs(action.items) do -- data[i] = item.text -- if filename ~= item.filename then - -- local cwd = vim.fn.getcwd(0) .. "/" + -- local cwd = vim.loop.cwd() .. "/" -- local add = util.get_relative_path(cwd, item.filename) -- data[i] = data[i] .. " - " .. add -- end @@ -193,7 +193,7 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg) -- for i, item in pairs(action.items) do -- data[i] = item.text -- if filename ~= item.filename then - -- local cwd = vim.fn.getcwd(0) .. "/" + -- local cwd = vim.loop.cwd() .. "/" -- local add = util.get_relative_path(cwd, item.filename) -- data[i] = data[i] .. " - " .. add -- end diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index bc2a0e9..4f19b07 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -18,7 +18,7 @@ local api = vim.api local util = require "navigator.util" local M = {} -local cwd = vim.fn.getcwd(0) +local cwd = vim.loop.cwd() local log = require"navigator.util".log local lerr = require"navigator.util".error local trace = require"navigator.util".trace diff --git a/tests/reference_spec.lua b/tests/reference_spec.lua index 8e82527..86c01c6 100644 --- a/tests/reference_spec.lua +++ b/tests/reference_spec.lua @@ -50,7 +50,7 @@ describe("should run lsp reference", function() vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width vim.bo.filetype = "go" - vim.lsp.buf.references() + -- vim.lsp.buf.references() eq(1, 1) end) it("reference handler should return items", function() @@ -63,7 +63,7 @@ describe("should run lsp reference", function() print(path) local cmd = " silent exe 'e " .. path .. "'" vim.cmd(cmd) - vim.cmd([[cd %:p:h]]) + -- vim.cmd([[cd %:p:h]]) local bufn = vim.fn.bufnr("") vim.fn.setpos(".", {bufn, 15, 4, 0}) -- width @@ -125,7 +125,7 @@ describe("should run lsp reference", function() local win, items, width if nvim_6 then - win, items, width = require('navigator.reference').reference_handler(nil, result, { + win, items, width = require('navigator.reference').ref_view(nil, result, { method = 'textDocument/references', bufnr = 1, client_id = 1