Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] Incremental Indexing #33485

Merged
merged 6 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions x-pack/plugins/code/common/git_diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

import { CommitInfo } from '../model/commit';

export interface CommitDiff {
commit: CommitInfo;
export interface Diff {
additions: number;
deletions: number;
files: FileDiff[];
}

export interface CommitDiff extends Diff {
commit: CommitInfo;
}

export interface FileDiff {
path: string;
originPath?: string;
Expand All @@ -25,8 +28,8 @@ export interface FileDiff {
}

export enum DiffKind {
ADDED,
DELETED,
MODIFIED,
RENAMED,
ADDED = 'ADDED',
DELETED = 'DELETED',
MODIFIED = 'MODIFIED',
RENAMED = 'RENAMED',
}
2 changes: 1 addition & 1 deletion x-pack/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const code = (kibana: any) =>
.default(['https', 'git']),
}).default(),
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
disableScheduler: Joi.boolean().default(true), // Temp option to disable all schedulers.
disableIndexScheduler: Joi.boolean().default(true), // Temp option to disable index scheduler.
enableGlobalReference: Joi.boolean().default(false), // Global reference as optional feature for now
codeNode: Joi.boolean().default(false),
}).default();
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/code/model/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface Repository {
nextUpdateTimestamp?: Date;
// The timestamp of next index for this repository.
nextIndexTimestamp?: Date;
// The current indexed revision in Elasticsearch.
indexedRevision?: string;
}

export interface RepositoryConfig {
Expand Down Expand Up @@ -87,9 +89,12 @@ export interface UpdateWorkerResult extends WorkerResult {
}

export enum IndexStatsKey {
File = 'file-count',
Symbol = 'symbol-count',
Reference = 'reference-count',
File = 'file-added-count',
FileDeleted = 'file-deleted-count',
Symbol = 'symbol-added-count',
SymbolDeleted = 'symbol-deleted-count',
Reference = 'reference-added-count',
ReferenceDeleted = 'reference-deleted-count',
}
export type IndexStats = Map<IndexStatsKey, number>;

Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/code/model/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { DetailSymbolInformation } from '@elastic/lsp-extension';
import { IRange } from 'monaco-editor';

import { DiffKind } from '../common/git_diff';
import { Repository, SourceHit } from '../model';
import { RepositoryUri } from './repository';

Expand All @@ -31,6 +32,12 @@ export interface LspIndexRequest extends IndexRequest {
revision: string; // The revision of the current repository
}

export interface LspIncIndexRequest extends LspIndexRequest {
originPath?: string;
kind: DiffKind;
originRevision: string;
}

// The request for RepositoryIndexer
export interface RepositoryIndexRequest extends IndexRequest {
repoUri: RepositoryUri;
Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/code/server/__tests__/git_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,36 @@ describe('git_operations', () => {
assert.strictEqual(count, 3, 'this repo should contains exactly 2 files');
assert.strictEqual(totalFiles, 3, 'this repo should contains exactly 2 files');
});

it('get diff between arbitrary 2 revisions', async () => {
function cloneProject(url: string, p: string) {
return new Promise(resolve => {
if (!fs.existsSync(p)) {
rimraf(p, error => {
Git.Clone.clone(url, p).then(repo => {
resolve(repo);
});
});
} else {
resolve();
}
});
}

await cloneProject(
'https://github.com/Microsoft/TypeScript-Node-Starter.git',
path.join(serverOptions.repoPath, 'github.com/Microsoft/TypeScript-Node-Starter')
);

const g = new GitOperations(serverOptions.repoPath);
const d = await g.getDiff(
'github.com/Microsoft/TypeScript-Node-Starter',
'6206f643',
'4779cb7e'
);
assert.equal(d.additions, 2);
assert.equal(d.deletions, 4);
assert.equal(d.files.length, 3);
// @ts-ignore
}).timeout(100000);
});
Loading