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
26 changes: 26 additions & 0 deletions extension/lsp/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,32 @@ export class MojoLSPManager extends DisposableContext {
return next(method, param);
}
},
async handleDiagnostics(uri, diagnostics, next) {
if (config.get<boolean>(
'lsp.suppress.diagnostics.in.docstring',
/*workspaceFolder=*/ undefined,
false,
)) {
const document = await vscode.workspace.openTextDocument(uri);
const foldingRanges = await vscode.commands.executeCommand<vscode.FoldingRange[]>(
'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.
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down