Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(outline)!: remove code actions from outline #387

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading