[Code] Filter out binary files for indexer (#37945) (#38049)

This commit is contained in:
Mengwei Ding 2019-06-04 16:45:44 -07:00 committed by GitHub
parent 0d334d982e
commit 1c342e3ad6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -202,11 +202,12 @@ describe('lsp_indexer unit tests', function(this: any) {
// There are 22 files which are written in supported languages in the repo. 1 file + 1 symbol + 1 reference = 3 objects to
// index for each file. Total doc indexed for these files should be 3 * 22 = 66.
// The rest 158 files will only be indexed for document. So the total number of index
// requests will be 66 + 158 = 224.
// The rest 158 files will only be indexed for document.
// There are also 10 binary files to be excluded.
// So the total number of index requests will be 66 + 158 - 10 = 214.
assert.ok(bulkSpy.calledOnce);
assert.strictEqual(lspSendRequestSpy.callCount, 22);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 224 * 2);
assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 214 * 2);
// @ts-ignore
}).timeout(20000);

View file

@ -194,7 +194,11 @@ export class GitOperations {
async function* walk(t: Tree): AsyncIterableIterator<FileTree> {
for (const e of t.entries()) {
if (e.isFile() && e.filemode() !== TreeEntry.FILEMODE.LINK) {
yield entry2Tree(e);
const blob = await e.getBlob();
// Ignore binary files
if (!blob.isBinary()) {
yield entry2Tree(e);
}
} else if (e.isDirectory()) {
const subFolder = await e.getTree();
await (yield* walk(subFolder));