-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: improve center_block_and_cursor function to correctly center code blocks for PHP files #12
Closed
Conversation
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
…the file - Calculate middle line of code block - Adjust middle line to assure within bounds of buffer - If 'keep_cursor_position' enabled, saves current cursor position - Move cursor to the middle line of code block and center view - Restore original cursor position or adjust if too close to end of file - Ensure cursor does not move beyond end of file when centering block
…ndling - Enhanced the `center_block_and_cursor` function to correctly center code blocks in PHP files. - Added detailed debug output to the function to help identify and troubleshoot issues with node identification. - Improved the `get_expand_root` function by encapsulating node identification logic in the `is_significant_block` function. - Ensured the `is_significant_block` function correctly identifies significant nodes (functions, methods, classes) and includes debug output for node types. - Distributed functions across multiple classes in the PHP test file to provide better test coverage for the centering logic. - Updated the `repro.lua` configuration to ensure proper loading of the local development version of `typewriter.nvim` and Treesitter settings. - Addressed edge cases near the bottom of the file to ensure the cursor does not move beyond the end of the file when centering the block. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files.
…ndling - Enhanced the `center_block_and_cursor` function to correctly center code blocks in PHP files. - Integrated the `center_block_config` module to determine significant nodes for centering. - Updated `is_significant_block` function to use the configuration from `center_block_config`. - Added detailed debug output to help identify and troubleshoot issues with node identification. - Improved the `get_expand_root` function by using `is_significant_block` for node identification. - Distributed functions across multiple classes in the PHP test file to provide better test coverage for the centering logic. - Updated the `repro.lua` configuration to ensure proper loading of the local development version of `typewriter.nvim` and Treesitter settings. - Ensured that the cursor does not move beyond the end of the file when centering the block. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files.
- Enhanced the `get_expand_root` function to stop traversing up the syntax tree when reaching high-level nodes such as `class_declaration` or `program`. - Integrated the `center_block_config` module to accurately determine significant nodes for centering. - Updated the `is_significant_block` function to use the configuration from `center_block_config` for identifying significant nodes. - Added detailed debug output to the `get_expand_root` and `center_block_and_cursor` functions to help identify and troubleshoot issues with node identification. - Ensured the function correctly identifies and centers code blocks within methods and function blocks, avoiding overly broad nodes. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files, by ensuring the correct code block is centered.
For improved node traversal
Added 'compound_statement' and 'method_declaration' nodes
Added 'class_declaration' node
…the file - Calculate middle line of code block - Adjust middle line to assure within bounds of buffer - If 'keep_cursor_position' enabled, saves current cursor position - Move cursor to the middle line of code block and center view - Restore original cursor position or adjust if too close to end of file - Ensure cursor does not move beyond end of file when centering block
…ndling - Enhanced the `center_block_and_cursor` function to correctly center code blocks in PHP files. - Added detailed debug output to the function to help identify and troubleshoot issues with node identification. - Improved the `get_expand_root` function by encapsulating node identification logic in the `is_significant_block` function. - Ensured the `is_significant_block` function correctly identifies significant nodes (functions, methods, classes) and includes debug output for node types. - Distributed functions across multiple classes in the PHP test file to provide better test coverage for the centering logic. - Updated the `repro.lua` configuration to ensure proper loading of the local development version of `typewriter.nvim` and Treesitter settings. - Addressed edge cases near the bottom of the file to ensure the cursor does not move beyond the end of the file when centering the block. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files.
…ndling - Enhanced the `center_block_and_cursor` function to correctly center code blocks in PHP files. - Integrated the `center_block_config` module to determine significant nodes for centering. - Updated `is_significant_block` function to use the configuration from `center_block_config`. - Added detailed debug output to help identify and troubleshoot issues with node identification. - Improved the `get_expand_root` function by using `is_significant_block` for node identification. - Distributed functions across multiple classes in the PHP test file to provide better test coverage for the centering logic. - Updated the `repro.lua` configuration to ensure proper loading of the local development version of `typewriter.nvim` and Treesitter settings. - Ensured that the cursor does not move beyond the end of the file when centering the block. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files.
- Enhanced the `get_expand_root` function to stop traversing up the syntax tree when reaching high-level nodes such as `class_declaration` or `program`. - Integrated the `center_block_config` module to accurately determine significant nodes for centering. - Updated the `is_significant_block` function to use the configuration from `center_block_config` for identifying significant nodes. - Added detailed debug output to the `get_expand_root` and `center_block_and_cursor` functions to help identify and troubleshoot issues with node identification. - Ensured the function correctly identifies and centers code blocks within methods and function blocks, avoiding overly broad nodes. These changes enhance the functionality and reliability of the `:TWCenter` command in Neovim, particularly for PHP files, by ensuring the correct code block is centered.
For improved node traversal
Added 'compound_statement' and 'method_declaration' nodes
Added 'class_declaration' node
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This pull request addresses the issue reported in #9, where the
:TWCenter
command centers the current line instead of the entire code block, particularly in PHP files.Summary of Changes:
Enhanced
center_block_and_cursor
Function:Updated
get_expand_root
Function:center_block_config
to accurately determine significant nodes for centering.Refactored
is_significant_block
Function:center_block_config
for comprehensive identification of significant nodes.Added New Node Types:
declaration_list
and other relevant nodes incenter_block_config
to ensure all significant blocks are considered.Removed Debug Print Statements:
Commits:
center_block_and_cursor
function for better PHP block handling.center_block_and_cursor
function for better PHP block handling.get_expand_root
logic for better PHP block handling.declaration_list
to node list.CHANGELOG.md
for v0.4.24 and remove duplicate entries.Files Changed:
Contributors:
Related Issues:
Testing:
:TWCenter
command now correctly centers the entire code block in PHP files.This pull request improves the reliability and functionality of the
:TWCenter
command in Neovim, particularly for PHP files, ensuring that the correct code block is centered as intended.