Skip to content

Commit 2f01120

Browse files
authored
Merge pull request #27 from IsLand-x/main
fix: Refresh untracked file list once a new file is created.
2 parents e17b3b0 + 4588ff9 commit 2f01120

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.tsbuildinfo
22
/coverage/
33
/dist/
4+
node_modules

src/git.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,25 @@ const fetchFromOrigin = (branch: string) => {
7777
child_process.execFileSync(COMMAND, args, OPTIONS);
7878
};
7979

80-
const getUntrackedFileList = (staged = false): string[] => {
80+
let untrackedFileListCache: string[] | undefined;
81+
const getUntrackedFileList = (
82+
staged = false,
83+
shouldRefresh = false
84+
): string[] => {
8185
if (staged) {
8286
return [];
8387
}
8488

85-
const args = ["ls-files", "--exclude-standard", "--others"];
89+
if (untrackedFileListCache === undefined || shouldRefresh) {
90+
const args = ["ls-files", "--exclude-standard", "--others"];
8691

87-
const untrackedFileListCache = child_process
88-
.execFileSync(COMMAND, args, OPTIONS)
89-
.toString()
90-
.trim()
91-
.split("\n")
92-
.map((filePath) => resolve(filePath));
92+
untrackedFileListCache = child_process
93+
.execFileSync(COMMAND, args, OPTIONS)
94+
.toString()
95+
.trim()
96+
.split("\n")
97+
.map((filePath) => resolve(filePath));
98+
}
9399

94100
return untrackedFileListCache;
95101
};

src/processors.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ if (process.env.CI !== undefined) {
2828
* This is increasingly useful the more files there are in the repository.
2929
*/
3030
const getPreProcessor =
31-
(untrackedFileList: string[], diffFileList: string[]) =>
31+
(diffFileList: string[], staged: boolean) =>
3232
(text: string, filename: string) => {
33+
let untrackedFileList = getUntrackedFileList(staged);
34+
const shouldRefresh =
35+
!diffFileList.includes(filename) && !untrackedFileList.includes(filename);
36+
if (shouldRefresh) {
37+
untrackedFileList = getUntrackedFileList(staged, true);
38+
}
3339
const shouldBeProcessed =
3440
process.env.VSCODE_CLI !== undefined ||
3541
diffFileList.includes(filename) ||
@@ -66,7 +72,7 @@ const getUnstagedChangesError = (filename: string): [Linter.LintMessage] => {
6672
};
6773

6874
const getPostProcessor =
69-
(untrackedFileList: string[], staged = false) =>
75+
(staged = false) =>
7076
(
7177
messages: Linter.LintMessage[][],
7278
filename: string
@@ -75,7 +81,7 @@ const getPostProcessor =
7581
// No need to filter, just return
7682
return [];
7783
}
78-
84+
const untrackedFileList = getUntrackedFileList(staged);
7985
if (untrackedFileList.includes(filename)) {
8086
// We don't need to filter the messages of untracked files because they
8187
// would all be kept anyway, so we return them as-is.
@@ -111,12 +117,11 @@ const getProcessors = (
111117
processorType: ProcessorType
112118
): Required<Linter.Processor> => {
113119
const staged = processorType === "staged";
114-
const untrackedFileList = getUntrackedFileList(staged);
115120
const diffFileList = getDiffFileList(staged);
116121

117122
return {
118-
preprocess: getPreProcessor(untrackedFileList, diffFileList),
119-
postprocess: getPostProcessor(untrackedFileList, staged),
123+
preprocess: getPreProcessor(diffFileList, staged),
124+
postprocess: getPostProcessor(staged),
120125
supportsAutofix: true,
121126
};
122127
};

0 commit comments

Comments
 (0)