Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create diagnostics entries without language server in Visual Studio Code

I have a reasonably simple extension for Visual Studio Code where I want to apply some warning, if possible, without having to implement an entire language server for it. Is there a way to do this directly on the document or editor objects? I'm not finding anything when inspecting the objects.

like image 437
Travis Avatar asked Mar 14 '23 04:03

Travis


1 Answers

So, I was able to do this after a bunch of digging.

import { languages, Diagnostic, DiagnosticSeverity } from 'vscode';

... 

let diagnosticCollection = languages.createDiagnosticCollection("stuff");
let diagnostics : Diagnostic[] = [];

...

diagnostics.push(new Diagnostic(range, message, DiagnosticSeverity.Warning));

diagnosticCollection.set(document.uri, diagnostics);
like image 118
Travis Avatar answered Mar 16 '23 10:03

Travis