Create diagnostics entries without language server in Visual Studio Code

别说谁变了你拦得住时间么 提交于 2020-07-03 07:51:42

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/35581332/create-diagnostics-entries-without-language-server-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!