Skip to content

fix: rename range rule's row to line#1664

Merged
HerringtonDarkholme merged 2 commits intomainfrom
fix-range-rule
Dec 14, 2024
Merged

fix: rename range rule's row to line#1664
HerringtonDarkholme merged 2 commits intomainfrom
fix-range-rule

Conversation

@HerringtonDarkholme
Copy link
Copy Markdown
Member

@HerringtonDarkholme HerringtonDarkholme commented Dec 14, 2024

BREAKING CHANGE: fix #1663
There is an inconsistency between the use of line and row in the ast-grep node's API and rule parameters. The node uses line, while the rule uses row, which may lead to confusion.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new macro for handling differences in the cloud printing functionality.
    • Enhanced error handling in the interactive printing process for improved feedback during file operations.
  • Improvements

    • Standardized line number retrieval across various components for consistency.
    • Added a new field for metadata in the JSON output structure to enhance match context.
    • Improved clarity in test cases by updating range specifications from "row" to "line".
  • Bug Fixes

    • Enhanced handling of diagnostic codes to prevent potential errors during code action generation.
    • Updated the JSON schema to reflect changes in terminology from "row" to "line" for better clarity.

BREAKING CHANGE: fix #1663
There is an inconsistency between the use of line and row in the ast-grep node's API and rule parameters.
The node uses line, while the rule uses row, which may lead to confusion.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 14, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request addresses an inconsistency in terminology across the ast-grep codebase, systematically replacing row with line in multiple files and interfaces. This comprehensive refactoring spans various components including core node representation, configuration handling, printing mechanisms, and language bindings (Python, TypeScript). The changes ensure consistent use of the term "line" when referring to line numbers, improving code clarity and reducing potential confusion for developers using the library.

Changes

