Skip to content

Commit 83d5206

Browse files
authored
filter out diagnostics if they are in docsstring (#38)
Signed-off-by: Maxim Zaks <maxim.zaks@gmail.com>
1 parent 3ba0a67 commit 83d5206

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

extension/lsp/lsp.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,32 @@ export class MojoLSPManager extends DisposableContext {
322322
return next(method, param);
323323
}
324324
},
325+
async handleDiagnostics(uri, diagnostics, next) {
326+
if (config.get<boolean>(
327+
'lsp.suppress.diagnostics.in.docstring',
328+
/*workspaceFolder=*/ undefined,
329+
false,
330+
)) {
331+
const document = await vscode.workspace.openTextDocument(uri);
332+
const foldingRanges = await vscode.commands.executeCommand<vscode.FoldingRange[]>(
333+
'vscode.executeFoldingRangeProvider',
334+
uri,
335+
);
336+
const docstringRanges = foldingRanges.filter(r => {
337+
return document.lineAt(r.start).text.trimStart().startsWith('"""')
338+
});
339+
diagnostics = diagnostics.filter(d => {
340+
for (let index = 0; index < docstringRanges.length; index++) {
341+
const range = docstringRanges[index];
342+
if (d.range.start.line > range.start && d.range.end.line < range.end) {
343+
return false;
344+
}
345+
}
346+
return true;
347+
});
348+
}
349+
next(uri, diagnostics);
350+
},
325351
};
326352

327353
// Create the language client and start the client.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@
159159
"type": "string"
160160
}
161161
},
162+
"mojo.lsp.suppress.diagnostics.in.docstring": {
163+
"scope": "resource",
164+
"type": "boolean",
165+
"default": false,
166+
"description": "Suppress warnings and errors in docstring."
167+
},
162168
"mojo.formatting.args": {
163169
"scope": "resource",
164170
"type": "array",

0 commit comments

Comments
 (0)