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

fix: improve center_block_and_cursor function to correctly center code blocks for PHP files #12

Closed
wants to merge 23 commits into from

Conversation

joshuadanpeterson
Copy link
Owner

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:

    • Improved logic to correctly identify and center the code block.
    • Added detailed debug output for better troubleshooting of node identification.
    • Ensured edge cases near the bottom of the file are handled correctly.
  • Updated get_expand_root Function:

    • Integrated center_block_config to accurately determine significant nodes for centering.
  • Refactored is_significant_block Function:

    • Leveraged center_block_config for comprehensive identification of significant nodes.
    • Added debug output for better visibility of node types.
  • Added New Node Types:

    • Included declaration_list and other relevant nodes in center_block_config to ensure all significant blocks are considered.
  • Removed Debug Print Statements:

    • Cleaned up code by removing unnecessary debug print statements.

Commits:

  1. feat(commands): Correctly center code block even when near bottom of the file.
  2. fix: Improve center_block_and_cursor function for better PHP block handling.
  3. fix: Improve center_block_and_cursor function for better PHP block handling.
  4. fix: Improve get_expand_root logic for better PHP block handling.
  5. feat(center_block_config): Add declaration_list to node list.
  6. refactor(center_block_and_cursor): Add new nodes.
  7. feat(center_block_config): Add new node.
  8. style(commands): Remove debug print statements.
  9. docs: Update CHANGELOG.md for v0.4.24 and remove duplicate entries.
  10. refactor(commands): Remove 'stop traversal' statement.
  11. merge: Merge branch 'dev' of https://github.com/joshuadanpeterson/typewriter.nvim

Files Changed:

  • CHANGELOG.md: 12 additions, 1 deletion.
  • lua/typewriter/commands.lua: 5 additions, 0 deletions.
  • lua/typewriter/utils/center_block_config.lua: 7 additions, 0 deletions.

Contributors:

Related Issues:

  • Fixes #9

Testing:

  • Verified that the :TWCenter command now correctly centers the entire code block in PHP files.
  • Ensured that the function works as expected with various node types and edge cases.

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.

joshuadanpeterson and others added 11 commits July 19, 2024 15:54
…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.
Added 'compound_statement' and 'method_declaration' nodes
Added 'class_declaration' node
@joshuadanpeterson joshuadanpeterson added the bug Something isn't working label Jul 20, 2024
@joshuadanpeterson joshuadanpeterson self-assigned this Jul 20, 2024
joshuadanpeterson and others added 12 commits July 19, 2024 18:11
…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.
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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TWCenter centers the line, not the code block
2 participants