Skip to content

Commit ec7f80b

Browse files
author
iamhyc
committed
chore(temp): integration
1 parent 0299850 commit ec7f80b

File tree

7 files changed

+116
-23
lines changed

7 files changed

+116
-23
lines changed
Lines changed: 1 addition & 0 deletions
Loading

resources/icons/gutter-edit.svg

Lines changed: 1 addition & 0 deletions
Loading

resources/icons/gutter-pass.svg

Lines changed: 1 addition & 0 deletions
Loading

src/api/extendedBase.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export interface UrlLinkedFileProvider {
1212
url: string,
1313
}
1414

15+
export interface CommentThreadSchema {
16+
messages: CommentThreadMessageSchema[],
17+
resolved?: boolean,
18+
resolved_at?: string, //ISO format date string
19+
resolved_by_user_id?: string,
20+
resolved_by_user?: UserInfoSchema,
21+
}
22+
1523
export interface CommentThreadMessageSchema {
1624
id: string,
1725
content: string,
@@ -22,32 +30,28 @@ export interface CommentThreadMessageSchema {
2230
user: UserInfoSchema,
2331
}
2432

33+
export interface DocumentReviewSchema {
34+
id: string,
35+
metadata: {user_id:string, ts:string}, //"ts" is ISO format date string
36+
}
37+
38+
export interface DocumentReviewChangeSchema extends DocumentReviewSchema {
39+
op: {p:number, i?:string, d?:string},
40+
}
41+
42+
export interface DocumentReviewCommentSchema {
43+
op: {p:number, c:string, t:string}, // "c" for quoted text, "t" for thread_id
44+
thread?: CommentThreadSchema, // to be filled in via API call
45+
}
46+
2547
export interface DocumentRangesSchema {
26-
changes: {
27-
id: string,
28-
op: {p:number, i?:string, d?:string},
29-
metadata: {user_id:string, ts:string}, //"ts" is ISO format date string
30-
}[],
31-
comments: {
32-
id: string,
33-
// "c" for quoted text, "t" for threadId
34-
op: {p:number, c:string, t:string},
35-
metadata: {user_id:string, ts:string}, //"ts" is ISO format date string
36-
}[],
48+
changes: DocumentReviewChangeSchema[],
49+
comments: DocumentReviewCommentSchema[],
3750
}
3851

3952
export interface ExtendedResponseSchema extends ResponseSchema {
40-
threads: {[threadId:string]: {
41-
messages: CommentThreadMessageSchema[],
42-
resolved?: boolean,
43-
resolved_at?: string, //ISO format date string
44-
resolved_by_user_id?: string,
45-
resolved_by_user?: UserInfoSchema,
46-
}},
47-
ranges: {
48-
id: string,//document id
49-
ranges: DocumentRangesSchema,
50-
}[],
53+
threads: {[threadId:string]: CommentThreadSchema},
54+
ranges: {[docId:string]: DocumentRangesSchema},
5155
}
5256

5357
export class ExtendedBaseAPI extends BaseAPI {
@@ -78,7 +82,8 @@ export class ExtendedBaseAPI extends BaseAPI {
7882
async getAllDocumentRanges(identity: Identity, project_id: string) {
7983
this.setIdentity(identity);
8084
return await this.request('GET', `project/${project_id}/ranges`, undefined, (res) => {
81-
const ranges = JSON.parse(res!);
85+
const rangeList = JSON.parse(res!) as {id:string, ranges:DocumentRangesSchema}[];
86+
const ranges = Object.assign({}, ...rangeList.map((r) => ({[r.id]: r.ranges})));
8287
return {ranges};
8388
}) as ExtendedResponseSchema;
8489
}

src/collaboration/clientManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SocketIOAPI, UpdateUserSchema } from '../api/socketio';
55
import { VirtualFileSystem } from '../core/remoteFileSystemProvider';
66
import { ChatViewProvider } from './chatViewProvider';
77
import { LocalReplicaSCMProvider } from '../scm/localReplicaSCM';
8+
import { ReviewPanelProvider } from './reviewPanelProvider';
89

910
interface ExtendedUpdateUserSchema extends UpdateUserSchema {
1011
selection?: {
@@ -59,6 +60,7 @@ export class ClientManager {
5960
private readonly onlineUsers: {[K:string]:ExtendedUpdateUserSchema} = {};
6061
private connectedFlag: boolean = true;
6162
private readonly chatViewer: ChatViewProvider;
63+
private readonly reviewPanel: ReviewPanelProvider;
6264

6365
constructor(
6466
private readonly vfs: VirtualFileSystem,
@@ -101,6 +103,7 @@ export class ClientManager {
101103
});
102104

103105
this.chatViewer = new ChatViewProvider(this.vfs, this.publicId, this.context.extensionUri, this.socket);
106+
this.reviewPanel = new ReviewPanelProvider(this.vfs, this.context, this.socket);
104107
this.status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
105108
this.updateStatus();
106109
}
@@ -376,6 +379,8 @@ export class ClientManager {
376379
}),
377380
// register chat view provider
378381
...this.chatViewer.triggers,
382+
// register review panel provider
383+
...this.reviewPanel.triggers,
379384
// update this client's position
380385
vscode.window.onDidChangeTextEditorSelection(async e => {
381386
if (e.kind===undefined) { return; }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as vscode from 'vscode';
2+
import { VirtualFileSystem } from '../core/remoteFileSystemProvider';
3+
import { SocketIOAPI } from '../api/socketio';
4+
import { DocumentRangesSchema } from '../api/extendedBase';
5+
6+
const reviewOpenCommentDecorationOption: vscode.DecorationRenderOptions = {
7+
// backgroundColor: 'rgba(243, 177, 17, 0.3)',
8+
backgroundColor: new vscode.ThemeColor('editor.hoverHighlightBackground'),
9+
gutterIconPath: 'resources/gutter-comment-unresolved.svg',
10+
};
11+
12+
const reviewResolvedCommentDecorationOption: vscode.DecorationRenderOptions = {
13+
gutterIconPath: 'resources/gutter-pass.svg',
14+
};
15+
16+
const reviewInsertChangeDecorationOption: vscode.DecorationRenderOptions = {
17+
// color: 'rgba(44, 142, 48, 0.3)',
18+
backgroundColor: new vscode.ThemeColor('diffEditor.insertedTextBackground'),
19+
gutterIconPath: 'resources/gutter-edit.svg',
20+
};
21+
22+
const reviewDeleteChangeDecorationOption: vscode.DecorationRenderOptions = {
23+
// color: 'rgba(197, 6, 11, 1.0)',
24+
fontStyle: 'text-decoration: line-through;',
25+
backgroundColor: new vscode.ThemeColor('diffEditor.removedTextBackground'),
26+
gutterIconPath: 'resources/gutter-edit.svg',
27+
};
28+
29+
function fixGutterIconAbsolutePaths(context: vscode.ExtensionContext) {
30+
for (const option of [
31+
reviewOpenCommentDecorationOption,
32+
reviewResolvedCommentDecorationOption,
33+
reviewInsertChangeDecorationOption,
34+
reviewDeleteChangeDecorationOption
35+
]) {
36+
if (option.gutterIconPath) {
37+
option.gutterIconPath = context.asAbsolutePath(option.gutterIconPath as string);
38+
}
39+
}
40+
}
41+
42+
export class ReviewPanelProvider {
43+
private reviewRecords?: {[docId:string]: DocumentRangesSchema};
44+
45+
constructor(
46+
private readonly vfs: VirtualFileSystem,
47+
private readonly context: vscode.ExtensionContext,
48+
private readonly socket: SocketIOAPI,
49+
) {
50+
// init review records
51+
}
52+
53+
private updateReviewDecorations() {
54+
55+
}
56+
57+
get triggers() {
58+
return [
59+
60+
];
61+
}
62+
}

src/core/remoteFileSystemProvider.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,24 @@ export class VirtualFileSystem extends vscode.Disposable {
11781178
return false;
11791179
}
11801180
}
1181+
1182+
async getAllDocumentReviews() {
1183+
const identity = await GlobalStateManager.authenticate(this.context, this.serverName);
1184+
const rangesRes = await (this.api as ExtendedBaseAPI).getAllDocumentRanges(identity, this.projectId);
1185+
if (rangesRes.type==='success') {
1186+
const threadsRes = await (this.api as ExtendedBaseAPI).getAllCommentThreads(identity, this.projectId);
1187+
if (threadsRes.type==='success') {
1188+
for (const range of Object.values(rangesRes.ranges)) {
1189+
for (const comment of range.comments) {
1190+
comment.thread = threadsRes.threads[comment.op.t];
1191+
}
1192+
}
1193+
return rangesRes.ranges;
1194+
}
1195+
}
1196+
1197+
return undefined;
1198+
}
11811199
}
11821200

11831201
export class RemoteFileSystemProvider implements vscode.FileSystemProvider {

0 commit comments

Comments
 (0)