Skip to content

[circt-verilog-lsp] Add hover support #8304

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

Open
wants to merge 1 commit into
base: dev/hidetou/lsp-features/inlay-hints
Choose a base branch
from

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Mar 6, 2025

Add hover functionality to the CIRCT Verilog LSP server.

The implementation adds hover support for Verilog symbols showing type information, definition location with source code, and links to source locations. It also implements hover for external source locations showing code snippets and links to external files.

Add hover functionality to the CIRCT Verilog LSP server. This includes hover
provider capability in server initialization and hover context line configuration
option.

The implementation adds hover support for Verilog symbols showing type information,
definition location with source code, and links to source locations. It also
implements hover for external source locations showing context-aware source code
snippets and links to external files.

The hover feature provides rich information when hovering over Verilog symbols
(showing type and definition) and source location annotations (showing external
source contents such as MLIR and scala).
// CHECK-NEXT: }
// CHECK-NEXT: }
// -----
// Find definition of `include/test.mlir:2:5`
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
// Find definition of `include/test.mlir:2:5`
// Find hover of `include/test.mlir:2:5`

@bryceberger
Copy link

This has an out of bounds if the definition is on the first line of a file.

Reproduction:

module thing(input var[2:0] a, output var [2:0] b);
    logic [2:0] c;
    assign c = a;
    assign b = c;
endmodule

Hover on c (either at definition position or on use), works as expected.

Hover on a or b, and the server crashes:

terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string_view::substr: __pos (which is 18446744073709551615) > __size (which is 118)

Minimal solution:

diff --git a/lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp b/lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
index 7bd80a6c47..a2933f1eeb 100644
--- a/lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
+++ b/lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
@@ -1297,6 +1297,9 @@
   auto offest = loc.offset();
   // Find line boundaries around the location
   auto start = text.find_last_of('\n', offest);
+  if (start == text.npos) {
+    start = 0;
+  }
   auto end = text.find_first_of('\n', offest);
   return StringRef(text.substr(start, end - start)).trim();
 }

@uenoku
Copy link
Member Author

uenoku commented Apr 12, 2025

This has an out of bounds if the definition is on the first line of a file.

Great point, thanks! The fix makes sense, I'll include your fix, thanks!

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