Skip to content

Refactor build_green_tree function to reduce argument count #43

@coderabbitai

Description

@coderabbitai

Problem

The build_green_tree function currently has too many arguments (7 parameters), triggering a clippy warning that requires suppression with #[expect(clippy::too_many_arguments)].

Current Signature

fn build_green_tree(
    tokens: Vec<(SyntaxKind, Span)>,
    src: &str,
    imports: &[Span],
    typedefs: &[Span], 
    relations: &[Span],
    indexes: &[Span],
    functions: &[Span],
    rules: &[Span],
) -> GreenNode

Proposed Solution

Group the related span parameters into a meaningful struct:

struct ParsedSpans {
    imports: Vec<Span>,
    typedefs: Vec<Span>,
    relations: Vec<Span>,
    indexes: Vec<Span>,
    functions: Vec<Span>,
    rules: Vec<Span>,
}

fn build_green_tree(
    tokens: Vec<(SyntaxKind, Span)>,
    src: &str,
    spans: &ParsedSpans,
) -> GreenNode

This approach:

  • Reduces function arguments from 8 to 3
  • Groups related parameters meaningfully
  • Eliminates the need for clippy warning suppression
  • Follows better coding practices for parameter management

Implementation Notes

  • Update all calls to build_green_tree to use the new struct
  • Update parse_tokens function to return the struct instead of a tuple
  • Ensure all span-related operations work with the new structure

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions