bugfix: fname->filename; allow treesitter work without LSP

neovim_0_5
ray-x 3 years ago
parent 9788bbaf54
commit 8d75a1498a

@ -143,6 +143,34 @@ EOF
You can remove your lspconfig.lua and use the hooks of navigator.lua. As the You can remove your lspconfig.lua and use the hooks of navigator.lua. As the
navigator will bind keys and handler for you. The LSP will be loaded lazily based on filetype. navigator will bind keys and handler for you. The LSP will be loaded lazily based on filetype.
A treesitter only mode. In some cases LSP is buggy or not available, you can also us treesitter
standalone
```vim
call plug#begin('~/.vim/plugged')
Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/navigator.lua'
" Plug 'hrsh7th/nvim-compe' and other plugins you commenly use...
" optional, if you need treesitter symbol support
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" optional:
Plug 'nvim-treesitter/nvim-treesitter-refactor' " this provides "go to def" etc
call plug#end()
lua <<EOF
require'navigator'.setup()
EOF
```
Nondefault configuration example: Nondefault configuration example:
```lua ```lua
@ -244,6 +272,21 @@ e.g
require'navigator'.setup({on_attach = function(client, bufnr) require 'illuminate'.on_attach(client)}) require'navigator'.setup({on_attach = function(client, bufnr) require 'illuminate'.on_attach(client)})
``` ```
## Highlight
Highlight I am using:
* LspReferenceRead, LspReferenceText and LspReferenceWrite are used for `autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()`
That is where you saw current symbol been highlighted.
* GHListDark and GHTextViewDark is used for floating listvew and TextView. They are be based on current background
(Normal) and PmenuSel
* In future, I will use NormalFloat for floating view. But ATM, most of colorscheme does not define NormalFloat
You can override above highlight to fit your current colorscheme
## Screenshots ## Screenshots
colorscheme: [aurora](https://github.com/ray-x/aurora) colorscheme: [aurora](https://github.com/ray-x/aurora)

@ -24,7 +24,7 @@ local function add_locs(bufnr, result)
_NG_hi_list[symbol] = {range = {}} _NG_hi_list[symbol] = {range = {}}
end end
if _NG_hi_list[symbol] ~= nil then if _NG_hi_list[symbol] ~= nil then
log("already added", symbol) trace("already added", symbol)
_NG_hi_list[symbol].range = {} _NG_hi_list[symbol].range = {}
-- vim.fn.matchdelete(hid) -- vim.fn.matchdelete(hid)
end end
@ -37,7 +37,7 @@ local function nohl()
for key, value in pairs(_NG_hi_list) do for key, value in pairs(_NG_hi_list) do
if value.hi_ids ~= nil then if value.hi_ids ~= nil then
for _, v in ipairs(value.hi_ids) do for _, v in ipairs(value.hi_ids) do
log("delete", v) trace("delete", v)
vim.fn.matchdelete(v) vim.fn.matchdelete(v)
end end
_NG_hi_list[key].hi_ids = nil _NG_hi_list[key].hi_ids = nil
@ -85,7 +85,7 @@ local function hi_symbol()
total_match = tonumber(p) total_match = tonumber(p)
end end
if total_match == totalref then -- same number as matchpos if total_match == totalref then -- same number as matchpos
log(total_match, "use matchadd()") trace(total_match, "use matchadd()")
local k = range[1].kind local k = range[1].kind
local hi_name = string.format("NGHiReference_%i_%i", _NG_ref_hi_idx, k) local hi_name = string.format("NGHiReference_%i_%i", _NG_ref_hi_idx, k)
local m = string.format("\\<%s\\>", symbol_wd) local m = string.format("\\<%s\\>", symbol_wd)
@ -107,7 +107,7 @@ local function hi_symbol()
end end
local w = value.range['end'].character - value.range.start.character local w = value.range['end'].character - value.range.start.character
local hi_name = string.format("NGHiReference_%i_%i", _NG_ref_hi_idx, k) local hi_name = string.format("NGHiReference_%i_%i", _NG_ref_hi_idx, k)
log(hi_name, {l, cs, w}) trace(hi_name, {l, cs, w})
local m = vim.fn.matchaddpos(hi_name, {{l, cs, w}}, 10) local m = vim.fn.matchaddpos(hi_name, {{l, cs, w}}, 10)
table.insert(_NG_hi_list[symbol].hi_ids, m) table.insert(_NG_hi_list[symbol].hi_ids, m)
end end
@ -153,7 +153,7 @@ local function handle_document_highlight(_, _, result, _, bufnr, _)
end end
-- modify from vim-illuminate -- modify from vim-illuminate
local function goto_adjent_reference(opt) local function goto_adjent_reference(opt)
log(opt) trace(opt)
opt = vim.tbl_extend("force", {forward = true, wrap = true}, opt or {}) opt = vim.tbl_extend("force", {forward = true, wrap = true}, opt or {})
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
@ -187,7 +187,7 @@ local function goto_adjent_reference(opt)
next = refs[nexti].range next = refs[nexti].range
end end
log(next) trace(next)
vim.api.nvim_win_set_cursor(0, {next.start.line + 1, next.start.character}) vim.api.nvim_win_set_cursor(0, {next.start.line + 1, next.start.character})
return next return next
end end

@ -189,9 +189,8 @@ function M.new_list_view(opts)
pos = 1 pos = 1
end end
local l = idx(data, pos) -- bug it not work with fzy filter local l = idx(data, pos) -- bug it not work with fzy filter
log(data)
if l.filename ~= nil then if l.filename ~= nil then
trace("openfile ", l.filename, l.lnum, l.col) log("openfile ", l.filename, l.lnum, l.col)
util.open_file_at(l.filename, l.lnum, l.col) util.open_file_at(l.filename, l.lnum, l.col)
end end
end, end,

@ -20,7 +20,11 @@ end
local has_lsp, lspconfig = pcall(require, "lspconfig") local has_lsp, lspconfig = pcall(require, "lspconfig")
if not has_lsp then if not has_lsp then
error("loading lsp config") return {
setup = function()
print("loading lsp config failed LSP may not working correctly")
end
}
end end
local highlight = require "navigator.lspclient.highlight" local highlight = require "navigator.lspclient.highlight"

@ -10,21 +10,25 @@ local event_hdlrs = {
{ev = "CursorMoved", func = "clear_references()"} {ev = "CursorMoved", func = "clear_references()"}
} }
local double = {"", "", "", "", "", "", "", ""}
local single = {"", "", "", "", "", "", "", ""}
local key_maps = { local key_maps = {
{key = "gr", func = "references()"}, {mode = "i", key = "<M-k>", func = "signature_help()"}, {key = "gr", func = "references()"}, {mode = "i", key = "<M-k>", func = "signature_help()"},
{key = "gs", func = "signature_help()"}, {key = "g0", func = "document_symbol()"}, {key = "gs", func = "signature_help()"}, {key = "g0", func = "document_symbol()"},
{key = "gW", func = "workspace_symbol()"}, {key = "<c-]>", func = "definition()"}, {key = "gW", func = "workspace_symbol()"}, {key = "<c-]>", func = "definition()"},
{key = "gD", func = "declaration()"}, {key = "gD", func = "declaration({ popup_opts = { border = 'single' }})"},
{key = "gp", func = "require('navigator.definition').definition_preview()"}, {key = "gp", func = "require('navigator.definition').definition_preview()"},
{key = "gT", func = "require('navigator.treesitter').buf_ts()"}, {key = "gT", func = "require('navigator.treesitter').buf_ts()"},
{key = "GT", func = "require('navigator.treesitter').bufs_ts()"}, {key = "K", func = "hover()"}, {key = "GT", func = "require('navigator.treesitter').bufs_ts()"},
{key = "K", func = "hover({ popup_opts = { border = single }})"},
{key = "ga", mode = "n", func = "code_action()"}, {key = "ga", mode = "n", func = "code_action()"},
{key = "ga", mode = "v", func = "range_code_action()"}, {key = "<Leader>re", func = "rename()"}, {key = "ga", mode = "v", func = "range_code_action()"}, {key = "<Leader>re", func = "rename()"},
{key = "<Leader>gi", func = "incoming_calls()"}, {key = "<Leader>go", func = "outgoing_calls()"}, {key = "<Leader>gi", func = "incoming_calls()"}, {key = "<Leader>go", func = "outgoing_calls()"},
{key = "gi", func = "implementation()"}, {key = "gt", func = "type_definition()"}, {key = "gi", func = "implementation()"}, {key = "gt", func = "type_definition()"},
{key = "gL", func = "diagnostic.show_line_diagnostics()"}, {key = "gL", func = "diagnostic.show_line_diagnostics()"},
{key = "gG", func = "require('navigator.diagnostics').show_diagnostic()"}, {key = "gG", func = "require('navigator.diagnostics').show_diagnostic()"},
{key = "]d", func = "diagnostic.goto_next()"}, {key = "[d", func = "diagnostic.goto_prev()"}, {key = "]d", func = "diagnostic.goto_next({ popup_opts = { border = single }})"},
{key = "[d", func = "diagnostic.goto_next({ popup_opts = { border = single }})"},
{key = "]r", func = "require('navigator.treesitter').goto_next_usage()"}, {key = "]r", func = "require('navigator.treesitter').goto_next_usage()"},
{key = "[r", func = "require('navigator.treesitter').goto_previous_usage()"}, {key = "[r", func = "require('navigator.treesitter').goto_previous_usage()"},
{key = "<C-LeftMouse>", func = "definition()"}, {key = "g<LeftMouse>", func = "implementation()"}, {key = "<C-LeftMouse>", func = "definition()"}, {key = "g<LeftMouse>", func = "implementation()"},
@ -174,7 +178,7 @@ function M.setup(user_opts)
vim.lsp.handlers["textDocument/signatureHelp"] = require"navigator.signature".signature_handler vim.lsp.handlers["textDocument/signatureHelp"] = require"navigator.signature".signature_handler
end end
-- vim.lsp.handlers["textDocument/hover"] = require 'navigator.hover'.hover_handler vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = single})
end end
return M return M

@ -116,7 +116,7 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
child.range = c.range child.range = c.range
local ckind = symbol_kind(child.kind) local ckind = symbol_kind(child.kind)
child.selectionRange = c.selectionRange child.selectionRange = c.selectionRange
child.fname = fname child.filename = fname
child.uri = uri child.uri = uri
child.lnum = c.range.start.line + 1 child.lnum = c.range.start.line + 1
child.detail = c.detail or "" child.detail = c.detail or ""

Loading…
Cancel
Save