Merge pull request #58 from simrat39/ram02z-master

Ram02z master
This commit is contained in:
sim
2021-08-20 19:19:29 -07:00
committed by GitHub
5 changed files with 61 additions and 45 deletions

View File

@@ -41,7 +41,7 @@ vim.g.symbols_outline = {
goto_location = "<Cr>", goto_location = "<Cr>",
focus_location = "o", focus_location = "o",
hover_symbol = "<C-space>", hover_symbol = "<C-space>",
preview_symbol = "K", toggle_preview = "K",
rename_symbol = "r", rename_symbol = "r",
code_actions = "a", code_actions = "a",
}, },
@@ -103,16 +103,16 @@ vim.g.symbols_outline = {
### Default keymaps ### Default keymaps
| Key | Action | | Key | Action |
| ---------- | -------------------------------------------------- | | ---------- | ------------------------------------------------------------------ |
| Escape | Close outline | | Escape | Close outline |
| Enter | Go to symbol location in code | | Enter | Go to symbol location in code |
| o | Go to symbol location in code without losing focus | | o | Go to symbol location in code without losing focus |
| Ctrl+Space | Hover current symbol | | Ctrl+Space | Hover current symbol |
| K | Show current symbol preview | | K | Toggles the current symbol preview (Only when auto_preview is off) |
| r | Rename symbol | | r | Rename symbol |
| a | Code actions | | a | Code actions |
| ? | Show help message | | ? | Show help message |
### Highlights ### Highlights
| Highlight | Purpose | | Highlight | Purpose |

View File

@@ -58,7 +58,7 @@ or skip this section entirely if you want to roll with the defaults.
goto_location = "<Cr>", goto_location = "<Cr>",
focus_location = "o", focus_location = "o",
hover_symbol = "<C-space>", hover_symbol = "<C-space>",
preview_symbol = "K", toggle_preview = "K",
rename_symbol = "r", rename_symbol = "r",
code_actions = "a", code_actions = "a",
}, },
@@ -218,8 +218,8 @@ symbol_blacklist
================================================================================ ================================================================================
5. COMMANDS *symbols-outline-commands* 5. COMMANDS *symbols-outline-commands*
| Command | Description | | Command | Description |
| ---------------------- | ---------------------- | | -------------------- | ---------------------- |
| `:SymbolsOutline` | Toggle symbols outline | | `:SymbolsOutline` | Toggle symbols outline |
| `:SymbolsOutlineOpen` | Open symbols outline | | `:SymbolsOutlineOpen` | Open symbols outline |
| `:SymbolsOutlineClose` | Close symbols outline | | `:SymbolsOutlineClose` | Close symbols outline |
@@ -227,16 +227,16 @@ symbol_blacklist
================================================================================ ================================================================================
6. DEFAULT KEYMAPS *symbols-outline-default_keymaps* 6. DEFAULT KEYMAPS *symbols-outline-default_keymaps*
| Key | Action | | Key | Action |
| ---------- | -------------------------------------------------- | | ---------- | ------------------------------------------------------------------ |
| Escape | Close outline | | Escape | Close outline |
| Enter | Go to symbol location in code | | Enter | Go to symbol location in code |
| o | Go to symbol location in code without losing focus | | o | Go to symbol location in code without losing focus |
| Ctrl+Space | Hover current symbol | | Ctrl+Space | Hover current symbol |
| K | Show current symbol preview | | K | Toggles the current symbol preview (Only when auto_preview is off) |
| r | Rename symbol | | r | Rename symbol |
| a | Code actions | | a | Code actions |
| ? | Show help message | | ? | Show help message |
================================================================================ ================================================================================
7. HIGHLIGHTS *symbols-outline-highlights* 7. HIGHLIGHTS *symbols-outline-highlights*

View File

