Skip to content

Commit

Permalink
feat: comments to open/toggle workspace or ducument mode directly
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Apr 22, 2021
1 parent 1ff45e2 commit f7db1c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ Trouble comes with the following defaults:
Trouble comes with the following commands:

* **LspTroubleOpen**: open the list
* **LspTroubleWorkspaceOpen**: set mode to "workspace" and open the list
* **LspTroubleDocumentOpen**: set mode to "document" and open the list
* **LspTroubleClose**: close the list
* **LspTroubleToggle**: toggle the list
* **LspTroubleWorkspaceToggle**: set mode to "workspace" and toggle the list (remains open if mode changes)
* **LspTroubleDocumentToggle**: set mode to "document" and toggle the list (remains open if mode changes)
* **LspTroubleRefresh**: manually refresh

Example keybinding of `<leader>xx` that toggles the trouble list:
Expand Down
15 changes: 14 additions & 1 deletion lua/trouble/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ end
function Trouble.close() if is_open() then view:close() end end

function Trouble.open(opts)
opts = opts or {}
if opts.mode and (opts.mode ~= config.options.mode) then
Trouble.action("toggle_mode")
end

if is_open() then
view:focus()
else
view = View.create(opts)
end
end

function Trouble.toggle()
function Trouble.toggle(opts)
opts = opts or {}

if opts.mode and (opts.mode ~= config.options.mode) then
Trouble.action("toggle_mode")
Trouble.open()
return
end

if is_open() then
Trouble.close()
else
Expand Down
5 changes: 5 additions & 0 deletions plugin/trouble.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ augroup LspTrouble
augroup end

command! LspTroubleOpen lua require'trouble'.open()
command! LspTroubleWorkspaceOpen lua require'trouble'.open({mode = "workspace"})
command! LspTroubleDocumentOpen lua require'trouble'.open({mode = "document"})
command! LspTroubleClose lua require'trouble'.close()
command! LspTroubleToggle lua require'trouble'.toggle()
command! LspTroubleWorkspaceToggle lua require'trouble'.toggle({mode = "workspace"})
command! LspTroubleDocumentToggle lua require'trouble'.toggle({mode = "document"})

command! LspTroubleRefresh lua require'trouble'.refresh()

0 comments on commit f7db1c2

Please sign in to comment.