Skip to content

P4 LSP: go-to-definition / find-references (ScopeStore 活用) #5

Description

@opaopa6969

概要

ScopeStore の宣言・参照情報を使って LSP の go-to-definition と find-references を実装する。

変更内容

unlaxer-dsl 側 (0.3.1)

ScopeStore.java:

  • getAllDeclarations(ctx) — 宣言一覧を flat list で返す(スコープが閉じた後も参照可能)
  • addReference(ctx, name, offset, length)@backref ルールが参照を記録
  • getAllReferences(ctx) — 参照一覧を返す
  • ReferenceInfo(name, offset, length) record 追加

ParserGenerator.java:

  • @backref scope mode の onCommit で ScopeStore.addReference(ctx, refName, offset, refName.length()) を追加生成

tinyexpression 側 (0.2.2)

TinyExpressionP4LanguageServerExt.java:

  • parseAndEnrichallDeclarations + allReferences をキャプチャして ExtDocumentState に保存
  • ExtTextDocumentService.definition() — カーソル位置のシンボル名を解決 → SymbolInfo.sourceOffsetLocation を返す
  • ExtTextDocumentService.references() — カーソル位置のシンボル名 → ReferenceInfo リストを Location[] で返す

期待動作

  • $varName を Ctrl+click → 変数宣言行にジャンプ
  • call methodName(...) を Ctrl+click → メソッド定義行にジャンプ
  • find-references → エディタ上のすべての参照箇所をハイライト

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions