Skip to content

Conversation

@marlon-costa-dc
Copy link

Summary

This PR adds complete Kotlin language support to rust-code-analysis, including all code metrics, along with upgrading tree-sitter to version 0.26.3 and updating related dependencies.

Kotlin Language Support

Implemented all metrics for Kotlin:

  • LOC (Lines of Code) - logical, source, comments, blank lines
  • Cyclomatic Complexity - control flow complexity measurement
  • Cognitive Complexity - human-understandable complexity metric
  • Halstead Metrics - vocabulary, volume, difficulty, effort
  • ABC Metric - Assignment, Branch, Condition metric
  • NPA (Number of Public Attributes)
  • NPM (Number of Public Methods)
  • WMC (Weighted Methods per Class)
  • NARGS (Number of Arguments)
  • NOM (Number of Methods)
  • Exit Points

Uses tree-sitter-kotlin-codanna (0.3.9) which provides tree-sitter 0.26.3 compatibility.

Dependency Updates

Package Previous Updated
tree-sitter 0.25.3 0.26.3
tree-sitter-javascript 0.23.1 0.25.0
tree-sitter-python 0.23.6 0.25.0
tree-sitter-rust 0.23.2 0.24.0
askama (enums) 0.14 0.15
insta (dev) 1.29.0 1.46.1

Internal Grammar Updates

Updated all internal grammars to tree-sitter 0.26.3:

  • tree-sitter-ccomment
  • tree-sitter-preproc
  • tree-sitter-mozcpp
  • tree-sitter-mozjs

Test Plan

  • All existing tests pass
  • Compilation check passes
  • Clippy passes
  • Full test suite verification
  • Manual verification of Kotlin metrics on sample files

Breaking Changes

None. This is an additive change with backward-compatible dependency updates.

Related Issues

Closes the need for Kotlin support in rust-code-analysis.
Addresses multiple dependabot PRs: #1200, #1201, #1202, #1203, #1204, #1205, #1184, #1185, #1186, #1192, #1193, #1150, #1152

Luni-4 and others added 30 commits May 5, 2025 15:09
Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases)
- [Commits](tree-sitter/tree-sitter-javascript@v0.23.1...v0.25.0)

---
updated-dependencies:
- dependency-name: tree-sitter-javascript
  dependency-version: 0.25.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases)
- [Commits](tree-sitter/tree-sitter-javascript@v0.23.1...v0.25.0)

---
updated-dependencies:
- dependency-name: tree-sitter-javascript
  dependency-version: 0.25.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter-javascript/releases)
- [Commits](tree-sitter/tree-sitter-javascript@v0.23.1...v0.25.0)

---
updated-dependencies:
- dependency-name: tree-sitter-javascript
  dependency-version: 0.25.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter-python/releases)
- [Commits](tree-sitter/tree-sitter-python@v0.23.6...v0.25.0)

---
updated-dependencies:
- dependency-name: tree-sitter-python
  dependency-version: 0.25.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter-python/releases)
- [Commits](tree-sitter/tree-sitter-python@v0.23.6...v0.25.0)

---
updated-dependencies:
- dependency-name: tree-sitter-python
  dependency-version: 0.25.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter/releases)
- [Commits](tree-sitter/tree-sitter@v0.25.3...v0.26.3)

---
updated-dependencies:
- dependency-name: tree-sitter
  dependency-version: 0.26.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter/releases)
- [Commits](tree-sitter/tree-sitter@v0.25.3...v0.26.3)

---
updated-dependencies:
- dependency-name: tree-sitter
  dependency-version: 0.26.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter/releases)
- [Commits](tree-sitter/tree-sitter@v0.25.3...v0.26.3)

