-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beba3cc
commit 2cfe0ef
Showing
7 changed files
with
388 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,112 @@ | ||
return { | ||
layout = require("clojure-test.ui.layout"), | ||
report_tree = require("clojure-test.ui.report-tree"), | ||
} | ||
local report_tree_api = require("clojure-test.ui.report-tree") | ||
local exceptions = require("clojure-test.ui.exceptions") | ||
local layout_api = require("clojure-test.ui.layout") | ||
local config = require("clojure-test.config") | ||
local utils = require("clojure-test.utils") | ||
|
||
local M = {} | ||
|
||
local function write_clojure_to_buf(buf, contents) | ||
vim.api.nvim_buf_set_option(buf, "filetype", "clojure") | ||
|
||
local lines = {} | ||
if contents then | ||
lines = vim.split(contents, "\n") | ||
end | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) | ||
end | ||
|
||
local function handle_on_move(UI, event) | ||
local node = event.node | ||
local layout = UI.layout | ||
|
||
if node.assertion then | ||
if node.assertion.exception then | ||
UI.layout:render_single() | ||
exceptions.render_exception_to_buf(layout.windows.right.bufnr, node.assertion.exception) | ||
return | ||
end | ||
|
||
layout:render_double() | ||
write_clojure_to_buf(layout.windows.left.bufnr, node.assertion.expected) | ||
write_clojure_to_buf(layout.windows.right.bufnr, node.assertion.actual) | ||
return | ||
end | ||
|
||
if node.exception then | ||
layout:render_single() | ||
exceptions.render_exception_to_buf(layout.windows.right.bufnr, { node.exception }) | ||
return | ||
end | ||
|
||
layout:hide() | ||
end | ||
|
||
function M.create(on_event) | ||
local UI = { | ||
mounted = false, | ||
layout = nil, | ||
tree = nil, | ||
|
||
last_active_window = vim.api.nvim_get_current_win(), | ||
} | ||
|
||
function UI:mount() | ||
if UI.mounted then | ||
return | ||
end | ||
|
||
UI.mounted = true | ||
|
||
UI.layout = layout_api.create(function(event) | ||
if event.type == "on-focus-lost" then | ||
return UI.layout:hide() | ||
end | ||
end) | ||
UI.layout:mount() | ||
|
||
UI.tree = report_tree_api.create(UI.layout.windows.tree, function(event) | ||
if event.type == "hover" then | ||
return handle_on_move(UI, event) | ||
end | ||
|
||
on_event(event) | ||
end) | ||
|
||
for _, chord in ipairs(utils.into_table(config.keys.ui.quit)) do | ||
UI.layout:map("n", chord, function() | ||
UI:unmount() | ||
end, { noremap = true }) | ||
end | ||
end | ||
|
||
function UI:unmount() | ||
if not UI.mounted then | ||
return | ||
end | ||
|
||
UI.mounted = false | ||
UI.layout:unmount() | ||
UI.layout = nil | ||
UI.tree = nil | ||
|
||
vim.api.nvim_set_current_win(UI.last_active_window) | ||
end | ||
|
||
function UI:navigate_back() | ||
-- UI.layout:hide() | ||
vim.api.nvim_set_current_win(UI.last_active_window) | ||
end | ||
|
||
function UI:render_reports(reports) | ||
UI.tree:render_reports(reports) | ||
end | ||
|
||
function UI:render_exceptions(exception_chain) end | ||
|
||
function UI:on() end | ||
|
||
return UI | ||
end | ||
|
||
return M |
Oops, something went wrong.