CIRCT 22.0.0git
Loading...
Searching...
No Matches
LSPDiagnosticClient.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
13
14#include "LSPDiagnosticClient.h"
15
16using namespace circt::lsp;
17
18static llvm::lsp::DiagnosticSeverity
19getSeverity(slang::DiagnosticSeverity severity) {
20 switch (severity) {
21 case slang::DiagnosticSeverity::Fatal:
22 case slang::DiagnosticSeverity::Error:
23 return llvm::lsp::DiagnosticSeverity::Error;
24 case slang::DiagnosticSeverity::Warning:
25 return llvm::lsp::DiagnosticSeverity::Warning;
26 case slang::DiagnosticSeverity::Ignored:
27 case slang::DiagnosticSeverity::Note:
28 return llvm::lsp::DiagnosticSeverity::Information;
29 }
30 llvm_unreachable("all slang diagnostic severities should be handled");
31 return llvm::lsp::DiagnosticSeverity::Error;
32}
33
34void LSPDiagnosticClient::report(const slang::ReportedDiagnostic &slangDiag) {
35 auto loc = document.getLspLocation(slangDiag.location);
36 // Show only the diagnostics in the current file.
37 if (loc.uri != document.getURI())
38 return;
39 auto &mlirDiag = diags.emplace_back();
40 mlirDiag.severity = getSeverity(slangDiag.severity);
41 mlirDiag.range = loc.range;
42 mlirDiag.source = "slang";
43 mlirDiag.message = slangDiag.formattedMessage;
44}
static llvm::lsp::DiagnosticSeverity getSeverity(slang::DiagnosticSeverity severity)
void report(const slang::ReportedDiagnostic &slangDiag) override
std::vector< llvm::lsp::Diagnostic > & diags
const llvm::lsp::URIForFile & getURI() const
llvm::lsp::Location getLspLocation(slang::SourceLocation loc) const