---
updated-dependencies:
- dependency-name: tree-sitter
  dependency-version: 0.26.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Updates the requirements on [tree-sitter](https://github.com/tree-sitter/tree-sitter) to permit the latest version.
- [Release notes](https://github.com/tree-sitter/tree-sitter/releases)
- [Commits](tree-sitter/tree-sitter@v0.25.3...v0.26.3)

---
updated-dependencies:
- dependency-name: tree-sitter
  dependency-version: 0.26.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Marlon Costa added 13 commits January 19, 2026 12:48
…mment/tree-sitter-eq-0.26.3' into tree-sitter-0.26-kotlin
…er-eq-0.26.3' into tree-sitter-0.26-kotlin
…proc/tree-sitter-eq-0.26.3' into tree-sitter-0.26-kotlin
…cpp/tree-sitter-eq-0.26.3' into tree-sitter-0.26-kotlin
…js/tree-sitter-eq-0.26.3' into tree-sitter-0.26-kotlin
…lity

- Replace tree-sitter-kotlin-ng with tree-sitter-kotlin-codanna (0.3.9)
- tree-sitter-kotlin-codanna is compatible with tree-sitter 0.26.3
- Update Kotlin node type mappings:
  - Comment -> LineComment | MultilineComment
  - LineStringLiteral/MultiLineStringLiteral -> StringLiteral | StringContent
- Fix tree-sitter 0.26 API changes:
  - Node.child() now takes u32 instead of usize
- Add special case for kotlin grammar's language() function (vs LANGUAGE constant)
- Fix FxHashMap -> HashMap import
- Add Makefile for build commands

All 251 tests passing + 17 doc tests.
- tree-sitter-rust: 0.23.2 → 0.24.0
- insta: 1.29.0 → 1.46.1
- Add .claude/ to .gitignore
Copilot AI review requested due to automatic review settings January 19, 2026 16:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive Kotlin language support to rust-code-analysis with all available code metrics, while also upgrading the tree-sitter dependency from 0.25.3 to 0.26.3. The implementation switches from tree-sitter-kotlin-ng to tree-sitter-kotlin-codanna for better compatibility with the new tree-sitter version.

Changes:

  • Complete Kotlin language support with all 11 metrics (LOC, Cyclomatic, Cognitive, Halstead, ABC, WMC, NPA, NPM, NARGS, Exit, NOM)
  • Tree-sitter core upgrade from 0.25.3 to 0.26.3 with corresponding API adjustments (Node lifetimes, child indexing)
  • Updated language parsers (JavaScript 0.25.0, Python 0.25.0, Rust 0.24.0) and dev dependencies (insta 1.46.1, askama 0.15)

Reviewed changes

Copilot reviewed 29 out of 30 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Cargo.toml Updates tree-sitter to 0.26.3, switches to tree-sitter-kotlin-codanna, updates parser dependencies
enums/Cargo.toml Mirrors main dependency updates for enum generation
src/languages/language_kotlin.rs Complete rewrite of Kotlin grammar enum definitions for new tree-sitter grammar
src/checker.rs Implements Checker trait for Kotlin (comments, functions, closures, strings, else-if detection)
src/getter.rs Implements Getter trait for Kotlin (space kinds, Halstead operators/operands)
src/metrics/*.rs Implements all metrics (LOC, Cyclomatic, Cognitive, Halstead, ABC, WMC, NPA, NPM, NARGS, Exit)
src/node.rs Adds Node lifetime annotations and u32 child indexing for tree-sitter 0.26.3, adds traverse_children helper
src/traits.rs Updates get_root return type with lifetime annotation
src/parser.rs Updates get_root return type with lifetime annotation
src/tools.rs Minor refactoring removing unnecessary parentheses
src/asttools.rs New file with unused utility functions (dead code - not imported in lib.rs)
tree-sitter-*/Cargo.toml Updates internal grammars to tree-sitter 0.26.3
src/macros.rs Adds special case for tree-sitter-kotlin-codanna grammar accessor
Makefile Adds convenience build/test/check targets
.gitignore Adds .claude/ directory to ignore list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Marlon Costa added 5 commits January 19, 2026 14:04
- npa.rs: Fix typo "interfaces" → "interface" in comment
- npm.rs: Fix typo "interfaces" → "interface" in comment
- cognitive.rs: Add missing space after comma in increase_nesting calls
- abc.rs: Update Java grammar references to Kotlin grammar in comments
- abc.rs: Fix typo "do-while statements" → "inside do-while statements"
@marlon-costa-dc
Copy link
Author

Addressed Review Comments

All 6 Copilot review comments have been resolved in commit a44288d:

File Issue Resolution
src/metrics/npa.rs:281 Typo "interfaces" ✅ Changed to "interface"
src/metrics/npm.rs:272 Typo "interfaces" ✅ Changed to "interface"
src/metrics/cognitive.rs Missing space after comma (9 occurrences) ✅ Fixed all increase_nesting(stats,&mutincrease_nesting(stats, &mut
src/metrics/abc.rs:585-586 Java grammar URLs in Kotlin code ✅ Updated to Kotlin grammar reference (2 occurrences)
src/metrics/abc.rs:443,709 Comment typo "do-while statements" ✅ Fixed to "inside do-while statements"
src/asttools.rs Dead code (not imported in lib.rs) ✅ Now properly exported in lib.rs:88-89 with pub mod asttools and re-exports

All changes have been pushed to the tree-sitter-0.26-kotlin branch.

Collapse nested if statements into single conditions using Rust's
if-let chain syntax (let-chains). This modernizes the codebase to
use the newer Rust idiom and satisfies clippy's collapsible_if lint.

Files fixed:
- src/alterator.rs
- src/asttools.rs
- src/checker.rs
- src/find.rs
- src/getter.rs
- src/metrics/abc.rs
- src/metrics/cognitive.rs
- src/metrics/loc.rs
- src/metrics/nargs.rs
- src/node.rs
@marlon-costa-dc
Copy link
Author

Additional Fix: Clippy Warnings

Fixed all clippy::collapsible_if warnings in commit 30d2228:

Converted nested if let statements to use Rust's let-chains syntax across 10 files:

  • src/alterator.rs
  • src/asttools.rs
  • src/checker.rs
  • src/find.rs
  • src/getter.rs
  • src/metrics/abc.rs
  • src/metrics/cognitive.rs
  • src/metrics/loc.rs
  • src/metrics/nargs.rs
  • src/node.rs

All cargo clippy --all-targets --all-features -- -D warnings checks now pass locally.

Marlon Costa added 2 commits January 19, 2026 14:41
Update all language enum files using the enums generator to match
the upgraded tree-sitter grammar versions:
- tree-sitter-rust 0.24.0
- tree-sitter-javascript 0.25.0
- tree-sitter-python 0.25.0
- tree-sitter-kotlin-codanna 0.3.9

Update test snapshots to reflect changes in grammar parsing
behavior across Python and JavaScript metrics tests.
@marlon-costa-dc
Copy link
Author

Update: Enums Regenerated for tree-sitter 0.26.3

All language enum files have been regenerated using the enums generator to match upgraded tree-sitter grammar versions:

  • tree-sitter-rust 0.24.0
  • tree-sitter-javascript 0.25.0
  • tree-sitter-python 0.25.0
  • tree-sitter-kotlin-codanna 0.3.9
  • tree-sitter core 0.26.3

Test snapshots have been updated to reflect changes in grammar parsing behavior. All tests passing.

Validation results:

  • ✅ Compilation - passes
  • ✅ Clippy - passes
  • ✅ Tests - 253 tests pass (17 doctests + 236 unit tests)

Commit: ecafc19

@Luni-4
Copy link
Collaborator

Luni-4 commented Jan 19, 2026

@marlon-costa-dc

Thanks a lot for your hard work! If it’s not too much trouble, could you move the dependency updates and the CI changes into separate PRs? Once those PRs are merged, could you then rebase this one?

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.

2 participants