Skip to content

Commit 63f153a

Browse files
author
Moritz Scherer
committed
[circt-verilog-lsp][NFC] Break out implementation classes
**Summary** - Refactored `VerilogServerImpl` into smaller, well-structured components for clarity, testability, and maintainability. - Moved large inline class implementations out of `VerilogServer.cpp` into dedicated compilation units. **Changes** - **New modules** - `VerilogTextFile`: manages LSP file contents, versioning, and incremental updates. - `VerilogDocument`: handles Slang integration, parsing, diagnostics, and indexing setup. - `VerilogIndex`: implements symbol/reference tracking using interval maps. - `LSPDiagnosticClient`: converts Slang diagnostics to LSP diagnostics. - `VerilogServerContext`: stores server-wide options and shared configuration. - **Refactors** - `VerilogServer`: simplified to a coordinator using the pImpl pattern and `VerilogTextFile` instances. - Removed large class definitions (Document, Index, DiagnosticClient, etc.) from `VerilogServer.cpp`. - Updated `CMakeLists.txt` to compile new files. - **Headers** - Added clear LLVM-style header comments. - Reduced includes and replaced them with forward declarations where possible. **Impact** - No functional changes; purely structural refactor. - Improved code organization and readability. - Enables independent testing and clearer layering between LSP, Slang, and CIRCT logic.
1 parent 35af03c commit 63f153a

File tree

12 files changed

+1259
-1039
lines changed

12 files changed

+1259
-1039
lines changed

lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ include(SlangCompilerOptions)
33

44
add_circt_library(CIRCTVerilogLspServerImpl
55
VerilogServer.cpp
6+
VerilogTextFile.cpp
7+
VerilogDocument.cpp
8+
VerilogIndex.cpp
9+
LSPDiagnosticClient.cpp
610

711
ADDITIONAL_HEADER_DIRS
812
${MLIR_MAIN_INCLUDE_DIR}/circt/Tools/circt-verilog-lsp-server
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
/// A converter that can be plugged into a slang `DiagnosticEngine` as a
10+
/// client that will map slang diagnostics to LSP diagnostics.
11+
12+
#include "LSPDiagnosticClient.h"
13+
14+
using namespace circt::lsp;
15+
16+
static llvm::lsp::DiagnosticSeverity
17+
getSeverity(slang::DiagnosticSeverity severity) {
18+
switch (severity) {
19+
case slang::DiagnosticSeverity::Fatal:
20+
case slang::DiagnosticSeverity::Error:
21+
return llvm::lsp::DiagnosticSeverity::Error;
22+
case slang::DiagnosticSeverity::Warning:
23+
return llvm::lsp::DiagnosticSeverity::Warning;
24+
case slang::DiagnosticSeverity::Ignored:
25+
case slang::DiagnosticSeverity::Note:
26+
return llvm::lsp::DiagnosticSeverity::Information;
27+
}
28+
llvm_unreachable("all slang diagnostic severities should be handled");
29+
return llvm::lsp::DiagnosticSeverity::Error;
30+
}
31+
32+
void LSPDiagnosticClient::report(const slang::ReportedDiagnostic &slangDiag) {
33+
auto loc = document.getLspLocation(slangDiag.location);
34+
// Show only the diagnostics in the current file.
35+
if (loc.uri != document.getURI())
36+
return;
37+
auto &mlirDiag = diags.emplace_back();
38+
mlirDiag.severity = getSeverity(slangDiag.severity);
39+
mlirDiag.range = loc.range;
40+
mlirDiag.source = "slang";
41+
mlirDiag.message = slangDiag.formattedMessage;
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
#include "VerilogDocument.h"
11+
12+
namespace circt {
13+
namespace lsp {
14+
15+
class LSPDiagnosticClient : public slang::DiagnosticClient {
16+
const VerilogDocument &document;
17+
std::vector<llvm::lsp::Diagnostic> &diags;
18+
19+
public:
20+
LSPDiagnosticClient(const VerilogDocument &document,
21+
std::vector<llvm::lsp::Diagnostic> &diags)
22+
: document(document), diags(diags) {}
23+
24+
void report(const slang::ReportedDiagnostic &slangDiag) override;
25+
};
26+
} // namespace lsp
27+
} // namespace circt

0 commit comments

Comments
 (0)