diff --git a/extension/lsp/lsp.ts b/extension/lsp/lsp.ts index 5c11f4f..8af7afb 100644 --- a/extension/lsp/lsp.ts +++ b/extension/lsp/lsp.ts @@ -322,6 +322,32 @@ export class MojoLSPManager extends DisposableContext { return next(method, param); } }, + async handleDiagnostics(uri, diagnostics, next) { + if (config.get( + 'lsp.suppress.diagnostics.in.docstring', + /*workspaceFolder=*/ undefined, + false, + )) { + const document = await vscode.workspace.openTextDocument(uri); + const foldingRanges = await vscode.commands.executeCommand( + 'vscode.executeFoldingRangeProvider', + uri, + ); + const docstringRanges = foldingRanges.filter(r => { + return document.lineAt(r.start).text.trimStart().startsWith('"""') + }); + diagnostics = diagnostics.filter(d => { + for (let index = 0; index < docstringRanges.length; index++) { + const range = docstringRanges[index]; + if (d.range.start.line > range.start && d.range.end.line < range.end) { + return false; + } + } + return true; + }); + } + next(uri, diagnostics); + }, }; // Create the language client and start the client. diff --git a/package.json b/package.json index dbad5c9..b4bd600 100644 --- a/package.json +++ b/package.json @@ -159,6 +159,12 @@ "type": "string" } }, + "mojo.lsp.suppress.diagnostics.in.docstring": { + "scope": "resource", + "type": "boolean", + "default": false, + "description": "Suppress warnings and errors in docstring." + }, "mojo.formatting.args": { "scope": "resource", "type": "array",