Closed Rasmus-Bertell closed 1 month ago
@Rasmus-Bertell Could you share your plugin config?
I'll create a minimal repro config on friday or saturday.
I ask because if you have keep_cursor_position
set to true
, then TWCenter
centers the current line, not the code block. Set keep_cursor_position
to false
, and it'll center the code block
I thought that might have been the problem, but testing it without keep_cursor_position
doesn't work either. I have mostly done the testing with php files so it might also be a problem with those. Trying to center anything in the repro.php-file just results in the line being centered.
Here's a minimal config to reproduce the problem with a php file. (inspired by stevearc repos)
-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify('./.repro', ':p')
-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'runtime', 'cache' }) do
vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end
-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'--single-branch',
'https://github.com/folke/lazy.nvim.git',
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
require('lazy').setup({
{
'joshuadanpeterson/typewriter.nvim',
opts = {},
dependencies = {
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
opts = {
ensure_installed = { 'php' },
},
},
},
},
}, {
root = root .. '/plugins',
})
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Line numbers so it's easier to see how center we are
vim.opt.number = true
vim.opt.relativenumber = true
vim.keymap.set(
'n',
'<leader>tc',
':TWCenter<CR>'
)
<?php
/**
* Save as repro.php
* Run with nvim -u repro.lua repro.php
* Ensure treesitter installed php parser
*/
declare(strict_types=1);
class Example
{
private string $example;
public function __construct(
string $example
) {
if ($example === null) {
throw \InvalidArgumentException(
'$example can\'t be null'
);
}
$this->example = $example;
}
public function Example(): void
{
if (false) {
throw \ErrorException(
'Making these functions'
);
} elseif (true) {
throw \ErrorException(
'longer so we can properly'
);
} elseif (true) {
throw \ErrorException(
'test the TWCenter command'
);
} else {
return;
}
}
}
@Rasmus-Bertell It should be fixed. I had to update a couple of the functions and add several node definitions for the Treesitter integration. Let me know if it works for you
Seems to work better now, but it's still a bit off in my opinion, at least in PHP files. It seems to favor curly braces. Same problem with TWTop
and TWBottom
.
// Doesn't center the method definition with the code block
// Instead centers on the curly braces
public function Example(): void
|--> {
| if (false) {
| throw \ErrorException(
| 'Making these functions'
| );
| } elseif (true) {
| throw \ErrorException(
| 'longer so we can properly'
| );
| } elseif (true) {
| throw \ErrorException(
| 'test the TWCenter command'
| );
| } elseif (true) {
| throw \ErrorException(
| 'test the TWCenter command'
| );
| } else {
| return;
| }
|--> }
Calling TWTop
on the above method results in the definition being off screen, e.g.
{
if (false) {
throw \ErrorException(
'Making these functions'
);
} elseif (true) {
throw \ErrorException(
'longer so we can properly'
);
} elseif (true) {
throw \ErrorException(
'test the TWCenter command'
);
} elseif (true) {
throw \ErrorException(
'test the TWCenter command'
);
} else {
return;
}
}
But this is a minor issue in my opinion, feel free to ignore this if you want.
Fixing it now. Give me a sec
@Rasmus-Bertell Try it now
Seems to work now, thank you.
It might be that I'm not using this plugin right, but when calling
TWCenter
the plugin centers the current line and not the code block as per documentation. I have treesitter installed and parsers installed.