|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import { ProvideDiagnosticSignature, ProvideWorkspaceDiagnosticSignature, vsdiag } from 'vscode-languageclient/node'; |
| 8 | +import { languageServerOptions } from '../../shared/options'; |
| 9 | + |
| 10 | +export async function provideDiagnostics( |
| 11 | + document: vscode.TextDocument | vscode.Uri, |
| 12 | + previousResultId: string | undefined, |
| 13 | + token: vscode.CancellationToken, |
| 14 | + next: ProvideDiagnosticSignature |
| 15 | +) { |
| 16 | + const result = await next(document, previousResultId, token); |
| 17 | + tryUpdateInformationDiagnostics(result); |
| 18 | + return result; |
| 19 | +} |
| 20 | + |
| 21 | +export async function provideWorkspaceDiagnostics( |
| 22 | + resultIds: vsdiag.PreviousResultId[], |
| 23 | + token: vscode.CancellationToken, |
| 24 | + resultReporter: vsdiag.ResultReporter, |
| 25 | + next: ProvideWorkspaceDiagnosticSignature |
| 26 | +) { |
| 27 | + const result = await next(resultIds, token, (chunk) => { |
| 28 | + chunk?.items.forEach(tryUpdateInformationDiagnostics); |
| 29 | + resultReporter(chunk); |
| 30 | + }); |
| 31 | + return result; |
| 32 | +} |
| 33 | + |
| 34 | +function tryUpdateInformationDiagnostics(report: vsdiag.DocumentDiagnosticReport | null | undefined) { |
| 35 | + if (report?.kind === vsdiag.DocumentDiagnosticReportKind.full && languageServerOptions.reportInformationAsHint) { |
| 36 | + report.items.forEach((item) => { |
| 37 | + if (item.severity === vscode.DiagnosticSeverity.Information) { |
| 38 | + item.severity = vscode.DiagnosticSeverity.Hint; |
| 39 | + } |
| 40 | + }); |
| 41 | + } |
| 42 | +} |
0 commit comments