File Change Summary
crates/core/src/node.rs Renamed row to line in Position struct and related methods
crates/config/src/rule/range.rs Updated SerializablePosition to use line instead of row
crates/cli/src/print/* Modified line number retrieval across multiple printing modules
crates/napi/manual.d.ts Updated Position interface to use line
crates/pyo3/ast_grep_py/__init__.py Renamed row to line in PosRule

Assessment against linked issues

Objective Addressed Explanation
Resolve inconsistent naming between line and row
Standardize node interface terminology

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Line Numbers

From row to line, we hop with glee,
Consistency is key, you see!
No more confusion, no more strife,
Our code now sings a clearer life!
🌈 Refactoring with bunny might!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ddf05c5 and 00dd245.

📒 Files selected for processing (1)
  • schemas/rule.json (2 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
crates/pyo3/tests/test_rule.py (1)

156-157: LGTM! Test cases updated to use new terminology.

The test cases have been updated to use "line" instead of "row" consistently. However, we could enhance the test coverage.

Consider adding a test case that explicitly verifies the behavior when using the old "row" key to ensure it fails appropriately, helping users identify the breaking change:

def test_deprecated_row_key():
    with pytest.raises(ValueError, match="'row' is no longer supported, use 'line' instead"):
        root.find(range={
            "start": {"row": 0, "column": 9},
            "end": {"row": 0, "column": 13},
        })

Also applies to: 162-163

crates/napi/__test__/index.spec.ts (1)

390-391: LGTM! Updated range test to use new line terminology

The test case correctly uses the new line property instead of row.

Consider adding additional test cases to verify edge cases:

// Test negative line numbers
{
  start: { line: -1, column: 0 },
  end: { line: 0, column: 0 }
}
// Test out of bounds line numbers
{
  start: { line: 999999, column: 0 },
  end: { line: 999999, column: 1 }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bfd4945 and ddf05c5.

📒 Files selected for processing (16)
  • crates/cli/src/print/cloud_print.rs (1 hunks)
  • crates/cli/src/print/colored_print.rs (2 hunks)
  • crates/cli/src/print/interactive_print.rs (3 hunks)
  • crates/cli/src/print/json_print.rs (1 hunks)
  • crates/config/src/combined.rs (2 hunks)
  • crates/config/src/rule/range.rs (9 hunks)
  • crates/core/src/node.rs (5 hunks)
  • crates/lsp/src/utils.rs (1 hunks)
  • crates/napi/__test__/index.spec.ts (1 hunks)
  • crates/napi/index.d.ts (1 hunks)
  • crates/napi/manual.d.ts (1 hunks)
  • crates/napi/src/sg_node.rs (1 hunks)
  • crates/pyo3/ast_grep_py/__init__.py (1 hunks)
  • crates/pyo3/src/range.rs (1 hunks)
  • crates/pyo3/tests/test_range.py (1 hunks)
  • crates/pyo3/tests/test_rule.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/napi/index.d.ts
🔇 Additional comments (17)
crates/cli/src/print/json_print.rs (1)

149-149: Update to line() method for position retrieval

Changed pos.row() to pos.line() to ensure consistency with the updated terminology across the codebase.

Also applies to: 153-153

crates/pyo3/tests/test_range.py (1)

57-57: Update range keys from row to line

Modified the range parameter to use "line" instead of "row", aligning with the updated API specification.

crates/pyo3/ast_grep_py/__init__.py (1)

19-19: Rename attribute row to line in PosRule

Updated the PosRule class attribute from row to line to standardize terminology across the codebase.

Ensure that all references to PosRule.row have been updated to PosRule.line throughout the codebase.

Run the following script to verify:

✅ Verification successful

Attribute rename from row to line in PosRule has been properly implemented

The verification shows that:

  • The old attribute row existed in a previous commit (bfd4945)
  • The current implementation correctly uses line instead of row
  • No remaining references to PosRule.row exist in the codebase
  • The change appears to be consistently applied as PosRule is only used in __init__.py for type definitions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find any usages of 'PosRule.row' in the codebase.

# Test: Search for 'PosRule.row' references. Expect: No results.
rg 'PosRule\.row\b'

Length of output: 21


Script:

#!/bin/bash
# Let's first verify if PosRule exists and check its current implementation
ast-grep --pattern 'class PosRule'

# Also search for any references to PosRule to understand its usage
rg 'PosRule' -A 2

Length of output: 448


Script:

#!/bin/bash
# Let's check the git history to see if there was a recent change from 'row' to 'line'
git log -p --grep="row" -- crates/pyo3/ast_grep_py/__init__.py

# Also let's check for any historical references to 'row' in this file
git grep 'row' $(git rev-list --all) -- crates/pyo3/ast_grep_py/__init__.py

Length of output: 247

crates/lsp/src/utils.rs (1)

64-64: LGTM! Method calls updated consistently.

The change from row() to line() is applied consistently while preserving the type conversion to u32.

Also applies to: 68-68

crates/config/src/rule/range.rs (1)

8-9: LGTM! Documentation and field name updated consistently.

The renaming from row to line has been properly implemented, with documentation updated to reflect the change.

crates/cli/src/print/cloud_print.rs (2)

97-98: LGTM! Method calls updated consistently.

The change from row() to line() is consistent with the PR objectives and maintains the same functionality.


Line range hint 20-23: LGTM! New macro follows existing patterns.

The Diffs! macro is implemented consistently with the existing Matches! macro pattern.

crates/config/src/combined.rs (2)

Line range hint 21-27: LGTM! Suppression line calculation updated consistently.

The change from row() to line() is properly implemented in the suppression collection logic, maintaining the same functionality.


Line range hint 42-46: LGTM! Suppression checking updated consistently.

The change from row() to line() is properly implemented in the suppression checking logic.

crates/cli/src/print/interactive_print.rs (1)

85-85: LGTM! Consistent renaming from row() to line()

The changes align with the PR objective of standardizing terminology from "row" to "line". The modifications maintain the same functionality while improving API consistency.

Let's verify that all occurrences of row() have been replaced:

Also applies to: 177-177, 196-196

✅ Verification successful

Remaining row() calls are from tree-sitter's API and should not be changed

The remaining row() calls are from the tree-sitter library's Point type (tree_sitter::Point), which is an external API that we cannot modify. These occurrences are different from our internal API changes:

  • In debug_query.rs: Converting from tree-sitter's Point which uses row()
  • In node.rs: Working directly with tree-sitter's position API

Our internal API standardization to line() is complete and correct, while these remaining row() calls should stay as they are to maintain compatibility with the tree-sitter library.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of row() method calls
# Expect: No matches as all should be renamed to line()

rg "\.row\(\)" 

Length of output: 219


Script:

#!/bin/bash
# Let's check the context of these remaining row() calls to understand if they need to be updated

# Check debug_query.rs
echo "=== debug_query.rs ==="
rg -B 2 -A 2 "\.row\(\)" crates/cli/src/utils/debug_query.rs

# Check node.rs
echo -e "\n=== node.rs ==="
rg -B 2 -A 2 "\.row\(\)" crates/core/src/node.rs

# Let's also check if there are any line() methods in these files
# to see if there's an ongoing pattern of conversion
echo -e "\n=== Checking line() usage in the same files ==="
rg "\.line\(\)" crates/cli/src/utils/debug_query.rs crates/core/src/node.rs

Length of output: 1254


Script:

#!/bin/bash
# Let's check the tree-sitter API documentation by looking at imports and type definitions
# to understand if these are different APIs

# Check tree-sitter imports and types
echo "=== Checking tree-sitter imports ==="
rg "use tree_sitter" -A 3 crates/cli/src/utils/debug_query.rs crates/core/src/node.rs

# Check Point type usage and definition
echo -e "\n=== Checking Point type usage ==="
rg "Point" -B 1 -A 1 crates/cli/src/utils/debug_query.rs crates/core/src/node.rs

Length of output: 1472

crates/napi/src/sg_node.rs (1)

45-45: LGTM! Updated position conversion to use line()

The change correctly updates the position conversion to use line() instead of row(), maintaining consistency with the new terminology.

crates/cli/src/print/colored_print.rs (1)

270-270: LGTM: Consistent terminology change from row to line.

The changes correctly replace row() with line() in the MatchMerger struct, maintaining the same functionality while standardizing terminology.

Let's verify no instances of row remain in this file:

Also applies to: 299-299

✅ Verification successful

Terminology change from row to line is complete and consistent

The verification confirms that there are no remaining instances of row or row() in the file crates/cli/src/print/colored_print.rs. While row terminology exists in other parts of the codebase, they are in different components and contexts, not related to this specific change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of 'row' that might need updating
rg '\brow\b' --type rust

Length of output: 654


Script:

#!/bin/bash
# Let's check the specific file mentioned in the review comment for any 'row' instances
rg '\brow\b' 'crates/cli/src/print/colored_print.rs'

# Also let's check for any remaining instances of 'row()' method calls
rg '\.row\(\)' 'crates/cli/src/print/colored_print.rs'

Length of output: 107

crates/core/src/node.rs (5)

13-13: Documentation correctly updated to use "line" terminology.

The documentation has been properly updated to reflect the terminology change from "row" to "line".

Also applies to: 18-19


27-27: Constructor and accessor methods updated consistently.

The Position struct's constructor and accessor methods have been updated to use "line" terminology consistently:

  • Constructor parameter renamed from row to line
  • Field renamed from row to line
  • Accessor method renamed from row() to line()

Also applies to: 29-35


44-44: Tree-sitter Point conversion updated.

The ts_point method has been updated to use the line field instead of row.


293-293: Display context calculation updated.

The DisplayContext struct's start_line calculation has been updated to use line() instead of row().


18-19: Verify impact of breaking changes.

This is a breaking change that renames the public API from row to line. While the changes look correct, we should verify the impact on dependent code.

Let's check for any external usage of the old row API:

Also applies to: 27-27, 34-35

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 14, 2024

Codecov Report

Attention: Patch coverage is 91.37931% with 5 lines in your changes missing coverage. Please review.

Project coverage is 87.13%. Comparing base (bfd4945) to head (00dd245).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/cli/src/print/interactive_print.rs 0.00% 3 Missing ⚠️
crates/lsp/src/utils.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1664      +/-   ##
==========================================
+ Coverage   87.11%   87.13%   +0.01%     
==========================================
  Files          96       96              
  Lines       15458    15476      +18     
==========================================
+ Hits        13467    13485      +18     
  Misses       1991     1991              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HerringtonDarkholme HerringtonDarkholme added this pull request to the merge queue Dec 14, 2024
Merged via the queue into main with commit ad8fd0e Dec 14, 2024
@HerringtonDarkholme HerringtonDarkholme deleted the fix-range-rule branch December 14, 2024 21:38
@coderabbitai coderabbitai bot mentioned this pull request Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent naming: 'line' vs 'row' in ast-grep node's interface and rule

1 participant