Skip to content

Commit

Permalink
feat(outline)!: remove code actions from outline (#387)
Browse files Browse the repository at this point in the history
Code actions in outline do not work, as mentioned in #244. Also, implementation uses deprecated API (vim.lsp.diagnostic.get_line_diagnostics) so to reduce maintenance this functionality is removed.
  • Loading branch information
sidlatau authored Sep 23, 2024
1 parent ea1d398 commit 6610090
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 138 deletions.
72 changes: 0 additions & 72 deletions lua/flutter-tools/lsp/code_actions.lua

This file was deleted.

66 changes: 0 additions & 66 deletions lua/flutter-tools/outline.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local ui = require("flutter-tools.ui")
local utils = require("flutter-tools.utils")
local config = require("flutter-tools.config")
local code_actions = require("flutter-tools.lsp.code_actions")

local api = vim.api
local fn = vim.fn
local lsp = vim.lsp
local fmt = string.format
local outline_filename = "Flutter Outline"
local outline_filetype = "flutterToolsOutline"
Expand Down Expand Up @@ -301,69 +299,6 @@ local function setup_autocommands()
})
end

---Execute the currently selected code action in the code action popup
---@param actions table[]
---@param action_win number
---@param code_buf number
---@param code_win number
---@param outline_win number
---@return function
local function select_code_action(actions, action_win, code_buf, code_win, outline_win)
return function()
local ln = api.nvim_get_current_line()
--- TODO: improve this once popup create returns a mapping of data to lines
local action = utils.find(actions, function(ca) return ln:match(ca.title) end)
if action then
code_actions.execute(action, code_buf, function()
-- HACK: figure out how to automatically refresh the code window so the new widget appears in the outline window
api.nvim_set_current_win(code_win)
vim.defer_fn(function() api.nvim_set_current_win(outline_win) end, 500)
end)
end
if api.nvim_win_is_valid(action_win) then api.nvim_win_close(action_win, true) end
end
end

---Find the window the outline relates to
---@param uri string
---@return number?, number[]?
local function find_code_window(uri)
local code_buf = vim.uri_to_bufnr(uri)
local code_wins = fn.win_findbuf(code_buf)
if not code_wins or #code_wins == 0 then return end
return code_wins[1], code_wins
end

local function request_code_actions()
local line = fn.line(".")
local uri = vim.b.outline_uri
if not uri then return ui.notify("Sorry! code actions not available") end
local outline = M.outlines[uri]
local item = outline[line]
if not item then return end
local params = code_actions.get_action_params(item, uri)
if not params then return end

local code_buf = vim.uri_to_bufnr(uri)
local code_win = find_code_window(uri)
local outline_win = api.nvim_get_current_win()

if not code_win then return end

lsp.buf_request(
params.bufnr,
"textDocument/codeAction",
params,
utils.lsp_handler(function(_, actions, _)
code_actions.open(
actions,
function(_, win) select_code_action(actions, win, code_buf, code_win, outline_win) end
)
api.nvim_win_set_cursor(code_win, { item.start_line + 1, item.start_col + 1 })
end)
)
end

local function select_outline_item()
local line = fn.line(".")
local uri = vim.b.outline_uri
Expand Down Expand Up @@ -402,7 +337,6 @@ local function setup_outline_window(buf, win, lines, highlights, _)

vim.keymap.set("n", "q", "<Cmd>bw!<CR>", { nowait = true, buffer = buf })
vim.keymap.set("n", "<CR>", select_outline_item, { buffer = buf, nowait = true })
vim.keymap.set("n", "a", request_code_actions, { buffer = buf, nowait = true })

setup_autocommands()
end
Expand Down

0 comments on commit 6610090

Please sign in to comment.