Skip to content

Commit dfc9203

Browse files
author
iamhyc
committed
chore(temp): init integration
1 parent 234c752 commit dfc9203

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
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/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: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import * as vscode from 'vscode';
2+
import { VirtualFileSystem } from '../core/remoteFileSystemProvider';
3+
import { SocketIOAPI } from '../api/socketio';
4+
import { CommentThreadSchema, 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+
private reviewThreads?: {[threadId:string]: CommentThreadSchema};
45+
46+
constructor(
47+
private readonly vfs: VirtualFileSystem,
48+
readonly context: vscode.ExtensionContext,
49+
private readonly socket: SocketIOAPI,
50+
) {
51+
fixGutterIconAbsolutePaths(context);
52+
// init review records
53+
this.vfs.getAllDocumentReviews().then((records) => {
54+
const {ranges,threads} = records!;
55+
this.reviewRecords = ranges;
56+
this.reviewThreads = threads;
57+
this.refreshReviewDecorations();
58+
this.registerEventHandlers();
59+
});
60+
}
61+
62+
private registerEventHandlers() {
63+
this.socket.updateEventHandlers({
64+
onCommentThreadResolved: (threadId, userInfo) => {
65+
const thread = this.reviewThreads![threadId];
66+
if (thread) {
67+
thread.resolved = true;
68+
thread.resolved_by_user = userInfo;
69+
thread.resolved_at = new Date().toISOString();
70+
this.refreshReviewDecorations(thread.doc_id);
71+
}
72+
},
73+
onCommentThreadReopen: (threadId) => {
74+
const thread = this.reviewThreads![threadId];
75+
if (thread) {
76+
thread.resolved = false;
77+
thread.resolved_by_user = undefined;
78+
thread.resolved_at = undefined;
79+
this.refreshReviewDecorations(thread.doc_id);
80+
}
81+
},
82+
onCommentThreadDeleted: (threadId) => {
83+
const thread = this.reviewThreads![threadId];
84+
if (thread) {
85+
delete this.reviewThreads![threadId];
86+
this.refreshReviewDecorations(thread.doc_id);
87+
}
88+
},
89+
onCommentThreadMessageCreated: (threadId, message) => {
90+
const thread = this.reviewThreads![threadId];
91+
if (thread) {
92+
thread.messages.push(message);
93+
this.refreshReviewDecorations(thread.doc_id);
94+
} else {
95+
this.reviewThreads![threadId] = {
96+
messages: [message],
97+
};
98+
}
99+
},
100+
onCommentThreadMessageEdited: (threadId, messageId, message) => {
101+
const thread = this.reviewThreads![threadId];
102+
if (thread) {
103+
const index = thread.messages.findIndex((m) => m.id === messageId);
104+
if (index !== -1) {
105+
thread.messages[index].content = message;
106+
this.refreshReviewDecorations(thread.doc_id);
107+
}
108+
}
109+
},
110+
//
111+
onFileChanged: (update) => {
112+
if (update.op===undefined) { return; }
113+
// update review comment thread
114+
if (update.op[0].t !== undefined) {
115+
116+
}
117+
// update review track changes
118+
if (update?.meta?.tc !== undefined) {
119+
const docId = update.doc;
120+
const ranges = this.reviewRecords![docId];
121+
if (ranges) {
122+
for (const op of update.op) {
123+
ranges.changes.push({
124+
id: update.meta.tc,
125+
op,
126+
metadata: {
127+
// eslint-disable-next-line @typescript-eslint/naming-convention
128+
user_id: '', ts: new Date().toISOString(),
129+
}
130+
});
131+
}
132+
}
133+
}
134+
},
135+
});
136+
}
137+
138+
private refreshReviewDecorations(docId?: string) {
139+
140+
}
141+
142+
get triggers() {
143+
return [];
144+
}
145+
}

0 commit comments

Comments
 (0)