@@ -22,9 +22,7 @@ local function setup_global_autocmd()
vim.cmd( vim.cmd(
"au InsertLeave,WinEnter,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()") "au InsertLeave,WinEnter,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
vim.cmd "au BufLeave * lua require'symbols-outline'._prevent_buffer_override()" vim.cmd "au BufLeave * lua require'symbols-outline'._prevent_buffer_override()"
if config.options.auto_preview then vim.cmd("au WinEnter * lua require'symbols-outline.preview'.close()")
vim.cmd "au WinEnter * lua require'symbols-outline.preview'.close_if_not_in_outline()"
end
if config.options.highlight_hovered_item then if config.options.highlight_hovered_item then
vim.cmd( vim.cmd(
"autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()") "autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()")
@@ -34,8 +32,12 @@ end
local function setup_buffer_autocmd() local function setup_buffer_autocmd()
if config.options.auto_preview then if config.options.auto_preview then
vim.cmd( vim.cmd(
"au CursorHold <buffer> lua require'symbols-outline.preview'.show()") "au CursorHold <buffer> lua require'symbols-outline.preview'.show(true)")
else
vim.cmd(
"au CursorMoved <buffer> lua require'symbols-outline.preview'.close()")
end end
end end
local function getParams() local function getParams()
@@ -215,8 +217,8 @@ local function setup_keymaps(bufnr)
nmap(config.options.keymaps.hover_symbol, nmap(config.options.keymaps.hover_symbol,
":lua require('symbols-outline.hover').show_hover()<Cr>") ":lua require('symbols-outline.hover').show_hover()<Cr>")
-- preview symbol -- preview symbol
nmap(config.options.keymaps.preview_symbol, nmap(config.options.keymaps.toggle_preview,
":lua require('symbols-outline.preview').show()<Cr>") ":lua require('symbols-outline.preview').toggle()<Cr>")
-- rename symbol -- rename symbol
nmap(config.options.keymaps.rename_symbol, nmap(config.options.keymaps.rename_symbol,
":lua require('symbols-outline.rename').rename()<Cr>") ":lua require('symbols-outline.rename').rename()<Cr>")

View File

@@ -16,7 +16,7 @@ local defaults = {
goto_location = "<Cr>", goto_location = "<Cr>",
focus_location = "o", focus_location = "o",
hover_symbol = "<C-space>", hover_symbol = "<C-space>",
preview_symbol = "K", toggle_preview = "K",
rename_symbol = "r", rename_symbol = "r",
code_actions = "a", code_actions = "a",
show_help = "?", show_help = "?",

View File

@@ -135,18 +135,6 @@ local function setup_hover_buf()
update_hover() update_hover()
end end
function M.close_if_not_in_outline()
if not is_current_win_outline() and has_code_win() then
if state.preview_win ~= nil and
vim.api.nvim_win_is_valid(state.preview_win) then
vim.api.nvim_win_close(state.preview_win, true)
end
if state.hover_win ~= nil and vim.api.nvim_win_is_valid(state.hover_win) then
vim.api.nvim_win_close(state.hover_win, true)
end
end
end
local function show_preview() local function show_preview()
if state.preview_win == nil and state.preview_buf == nil then if state.preview_win == nil and state.preview_buf == nil then
state.preview_buf = vim.api.nvim_create_buf(false, true) state.preview_buf = vim.api.nvim_create_buf(false, true)
@@ -198,12 +186,38 @@ local function show_hover()
end end
end end
function M.show() function M.show(force)
if not is_current_win_outline() or #vim.api.nvim_list_wins() < 2 then if not is_current_win_outline() or
#vim.api.nvim_list_wins() < 2 then
return return
end end
if force ~= true and state.preview_win ~= nil then
return 1
end
show_preview() show_preview()
show_hover() show_hover()
end end
function M.close()
if has_code_win() then
if state.preview_win ~= nil and
vim.api.nvim_win_is_valid(state.preview_win) then
vim.api.nvim_win_close(state.preview_win, true)
end
if state.hover_win ~= nil and
vim.api.nvim_win_is_valid(state.hover_win) then
vim.api.nvim_win_close(state.hover_win, true)
end
end
end
function M.toggle()
local code = M.show()
if code == 1 then
M.close()
end
end
return M return M