Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ static lsp::Diagnostic getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr,
}
lspDiag.message = diag.str();

// Downgrade errors related to unregistered dialects. We want to be able to
// provide the user with headsup about why the file didn't parse, but it is
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// provide the user with headsup about why the file didn't parse, but it is
// provide the user with heads up about why the file didn't parse, but it is

// not an error in the same way invalid syntax or op that failed verification
// is. Chose to make it a warning rather than information as it could be due
// to typo (and so addressable by the user).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite get this: an invalid syntax is even more likely to be a typo and so addressable by the user, the argument reads backward to me here.

if (lspDiag.severity == lsp::DiagnosticSeverity::Error) {
StringRef msg(lspDiag.message);
if (msg.starts_with("Dialect `") && msg.contains("not found for custom op"))
lspDiag.severity = lsp::DiagnosticSeverity::Warning;
}

// Attach any notes to the main diagnostic as related information.
std::vector<lsp::DiagnosticRelatedInformation> relatedDiags;
for (Diagnostic &note : diag.getNotes()) {
Expand Down
22 changes: 22 additions & 0 deletions mlir/test/mlir-lsp-server/diagnostics.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
// CHECK-NEXT: "version": 1
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
"uri":"test:///foo.mlir",
"languageId":"mlir",
"version":1,
"text":"unregistered.func.func ()"
}}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [
// CHECK-NEXT: {
// CHECK-NEXT: "category": "Parse Error",
// Note: If the next lines need change, please update the corresponding logic
// in MLIRServer.cpp to ensure the severity is still set as expected.
// CHECK-NEXT: "message": "Dialect `unregistered' not found for custom
// CHECK: "severity": 2,
// CHECK-NEXT: "source": "mlir"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "uri": "test:///foo.mlir",
// CHECK-NEXT: "version": 1
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","id":3,"method":"shutdown"}
// -----
{"jsonrpc":"2.0","method":"exit"}
Loading