-
Notifications
You must be signed in to change notification settings - Fork 404
[circt-verilog-lsp] Move to Slang's src mngr, drop LLVM src mngr #9045
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
Conversation
b600611 to
b769850
Compare
lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
Outdated
Show resolved
Hide resolved
uenoku
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic, thank you for unifying them!
b769850 to
c2ed31d
Compare
Thanks! I'll open this for review / merging now, do let me know if you have any points that stick out to you 😄 |
c2ed31d to
ef082a9
Compare
lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
Outdated
Show resolved
Hide resolved
lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
Outdated
Show resolved
Hide resolved
lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp
Outdated
Show resolved
Hide resolved
uenoku
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for improving buffer handling!
- **Use Slang buffers as source of truth** - Replace `llvm::SourceMgr`-centric code with direct use of `slang::SourceManager`. - Add `slang::BufferID mainBufferId` and expose `getMainBufferID()`. - **Interval map now indexes Slang buffer pointers** - New typedef: `using SlangBufferPointer = char const *;`. - Change from `IntervalMap<const char*, …>` to `IntervalMap<SlangBufferPointer, …>` (half-open). - Lookups are computed from `slang::SourceManager::getSourceText(buf).data() + offset`. - **Remove LLVM `SourceMgr` plumbing** - Drop members/APIs: `sourceMgr`, `bufferIDMap`, `getSMLoc(...)`. - Update `filePathMap` to store `(slang::BufferID, path)` pairs. - `getOrOpenFile(...)` now assigns text via Slang (`driver.sourceManager.assignText(...)`) and caches the returned `BufferID`. - **Implement LSP UTF-16 to Slang UTF-8 conversion** - Add `decodeUtf8(...)` and `lspPositionToOffset(...)` helpers. - Use these helpers in `getLocationsOf(...)` and `findReferencesOf(...)` before interval lookups. - Clamp positions past end-of-line to buffer end; avoid OOB pointer math. - **Definition & reference resolution updated** - `getLspLocation(slang::SourceLocation/Range)` now uses Slang line/column and compares `loc.buffer()` directly to `mainBufferId`. - `findReferencesOf(...)` / `getLocationsOf(...)` locate the interval by pointer into the **main** buffer. - **Top module discovery via syntax trees** - Derive `driver.options.topModules` from `CompilationUnitSyntax` members by reading `ModuleDeclarationSyntax` headers (covers modules and packages). - Avoid creating a separate `Compilation` just to enumerate tops.
7a500b0 to
25a18c9
Compare
Thank you once more for the helpful and targetted feedback. You really helped to point out some areas to improve further! I think unit tests make a lot of sense (easier to test things that way), but I would suggest to first break out VerilogServer, VerilogServerContext, VerilogTextFile and VerilogDocument into separate .cc files with corresponding header files. We could then add a unittest directory in the VerilogServerImpl directory, e.g. like this: VerilogServerImpl/ If something like this is fine for you, I can open a separate PR to implement it. Let me know what you think! |
Thanks! The current PR looks also great me!
I agree, I think this looks awesome! I also think separating headers is great. One nitpick is we probably want to use flat structures without |
Use Slang buffers as source of truth
llvm::SourceMgr-centric code with direct use ofslang::SourceManager.slang::BufferID mainBufferIdand exposegetMainBufferID().Interval map now indexes Slang buffer pointers
using SlangBufferPointer = char const *;.IntervalMap<const char*, …>toIntervalMap<SlangBufferPointer, …>(half-open).slang::SourceManager::getSourceText(buf).data() + offset.Remove LLVM
SourceMgrplumbingsourceMgr,bufferIDMap,getSMLoc(...).filePathMapto store(slang::BufferID, path)pairs.getOrOpenFile(...)now assigns text via Slang (driver.sourceManager.assignText(...)) and caches the returnedBufferID.Implement LSP UTF-16 to Slang UTF-8 conversion
decodeUtf8(...)andlspPositionToOffset(...)helpers.getLocationsOf(...)andfindReferencesOf(...)before interval lookups.Definition & reference resolution updated
getLspLocation(slang::SourceLocation/Range)now uses Slang line/column and comparesloc.buffer()directly tomainBufferId.findReferencesOf(...)/getLocationsOf(...)locate the interval by pointer into the main buffer.Top module discovery via syntax trees
driver.options.topModulesfromCompilationUnitSyntaxmembers by readingModuleDeclarationSyntaxheaders (covers modules and packages).Compilationjust to enumerate tops.