Skip to content

Commit

Permalink
add: config 'maxFindFiles'
Browse files Browse the repository at this point in the history
  • Loading branch information
uctakeoff committed Jul 31, 2024
1 parent 2fcc0cd commit bc8273c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ However, you must carry the stored information to the remote environment by your

* `VSCodeCounter.useGitignore`: Whether to use '.gitignore' files for excluding files.
* `VSCodeCounter.useFilesExclude`: Whether to use setting 'files.exclude' for excluding files.
* `VSCodeCounter.maxFindFiles`: Maximum number of searchable files.
* `VSCodeCounter.maxOpenFiles`: Maximum number of files that VSCodeCounter can read simultaneously.
* `VSCodeCounter.printNumberWithCommas`: Whether to print a number with commas as thousands separators.(except for CSV)
* `VSCodeCounter.ignoreUnsupportedFile`: Ignore unsupported files.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
"type": "boolean",
"default": true
},
"VSCodeCounter.maxFindFiles": {
"description": "%configuration.maxFindFiles.description%",
"type": "number",
"default": 1000000
},
"VSCodeCounter.maxOpenFiles": {
"description": "%configuration.maxOpenFiles.description%",
"type": "number",
Expand Down
1 change: 1 addition & 0 deletions package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

"configuration.useGitignore.description": "対象ファイルを除外するために '.gitignore' を使う.",
"configuration.useFilesExclude.description": "対象ファイルを除外するために 'files.exclude' 設定を使う.",
"configuration.maxFindFiles.description": "検索可能なファイルの最大数.",
"configuration.maxOpenFiles.description": "VSCodeCounter が同時に読み取ることのできるファイルの最大数.",
"configuration.printNumberWithCommas.description": "数値をカンマ区切りで出力する (CSVを除く).",
"configuration.ignoreUnsupportedFile.description": "サポートしないファイルを無視する.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

"configuration.useGitignore.description": "Whether to use '.gitignore' files for excluding files.",
"configuration.useFilesExclude.description": "Whether to use setting 'files.exclude' for excluding files.",
"configuration.maxFindFiles.description": "Maximum number of searchable files.",
"configuration.maxOpenFiles.description": "Maximum number of files that VSCodeCounter can read simultaneously.",
"configuration.printNumberWithCommas.description": "Whether to print a number with commas as thousands separators.(except for CSV)",
"configuration.ignoreUnsupportedFile.description": "Ignore unsupported files.",
Expand Down
12 changes: 8 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const loadConfig = () => {
associations: Object.entries(confFiles.get<{ [key: string]: string }>('associations', {})),

maxOpenFiles: conf.get('maxOpenFiles', 500),
maxFindFiles: conf.get('maxFindFiles', 1_000_000),
ignoreUnsupportedFile: conf.get('ignoreUnsupportedFile', true),
history: Math.max(1, conf.get('history', 5)),
languages: conf.get<{ [key: string]: Partial<LanguageConf> }>('languages', {}),
Expand Down Expand Up @@ -228,11 +229,14 @@ class CodeCounterController {
const outputDir = buildUri(workspaceDir, this.conf.outputDirectory);
log(`include : "${this.conf.include}"`);
log(`exclude : "${this.conf.exclude}"`);
const files = await vscode.workspace.findFiles(`{${this.conf.include}}`, `{${this.conf.exclude},${vscode.workspace.asRelativePath(outputDir)}}`);
const files = await vscode.workspace.findFiles(
`{${this.conf.include}}`,
`{${this.conf.exclude},${vscode.workspace.asRelativePath(outputDir)}}`,
this.conf.maxFindFiles);
let targetFiles = files.filter(uri => !path.relative(targetUri.path, uri.path).startsWith(".."));
if (this.conf.useGitignore) {
log(`target : ${targetFiles.length} files -> use .gitignore`);
const gitignores = await loadGitIgnore();
const gitignores = await loadGitIgnore(this.conf.maxFindFiles);
targetFiles = targetFiles.filter(p => gitignores.excludes(p.fsPath));
}

Expand Down Expand Up @@ -302,8 +306,8 @@ class CodeCounterController {
}


const loadGitIgnore = async () => {
const gitignoreFiles = await vscode.workspace.findFiles('**/.gitignore', '');
const loadGitIgnore = async (maxFindFiles?: number) => {
const gitignoreFiles = await vscode.workspace.findFiles('**/.gitignore', '', maxFindFiles);
gitignoreFiles.forEach(f => log(`use gitignore : ${f}`));
const values = await readUtf8Files(gitignoreFiles.sort());
return new Gitignore('').merge(...values.map(p => new Gitignore(p.data, dirUri(p.uri).fsPath)));
Expand Down

0 comments on commit bc8273c

Please sign in to comment.