Skip to content

Commit abe8de2

Browse files
bonegarazzeee
authored andcommitted
make all reported problems respect elm-analyse excluded files
1 parent 800fee7 commit abe8de2

4 files changed

Lines changed: 64 additions & 29 deletions

File tree

src/common/providers/diagnostics/diagnosticsProvider.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { ElmMakeDiagnostics } from "./elmMakeDiagnostics";
2727
import { DiagnosticKind, FileDiagnostics } from "./fileDiagnostics";
2828
import { ISourceFile } from "../../../compiler/forest";
2929
import { ElmReviewDiagnostics } from "./elmReviewDiagnostics";
30+
import { IElmAnalyseJsonService } from "./elmAnalyseJsonService";
3031

3132
export interface IElmIssueRegion {
3233
start: { line: number; column: number };
@@ -90,6 +91,7 @@ export class DiagnosticsProvider implements Disposable {
9091
private elmMakeDiagnostics: ElmMakeDiagnostics;
9192
private elmReviewDiagnostics: ElmReviewDiagnostics;
9293
private elmLsDiagnostics: ElmLsDiagnostics;
94+
private elmAnalyseJsonService: IElmAnalyseJsonService;
9395
private currentDiagnostics: Map<string, FileDiagnostics>;
9496
private events: TextDocumentEvents;
9597
private connection: Connection;
@@ -112,6 +114,9 @@ export class DiagnosticsProvider implements Disposable {
112114
this.elmMakeDiagnostics = container.resolve(ElmMakeDiagnostics);
113115
this.elmReviewDiagnostics = container.resolve(ElmReviewDiagnostics);
114116
this.elmLsDiagnostics = container.resolve(ElmLsDiagnostics);
117+
this.elmAnalyseJsonService = container.resolve<IElmAnalyseJsonService>(
118+
"ElmAnalyseJsonService",
119+
);
115120
this.documentEvents = container.resolve(TextDocumentEvents);
116121

117122
this.connection = container.resolve("Connection");
@@ -446,6 +451,21 @@ export class DiagnosticsProvider implements Disposable {
446451
return;
447452
}
448453

454+
if (
455+
this.elmAnalyseJsonService.isFileExcluded(
456+
sourceFile.uri,
457+
program.getRootPath().fsPath,
458+
)
459+
) {
460+
this.updateDiagnostics(uri, DiagnosticKind.ElmMake, []);
461+
this.updateDiagnostics(uri, DiagnosticKind.Syntactic, []);
462+
this.updateDiagnostics(uri, DiagnosticKind.Semantic, []);
463+
this.updateDiagnostics(uri, DiagnosticKind.Suggestion, []);
464+
this.updateDiagnostics(uri, DiagnosticKind.ElmLS, []);
465+
goNext();
466+
return;
467+
}
468+
449469
next.immediate(() => {
450470
this.updateDiagnostics(uri, DiagnosticKind.ElmMake, []);
451471
this.updateDiagnostics(

src/common/providers/diagnostics/elmAnalyseJsonService.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path";
22
import { container, injectable } from "tsyringe";
33
import { Connection } from "vscode-languageserver";
4+
import { URI } from "vscode-uri";
45

56
export interface IElmAnalyseJson {
67
checks?: {
@@ -40,6 +41,7 @@ export interface IElmAnalyseJson {
4041

4142
export interface IElmAnalyseJsonService {
4243
getElmAnalyseJson(workspacePath: string): IElmAnalyseJson;
44+
isFileExcluded(fileUri: string, workspacePath: string): boolean;
4345
}
4446

4547
@injectable()
@@ -72,4 +74,24 @@ export class ElmAnalyseJsonService implements IElmAnalyseJsonService {
7274
this.elmAnalyseJson.set(workspacePath, elmAnalyseJson);
7375
return elmAnalyseJson;
7476
}
77+
78+
public isFileExcluded(fileUri: string, workspacePath: string): boolean {
79+
const elmAnalyseJson = this.getElmAnalyseJson(workspacePath);
80+
81+
if (!elmAnalyseJson.excludedPaths) {
82+
return false;
83+
}
84+
85+
return elmAnalyseJson.excludedPaths.some((excludedPath) => {
86+
if (excludedPath.startsWith(workspacePath)) {
87+
// absolute path
88+
return fileUri.startsWith(URI.file(excludedPath).toString());
89+
} else {
90+
// relative path
91+
return fileUri.startsWith(
92+
URI.file(path.join(workspacePath, excludedPath)).toString(),
93+
);
94+
}
95+
});
96+
}
7597
}

src/common/providers/diagnostics/elmLsDiagnostics.ts

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -396,32 +396,6 @@ export class ElmLsDiagnostics {
396396
);
397397
}
398398

399-
private excludedFolder(
400-
sourceFile: ISourceFile,
401-
program: IProgram,
402-
elmAnalyseJson: IElmAnalyseJson,
403-
): boolean {
404-
const uri = sourceFile.uri;
405-
const rootPath = program.getRootPath().fsPath;
406-
407-
if (
408-
elmAnalyseJson.excludedPaths?.some((excludedPath) => {
409-
if (excludedPath.startsWith(rootPath)) {
410-
// absolute path
411-
return uri.startsWith(URI.file(excludedPath).toString());
412-
} else {
413-
// relative path
414-
return uri.startsWith(
415-
URI.file(path.join(rootPath, excludedPath)).toString(),
416-
);
417-
}
418-
})
419-
) {
420-
return true;
421-
}
422-
return false;
423-
}
424-
425399
public createDiagnostics = (
426400
sourceFile: ISourceFile,
427401
program: IProgram,
@@ -430,7 +404,12 @@ export class ElmLsDiagnostics {
430404
program.getRootPath().fsPath,
431405
);
432406

433-
if (this.excludedFolder(sourceFile, program, elmAnalyseJson)) {
407+
if (
408+
this.elmAnalyseJsonService.isFileExcluded(
409+
sourceFile.uri,
410+
program.getRootPath().fsPath,
411+
)
412+
) {
434413
return [];
435414
}
436415

@@ -499,7 +478,12 @@ export class ElmLsDiagnostics {
499478
program.getRootPath().fsPath,
500479
);
501480

502-
if (this.excludedFolder(sourceFile, program, elmAnalyseJson)) {
481+
if (
482+
this.elmAnalyseJsonService.isFileExcluded(
483+
sourceFile.uri,
484+
program.getRootPath().fsPath,
485+
)
486+
) {
503487
return [];
504488
}
505489

src/common/providers/diagnostics/elmMakeDiagnostics.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ElmDiagnosticsHelper } from "./elmDiagnosticsHelper";
1717
import { IProgram } from "../../../compiler/program";
1818
import { IFileSystemHost } from "../../types";
1919
import type { ExecaReturnValue } from "execa";
20+
import { IElmAnalyseJsonService } from "./elmAnalyseJsonService";
2021

2122
const ELM_MAKE = "Elm";
2223
export const NAMING_ERROR = "NAMING ERROR";
@@ -61,11 +62,15 @@ export class ElmMakeDiagnostics {
6162
private elmWorkspaceMatcher: ElmWorkspaceMatcher<URI>;
6263
private settings: Settings;
6364
private connection: Connection;
65+
private elmAnalyseJsonService: IElmAnalyseJsonService;
6466

6567
constructor(private host: IFileSystemHost) {
6668
this.settings = container.resolve("Settings");
6769
this.connection = container.resolve<Connection>("Connection");
6870
this.elmWorkspaceMatcher = new ElmWorkspaceMatcher((uri) => uri);
71+
this.elmAnalyseJsonService = container.resolve<IElmAnalyseJsonService>(
72+
"ElmAnalyseJsonService",
73+
);
6974
}
7075

7176
public canRun = (sourceFile: ISourceFile): boolean => {
@@ -204,7 +209,11 @@ export class ElmMakeDiagnostics {
204209
? forestFiles
205210
: forestFiles.concat(sourceFile);
206211

207-
const projectFiles = allFiles.filter((file) => !file.isDependency);
212+
const projectFiles = allFiles.filter(
213+
(file) =>
214+
!file.isDependency &&
215+
!this.elmAnalyseJsonService.isFileExcluded(file.uri, workspaceRootPath),
216+
);
208217

209218
const testFilesForSure = projectFiles.filter((file) => file.isTestFile);
210219
const otherFiles = projectFiles.filter((file) => !file.isTestFile);

0 commit comments

Comments
 (0)