Skip to content

feat(reference): extract_token_at_cursor を C# lexer 化(Phase 4-C / Refs #191)#194

Merged
akiojin merged 2 commits into
developfrom
work/20260511-0223
May 11, 2026
Merged

feat(reference): extract_token_at_cursor を C# lexer 化(Phase 4-C / Refs #191)#194
akiojin merged 2 commits into
developfrom
work/20260511-0223

Conversation

@akiojin
Copy link
Copy Markdown
Owner

@akiojin akiojin commented May 11, 2026

Summary

Changes

  • src/reference/mod.rs::is_cursor_in_comment_or_string を新設。カーソル位置までの 1 行を scan し、// line comment 内と "..." string literal 内かを判定する。\" エスケープは string を閉じない扱い。
  • extract_token_at_cursor がカーソル位置の class を判定し、comment 内 / string 内なら None を返すように改良。
  • 新規 RED テスト 4 件:
    • extract_token_at_cursor_skips_line_comment
    • extract_token_at_cursor_skips_string_literal
    • extract_token_at_cursor_returns_ident_after_closed_string
    • extract_token_at_cursor_handles_escaped_quote_in_string

Testing

  • cargo fmt -- --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --bin unity-cli386 passed / 0 failed
  • cargo llvm-cov --all-targets --summary-only -- --test-threads=1 — TOTAL line coverage 91.03%
  • unity-cli skills lint --severity error — 15 skills / 0 violations

Closing Issues

Related Issues / Links

Checklist

  • Tests added/updated (4 件)
  • Lint/format passed (cargo clippy, cargo fmt, unity-cli skills lint)
  • Documentation updated — none required (内部実装の改善で公開 API 変更なし)
  • Migration/backfill plan included — Not applicable: 入出力の構造は不変、tokenNamenull で返るケースが拡張されるだけ
  • CHANGELOG impact considered — minor bump per Conventional Commits (feat)

Context

resolve-symbol-at は project file の cursor 位置から reference cache の候補を返す薄い wrapper。Phase 3 MVP では正規表現ベースの identifier 抽出だったため、LLM が cursor をコメントや文字列リテラル内に置いたときに偽の tokenName を返してしまい、candidates も虚しく埋まっていた。本 PR で line comment と string literal の 2 ケースを除外し、cursor が code 領域にあるときだけ token を抽出する。

Out of Scope

umbrella SPEC #191 で継続管理する範囲:

  • block comment /* ... */ の multi-line 判定。現状は 1 行内のみ。
  • char literal '...' や interpolated string $"..."、verbatim string @"..." の特例。
  • preprocessor directive #if / #endif の中の cursor。
  • Phase 4-A (member-level シンボル抽出) / Phase 4-D (reference fetch の zip fallback) / Phase 4-E (vector embedding) は umbrella の Tasks として未着手。

Notes

  • block comment の multi-line 判定はファイル全体スキャンが必要で、本 PR では意図的にスコープアウト。LLM のカーソルが block comment 内に来るケースは line comment より稀との判断。

SPEC #191 (Phase 4 umbrella) のサブタスク C として、Phase 3 (#188)
で MVP land した extract_token_at_cursor の精度を上げる。これまでは
正規表現ベースで identifier 文字を機械的に拾うだけだったため、
コメント (`// ...`) 内や文字列リテラル (`"..."`) 内の identifier も
hit してしまい、resolve-symbol-at が偽陽性候補を返していた。

主な変更:

- src/reference/mod.rs::is_cursor_in_comment_or_string を新設し、
  カーソル位置までを scan して // line comment 内と "..." string
  literal 内を判定する。エスケープシーケンス \" は string を閉じ
  ない、line comment は // 以降を全て comment として扱う。
- extract_token_at_cursor が cursor 位置の class を判定し、comment
  内 / string 内なら None を返す。
- 新規 RED テスト 4 件: skips_line_comment / skips_string_literal /
  returns_ident_after_closed_string /
  handles_escaped_quote_in_string。

スコープ外(umbrella #191 で継続管理):

- block comment /* ... */ の multi-line 対応。現状は 1 行内の判定
  のみ。
- char literal '...' や interpolated string $"..." の特例。
- preprocessor directive #if/#endif の中の cursor。

ローカル検証:

- cargo fmt -- --check: clean
- cargo clippy --all-targets -- -D warnings: clean
- cargo test --bin unity-cli: 386 passed / 0 failed
- cargo llvm-cov --all-targets: TOTAL line coverage 91.03%
- unity-cli skills lint --severity error: 15 skills / 0 violations

Refs #191

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3bfa7598-9e77-440e-a085-f7e3484c8292

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch work/20260511-0223

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant