feat: clearcol
This commit is contained in:
parent
114187164e
commit
13933fc7fd
6 changed files with 40 additions and 1 deletions
|
|
@ -56,6 +56,7 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
|
local helpers = require('cp.helpers')
|
||||||
local utils = require('cp.utils')
|
local utils = require('cp.utils')
|
||||||
|
|
||||||
-- defaults per the new single schema
|
-- defaults per the new single schema
|
||||||
|
|
@ -103,7 +104,13 @@ M.defaults = {
|
||||||
default_language = 'cpp',
|
default_language = 'cpp',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hooks = { before_run = nil, before_debug = nil, setup_code = nil },
|
hooks = {
|
||||||
|
before_run = nil,
|
||||||
|
before_debug = nil,
|
||||||
|
setup_code = nil,
|
||||||
|
setup_io_input = helpers.clearcol,
|
||||||
|
setup_io_output = helpers.clearcol,
|
||||||
|
},
|
||||||
debug = false,
|
debug = false,
|
||||||
scrapers = constants.PLATFORMS,
|
scrapers = constants.PLATFORMS,
|
||||||
filename = nil,
|
filename = nil,
|
||||||
|
|
@ -231,6 +238,8 @@ function M.setup(user_config)
|
||||||
before_run = { cfg.hooks.before_run, { 'function', 'nil' }, true },
|
before_run = { cfg.hooks.before_run, { 'function', 'nil' }, true },
|
||||||
before_debug = { cfg.hooks.before_debug, { 'function', 'nil' }, true },
|
before_debug = { cfg.hooks.before_debug, { 'function', 'nil' }, true },
|
||||||
setup_code = { cfg.hooks.setup_code, { 'function', 'nil' }, true },
|
setup_code = { cfg.hooks.setup_code, { 'function', 'nil' }, true },
|
||||||
|
setup_io_input = { cfg.hooks.setup_io_input, { 'function', 'nil' }, true },
|
||||||
|
setup_io_output = { cfg.hooks.setup_io_output, { 'function', 'nil' }, true },
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.validate({
|
vim.validate({
|
||||||
|
|
|
||||||
11
lua/cp/helpers.lua
Normal file
11
lua/cp/helpers.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
function M.clearcol(bufnr)
|
||||||
|
vim.bo[bufnr].signcolumn = 'no'
|
||||||
|
vim.bo[bufnr].statuscolumn = ''
|
||||||
|
vim.bo[bufnr].number = false
|
||||||
|
vim.bo[bufnr].relativenumber = false
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local config_module = require('cp.config')
|
local config_module = require('cp.config')
|
||||||
|
local helpers = require('cp.helpers')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
|
|
||||||
|
M.helpers = helpers
|
||||||
|
|
||||||
if vim.fn.has('nvim-0.10.0') == 0 then
|
if vim.fn.has('nvim-0.10.0') == 0 then
|
||||||
logger.log('Requires nvim-0.10.0+', vim.log.levels.ERROR)
|
logger.log('Requires nvim-0.10.0+', vim.log.levels.ERROR)
|
||||||
return {}
|
return {}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ local M = {}
|
||||||
local cache = require('cp.cache')
|
local cache = require('cp.cache')
|
||||||
local config_module = require('cp.config')
|
local config_module = require('cp.config')
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
|
local helpers = require('cp.helpers')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local scraper = require('cp.scraper')
|
local scraper = require('cp.scraper')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
@ -178,6 +179,9 @@ function M.setup_problem(problem_id, language)
|
||||||
if ok then
|
if ok then
|
||||||
vim.b[prov.bufnr].cp_setup_done = true
|
vim.b[prov.bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
|
elseif not vim.b[prov.bufnr].cp_setup_done then
|
||||||
|
helpers.clearcol(prov.bufnr)
|
||||||
|
vim.b[prov.bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
cache.set_file_state(
|
cache.set_file_state(
|
||||||
vim.fn.fnamemodify(source_file, ':p'),
|
vim.fn.fnamemodify(source_file, ':p'),
|
||||||
|
|
@ -202,6 +206,9 @@ function M.setup_problem(problem_id, language)
|
||||||
if ok then
|
if ok then
|
||||||
vim.b[bufnr].cp_setup_done = true
|
vim.b[bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
|
elseif not vim.b[bufnr].cp_setup_done then
|
||||||
|
helpers.clearcol(bufnr)
|
||||||
|
vim.b[bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
cache.set_file_state(
|
cache.set_file_state(
|
||||||
vim.fn.expand('%:p'),
|
vim.fn.expand('%:p'),
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local helpers = require('cp.helpers')
|
||||||
local utils = require('cp.utils')
|
local utils = require('cp.utils')
|
||||||
|
|
||||||
local function create_none_diff_layout(parent_win, expected_content, actual_content)
|
local function create_none_diff_layout(parent_win, expected_content, actual_content)
|
||||||
local expected_buf = utils.create_buffer_with_options()
|
local expected_buf = utils.create_buffer_with_options()
|
||||||
local actual_buf = utils.create_buffer_with_options()
|
local actual_buf = utils.create_buffer_with_options()
|
||||||
|
helpers.clearcol(expected_buf)
|
||||||
|
helpers.clearcol(actual_buf)
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(parent_win)
|
vim.api.nvim_set_current_win(parent_win)
|
||||||
vim.cmd.split()
|
vim.cmd.split()
|
||||||
|
|
@ -42,6 +45,8 @@ end
|
||||||
local function create_vim_diff_layout(parent_win, expected_content, actual_content)
|
local function create_vim_diff_layout(parent_win, expected_content, actual_content)
|
||||||
local expected_buf = utils.create_buffer_with_options()
|
local expected_buf = utils.create_buffer_with_options()
|
||||||
local actual_buf = utils.create_buffer_with_options()
|
local actual_buf = utils.create_buffer_with_options()
|
||||||
|
helpers.clearcol(expected_buf)
|
||||||
|
helpers.clearcol(actual_buf)
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(parent_win)
|
vim.api.nvim_set_current_win(parent_win)
|
||||||
vim.cmd.split()
|
vim.cmd.split()
|
||||||
|
|
@ -89,6 +94,7 @@ end
|
||||||
|
|
||||||
local function create_git_diff_layout(parent_win, expected_content, actual_content)
|
local function create_git_diff_layout(parent_win, expected_content, actual_content)
|
||||||
local diff_buf = utils.create_buffer_with_options()
|
local diff_buf = utils.create_buffer_with_options()
|
||||||
|
helpers.clearcol(diff_buf)
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(parent_win)
|
vim.api.nvim_set_current_win(parent_win)
|
||||||
vim.cmd.split()
|
vim.cmd.split()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ local M = {}
|
||||||
local cache = require('cp.cache')
|
local cache = require('cp.cache')
|
||||||
local config_module = require('cp.config')
|
local config_module = require('cp.config')
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
|
local helpers = require('cp.helpers')
|
||||||
local layouts = require('cp.ui.layouts')
|
local layouts = require('cp.ui.layouts')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
@ -262,6 +263,7 @@ function M.ensure_io_view()
|
||||||
if config.hooks and config.hooks.setup_io_output then
|
if config.hooks and config.hooks.setup_io_output then
|
||||||
pcall(config.hooks.setup_io_output, output_buf, state)
|
pcall(config.hooks.setup_io_output, output_buf, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.hooks and config.hooks.setup_io_input then
|
if config.hooks and config.hooks.setup_io_input then
|
||||||
pcall(config.hooks.setup_io_input, input_buf, state)
|
pcall(config.hooks.setup_io_input, input_buf, state)
|
||||||
end
|
end
|
||||||
|
|
@ -440,6 +442,7 @@ function M.toggle_panel(panel_opts)
|
||||||
vim.cmd('silent only')
|
vim.cmd('silent only')
|
||||||
|
|
||||||
local tab_buf = utils.create_buffer_with_options()
|
local tab_buf = utils.create_buffer_with_options()
|
||||||
|
helpers.clearcol(tab_buf)
|
||||||
local main_win = vim.api.nvim_get_current_win()
|
local main_win = vim.api.nvim_get_current_win()
|
||||||
vim.api.nvim_win_set_buf(main_win, tab_buf)
|
vim.api.nvim_win_set_buf(main_win, tab_buf)
|
||||||
vim.api.nvim_set_option_value('filetype', 'cp', { buf = tab_buf })
|
vim.api.nvim_set_option_value('filetype', 'cp', { buf = tab_buf })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue