Skip to content

Commit 0a679b8

Browse files
committed
Fix old diagnostics not being removed properly
1 parent d07dd18 commit 0a679b8

File tree

4 files changed

+105
-94
lines changed

4 files changed

+105
-94
lines changed

.vscode/settings.json

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,8 @@
88
"dist": true
99
},
1010
"typescript.tsc.autoDetect": "off",
11-
"[javascript]": {
12-
"editor.formatOnSave": true,
13-
"editor.defaultFormatter": "esbenp.prettier-vscode"
14-
},
15-
"[typescript]": {
16-
"editor.formatOnSave": true,
17-
"editor.defaultFormatter": "esbenp.prettier-vscode"
18-
},
19-
"[json]": {
20-
"editor.formatOnSave": true,
21-
"editor.defaultFormatter": "esbenp.prettier-vscode"
22-
},
23-
"[yaml]": {
24-
"editor.formatOnSave": true,
25-
"editor.defaultFormatter": "esbenp.prettier-vscode"
26-
},
27-
"[yml]": {
28-
"editor.formatOnSave": true,
29-
"editor.defaultFormatter": "esbenp.prettier-vscode"
30-
},
11+
"editor.formatOnSave": true,
12+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3113
"explorer.fileNesting.enabled": true,
3214
"explorer.fileNesting.patterns": {
3315
"*.ts": "${capture}.js",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to the "vscode-clazy" extension will be documented in this f
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v1.1.1
9+
10+
- Fix old diagnostics not being removed properly.
11+
812
## v1.1.0
913

1014
A lot of refactoring and update dependencies:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-clazy",
33
"displayName": "Clazy",
44
"description": "VSCode extension for Clazy",
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"license": "SEE LICENSE IN LICENSE",
77
"repository": {
88
"url": "https://github.com/TheBill2001/vscode-clazy"
@@ -315,7 +315,7 @@
315315
"watch": "npm-run-all -p watch:*",
316316
"watch:esbuild": "node esbuild.mjs --watch",
317317
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
318-
"package": "npm run check-types && npm run format && npm run lint && node esbuild.mjs --production",
318+
"package": "node esbuild.mjs --production",
319319
"lint": "eslint src",
320320
"format": "prettier --write --ignore-unknown ."
321321
},

src/lint.ts

Lines changed: 97 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -144,88 +144,113 @@ export default class Lint {
144144
static lintDocument(document: TextDocument) {
145145
Log.info(`Linting document: ${document.uri.toString()}`);
146146

147-
runClazy(document.uri.fsPath)?.then((clazyDiagnostics) => {
148-
if (clazyDiagnostics.length <= 0) {
149-
return;
150-
}
151-
152-
const fixClazyDiagnostics = fixDiagnosticRanges(
153-
clazyDiagnostics,
154-
document,
155-
);
147+
runClazy(document.uri.fsPath)
148+
?.then(
149+
(
150+
clazyDiagnostics,
151+
): Map<Diagnostic, ClazyReplacement[]> | undefined => {
152+
if (clazyDiagnostics.length <= 0) {
153+
return;
154+
}
155+
156+
const fixClazyDiagnostics = fixDiagnosticRanges(
157+
clazyDiagnostics,
158+
document,
159+
);
156160

157-
// Dedup
158-
for (let index1 = 0; index1 < clazyDiagnostics.length; ++index1) {
159-
const d1 = clazyDiagnostics[index1];
160-
for (
161-
let index2 = index1 + 1;
162-
index2 < clazyDiagnostics.length;
163-
) {
164-
const d2 = clazyDiagnostics[index2];
165-
166-
if (
167-
d1.diagnosticName !== d2.diagnosticName ||
168-
d1.diagnosticMessage.message !==
169-
d2.diagnosticMessage.message ||
170-
d1.diagnosticMessage.filePath !==
171-
d2.diagnosticMessage.filePath ||
172-
d1.diagnosticMessage.severity !==
173-
d2.diagnosticMessage.severity ||
174-
d1.diagnosticMessage.fileOffset !==
175-
d2.diagnosticMessage.fileOffset ||
176-
d1.diagnosticMessage.row !== d2.diagnosticMessage.row ||
177-
d1.diagnosticMessage.column !==
178-
d2.diagnosticMessage.column
161+
// Dedup
162+
for (
163+
let index1 = 0;
164+
index1 < clazyDiagnostics.length;
165+
++index1
179166
) {
180-
++index2;
181-
continue;
167+
const d1 = clazyDiagnostics[index1];
168+
for (
169+
let index2 = index1 + 1;
170+
index2 < clazyDiagnostics.length;
171+
) {
172+
const d2 = clazyDiagnostics[index2];
173+
174+
if (
175+
d1.diagnosticName !== d2.diagnosticName ||
176+
d1.diagnosticMessage.message !==
177+
d2.diagnosticMessage.message ||
178+
d1.diagnosticMessage.filePath !==
179+
d2.diagnosticMessage.filePath ||
180+
d1.diagnosticMessage.severity !==
181+
d2.diagnosticMessage.severity ||
182+
d1.diagnosticMessage.fileOffset !==
183+
d2.diagnosticMessage.fileOffset ||
184+
d1.diagnosticMessage.row !==
185+
d2.diagnosticMessage.row ||
186+
d1.diagnosticMessage.column !==
187+
d2.diagnosticMessage.column
188+
) {
189+
++index2;
190+
continue;
191+
}
192+
193+
if (
194+
d1.diagnosticMessage.replacements.length <
195+
d2.diagnosticMessage.replacements.length
196+
) {
197+
d1.diagnosticMessage.replacements =
198+
d2.diagnosticMessage.replacements;
199+
}
200+
201+
if (
202+
d1.relatedInformation !==
203+
d2.relatedInformation &&
204+
!d1.relatedInformation
205+
) {
206+
d1.relatedInformation = d2.relatedInformation;
207+
}
208+
209+
clazyDiagnostics.splice(index2, 1);
210+
}
182211
}
183212

184-
if (
185-
d1.diagnosticMessage.replacements.length <
186-
d2.diagnosticMessage.replacements.length
187-
) {
188-
d1.diagnosticMessage.replacements =
189-
d2.diagnosticMessage.replacements;
213+
const diagnostics = new Map<
214+
Diagnostic,
215+
ClazyReplacement[]
216+
>();
217+
for (const clazyDiagnostic of fixClazyDiagnostics) {
218+
if (
219+
workspace.asRelativePath(document.fileName) ===
220+
workspace.asRelativePath(
221+
clazyDiagnostic.diagnosticMessage.filePath,
222+
)
223+
) {
224+
const [diagnostic, replacements] =
225+
makeVSCodeDiagnostics(
226+
document,
227+
clazyDiagnostic,
228+
);
229+
diagnostics.set(diagnostic, replacements);
230+
}
190231
}
232+
return diagnostics;
233+
},
234+
)
235+
.then((diagnostics) => {
236+
Lint.removeDiagnosticForUri(document.uri);
191237

192-
if (
193-
d1.relatedInformation !== d2.relatedInformation &&
194-
!d1.relatedInformation
195-
) {
196-
d1.relatedInformation = d2.relatedInformation;
238+
if (diagnostics) {
239+
for (const [diagnostic, replacements] of diagnostics) {
240+
if (replacements.length > 0) {
241+
ClazyRefactorActionProvider.addDiagnostic(
242+
diagnostic,
243+
replacements,
244+
);
245+
}
197246
}
198247

199-
clazyDiagnostics.splice(index2, 1);
200-
}
201-
}
202-
203-
const diagnostics: Diagnostic[] = [];
204-
for (const clazyDiagnostic of fixClazyDiagnostics) {
205-
if (
206-
workspace.asRelativePath(document.fileName) ===
207-
workspace.asRelativePath(
208-
clazyDiagnostic.diagnosticMessage.filePath,
209-
)
210-
) {
211-
const [diagnostic, resplacements] = makeVSCodeDiagnostics(
212-
document,
213-
clazyDiagnostic,
248+
this.#diagnosticCollection.set(
249+
document.uri,
250+
Array.from(diagnostics.keys()),
214251
);
215-
216-
diagnostics.push(diagnostic);
217-
218-
if (resplacements.length > 0) {
219-
ClazyRefactorActionProvider.addDiagnostic(
220-
diagnostic,
221-
resplacements,
222-
);
223-
}
224252
}
225-
}
226-
227-
this.#diagnosticCollection.set(document.uri, diagnostics);
228-
});
253+
});
229254
}
230255

231256
static removeDiagnosticForUri(uri: Uri) {

0 commit comments

Comments
 (0)