Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[circt-verilog-lsp] Add definition and reference providers #8280

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Feb 27, 2025

This commit adds "Go to Definition" and "Find References" functionality to the CIRCT Verilog LSP server. These features allow users to navigate between symbol definitions and usages within Verilog source files. Besides it provides cross references for source location comments.

  • Added VerilogIndex class to track symbol definitions and references
  • Implemented source location parsing for external file references
  • Added support for LSP definition and reference requests
  • Extended server capabilities for the new functionality

Following PDLL's LSP implemetation, the implementation uses an IntervalMap to efficiently map source positions
to symbols, allowing quick lookups when users request definitions or references. It also supports source location annotations in comments that can link to external source files, enabling cross-language navigation.

@uenoku uenoku changed the base branch from dev/hidetou/lsp to main February 28, 2025 00:37
This commit adds "Go to Definition" and "Find References" functionality to
the CIRCT Verilog LSP server. These features allow users to navigate between
symbol definitions and usages within Verilog source files.

- Added VerilogIndex class to track symbol definitions and references
- Implemented source location parsing for external file references
- Added support for LSP definition and reference requests
- Extended server capabilities to advertise the new functionality
- Added test cases to verify the new features

Following PDLL's LSP implemetation, the implementation uses an
IntervalMap to efficiently map source positions
to symbols, allowing quick lookups when users request definitions or
references. It also supports source location annotations in comments that
can link to external MLIR files, enabling cross-language navigation.
if (!intervalIt.valid() || posLoc.getPointer() < intervalIt.start())
return;

const auto *symbol = cast<const slang::ast::Symbol *>(intervalIt.value());
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
const auto *symbol = cast<const slang::ast::Symbol *>(intervalIt.value());
const auto *symbol = dyn_cast<const slang::ast::Symbol *>(intervalIt.value());

Comment on lines +812 to +813
circt::lsp::Logger::info(std::to_string(defPos.line) + ":" +
std::to_string(defPos.character));
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
circt::lsp::Logger::info(std::to_string(defPos.line) + ":" +
std::to_string(defPos.character));


auto element = it.value();
if (auto attr = dyn_cast<Attribute>(element)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change

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