使用 VSCode 扩展 API 获取所有问题(错误、警告等)
Get all problems (errors, warnings, etc.) using VSCode extensions API
我正在创建一个 VSCode 扩展,我需要一种方法来访问“问题”窗格中的所有当前错误、警告等,但我什至不确定 API 是否提供访问权限对此。我看到我可以创建 Diagnostics
并且似乎我可以使用 DiagnosticCollection
获得这些诊断,但我看不到在哪里可以获得所有错误等的列表。有没有人有这方面的经验。
p.s。我试过了
console.log(vscode.DiagnosticCollection) // undefined
console.log(vscode) // Looked through the object and found nothing of use
console.log(window) // Same thing. Nothing of use.
根据文档,目前似乎不可能。
但我看到一些关于在问题视图中添加 API 的讨论,以便在下一个版本中可用。
现在有 2 个 api,请参阅 api reference: language diagnostics:
getDiagnostics(): [Uri, Diagnostic[]][]
获取所有文件的诊断信息
let diagnostics = vscode.languages.getDiagnostics();
getDiagnostics(resource: Uri): Diagnostic[]
获取特定 uri 的诊断信息
const uri = vscode.window.activeTextEditor.document.uri;
let diagnostics = vscode.languages.getDiagnostics(uri); // returns an array
我正在创建一个 VSCode 扩展,我需要一种方法来访问“问题”窗格中的所有当前错误、警告等,但我什至不确定 API 是否提供访问权限对此。我看到我可以创建 Diagnostics
并且似乎我可以使用 DiagnosticCollection
获得这些诊断,但我看不到在哪里可以获得所有错误等的列表。有没有人有这方面的经验。
p.s。我试过了
console.log(vscode.DiagnosticCollection) // undefined
console.log(vscode) // Looked through the object and found nothing of use
console.log(window) // Same thing. Nothing of use.
根据文档,目前似乎不可能。
但我看到一些关于在问题视图中添加 API 的讨论,以便在下一个版本中可用。
现在有 2 个 api,请参阅 api reference: language diagnostics:
getDiagnostics(): [Uri, Diagnostic[]][]
获取所有文件的诊断信息
let diagnostics = vscode.languages.getDiagnostics();
getDiagnostics(resource: Uri): Diagnostic[]
获取特定 uri 的诊断信息
const uri = vscode.window.activeTextEditor.document.uri;
let diagnostics = vscode.languages.getDiagnostics(uri); // returns an array