Skip to content

Commit

Permalink
feat: make position of the trouble list configurable (top, bottom, le…
Browse files Browse the repository at this point in the history
…ft or right) #27
  • Loading branch information
folke committed May 9, 2021
1 parent 1fa8469 commit 0c9ca5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Trouble comes with the following defaults:

```lua
{
height = 10, -- height of the trouble list
position = "bottom", -- position of the list can be: bottom, top, left, right
height = 10, -- height of the trouble list when position is top or bottom
width = 50, -- width of the list when position is left or right
icons = true, -- use devicons for filenames
mode = "lsp_workspace_diagnostics", -- "lsp_workspace_diagnostics", "lsp_document_diagnostics", "quickfix", "lsp_references", "loclist"
fold_open = "", -- icon used for open folds
Expand Down
4 changes: 3 additions & 1 deletion lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ M.namespace = vim.api.nvim_create_namespace("LspTrouble")
---@field win number|nil
local defaults = {
debug = false,
height = 10, -- height of the trouble list
position = "bottom", -- position of the list can be: bottom, top, left, right
height = 10, -- height of the trouble list when position is top or bottom
width = 50, -- width of the list when position is left or right
icons = true, -- use devicons for filenames
mode = "lsp_workspace_diagnostics", -- "lsp_workspace_diagnostics", "lsp_document_diagnostics", "quickfix", "lsp_references", "loclist"
fold_open = "", -- icon used for open folds
Expand Down
9 changes: 7 additions & 2 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function View:setup(opts)
end
end

vim.api.nvim_win_set_height(self.win, config.options.height)
if config.options.position == "top" or config.options.position == "bottom" then
vim.api.nvim_win_set_height(self.win, config.options.height)
else
vim.api.nvim_win_set_width(self.win, config.options.width)
end

vim.api.nvim_exec([[
augroup LspTroubleHighlights
Expand Down Expand Up @@ -301,7 +305,8 @@ function View.create(opts)
vim.cmd("enew")
else
vim.cmd("below new")
vim.cmd("wincmd J")
local pos = {bottom = "J", top = "K", left = "H", right = "L"}
vim.cmd("wincmd " .. (pos[config.options.position] or "K"))
end
local buffer = View:new(opts)
buffer:setup(opts)
Expand Down

0 comments on commit 0c9ca5e

Please sign in to comment.