|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | import { Diagnostic, DiagnosticSeverity, type Disposable, languages, Uri, Range } from "vscode";
|
5 |
| -import type { FileIssues } from "../type"; |
| 5 | +import type { FileIssues, UpgradeIssue } from "../type"; |
6 | 6 | import { Upgrade } from "../../constants";
|
7 | 7 | import { buildMessage } from "../utility";
|
8 | 8 |
|
9 | 9 | class DiagnosticsManager implements Disposable {
|
10 | 10 | private diagnostics = languages.createDiagnosticCollection('javaUpgrade');
|
| 11 | + private diagIssueMap = new WeakMap<Diagnostic, UpgradeIssue>(); |
11 | 12 |
|
12 | 13 | dispose() {
|
13 | 14 | this.diagnostics.dispose();
|
14 | 15 | }
|
15 | 16 |
|
16 |
| - refresh(filePath: string, issues: FileIssues) { |
17 |
| - this.diagnostics.set(Uri.file(filePath), Object.entries(issues).map(([groupId, issue]) => { |
| 17 | + public refresh(filePath: string, issues: FileIssues) { |
| 18 | + this.diagnostics.set(Uri.file(filePath), Object.entries(issues).map(([packageId, issue]) => { |
18 | 19 | const diagnostic = new Diagnostic(
|
19 | 20 | // TODO: locate the actual version settings
|
20 | 21 | new Range(0, 0, 0, 0),
|
21 | 22 | buildMessage(issue),
|
22 | 23 | DiagnosticSeverity.Warning
|
23 | 24 | );
|
| 25 | + this.diagIssueMap.set(diagnostic, issue); |
24 | 26 |
|
25 |
| - diagnostic.code = JSON.stringify(issue); |
| 27 | + diagnostic.code = packageId; |
26 | 28 | diagnostic.source = Upgrade.PROMOTION_DIAGNOSTIC_SOURCE;
|
27 | 29 |
|
28 | 30 | return diagnostic;
|
29 | 31 | }));
|
30 | 32 | }
|
| 33 | + |
| 34 | + public getIssue(diagnostic: Diagnostic) { |
| 35 | + return this.diagIssueMap.get(diagnostic); |
| 36 | + } |
31 | 37 | }
|
32 | 38 |
|
33 | 39 | const diagnosticsManager = new DiagnosticsManager();
|
|
0 commit comments