@opensumi/ide-comments 3.0.5-next-1717473339.0 → 3.0.5-next-1717486612.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/comments-item.view.d.ts.map +1 -1
- package/lib/browser/comments-item.view.js +2 -6
- package/lib/browser/comments-item.view.js.map +1 -1
- package/lib/browser/comments-thread.d.ts +1 -3
- package/lib/browser/comments-thread.d.ts.map +1 -1
- package/lib/browser/comments-thread.js +2 -36
- package/lib/browser/comments-thread.js.map +1 -1
- package/lib/browser/comments-zone.service.d.ts +0 -2
- package/lib/browser/comments-zone.service.d.ts.map +1 -1
- package/lib/browser/comments-zone.service.js +0 -8
- package/lib/browser/comments-zone.service.js.map +1 -1
- package/lib/browser/comments-zone.view.d.ts.map +1 -1
- package/lib/browser/comments-zone.view.js +3 -15
- package/lib/browser/comments-zone.view.js.map +1 -1
- package/lib/browser/comments.module.less +16 -81
- package/lib/browser/comments.service.d.ts +0 -29
- package/lib/browser/comments.service.d.ts.map +1 -1
- package/lib/browser/comments.service.js +44 -508
- package/lib/browser/comments.service.js.map +1 -1
- package/lib/common/index.d.ts +0 -9
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js.map +1 -1
- package/package.json +10 -10
- package/src/browser/comments-item.view.tsx +1 -6
- package/src/browser/comments-thread.ts +3 -22
- package/src/browser/comments-zone.service.ts +0 -9
- package/src/browser/comments-zone.view.tsx +3 -29
- package/src/browser/comments.module.less +16 -81
- package/src/browser/comments.service.ts +58 -593
- package/src/common/index.ts +0 -9
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommentsService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const debounce_1 = tslib_1.__importDefault(require("lodash/debounce"));
|
|
5
6
|
const flattenDeep_1 = tslib_1.__importDefault(require("lodash/flattenDeep"));
|
|
6
7
|
const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
|
|
7
8
|
const di_1 = require("@opensumi/di");
|
|
@@ -9,7 +10,6 @@ const ide_core_browser_1 = require("@opensumi/ide-core-browser");
|
|
|
9
10
|
const browser_1 = require("@opensumi/ide-editor/lib/browser");
|
|
10
11
|
const ide_main_layout_1 = require("@opensumi/ide-main-layout");
|
|
11
12
|
const ide_monaco_1 = require("@opensumi/ide-monaco");
|
|
12
|
-
const monaco = tslib_1.__importStar(require("@opensumi/ide-monaco"));
|
|
13
13
|
const browser_2 = require("@opensumi/ide-monaco/lib/browser");
|
|
14
14
|
const ide_theme_1 = require("@opensumi/ide-theme");
|
|
15
15
|
const textModel = tslib_1.__importStar(require("@opensumi/monaco-editor-core/esm/vs/editor/common/model/textModel"));
|
|
@@ -24,20 +24,13 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
24
24
|
this.threads = new Map();
|
|
25
25
|
this.threadsChangeEmitter = new ide_core_browser_1.Emitter();
|
|
26
26
|
this.threadsCommentChangeEmitter = new ide_core_browser_1.Emitter();
|
|
27
|
-
this.commentRangeProviderChangeEmitter = new ide_core_browser_1.Emitter();
|
|
28
|
-
this.onDidChangeCurrentCommentThreadEmitter = new ide_core_browser_1.Emitter();
|
|
29
27
|
this.threadsCreatedEmitter = new ide_core_browser_1.Emitter();
|
|
30
28
|
this.rangeProviderMap = new Map();
|
|
31
29
|
this.rangeOwner = new Map();
|
|
32
30
|
this.providerDecorationCache = new ide_core_browser_1.LRUCache(10000);
|
|
33
|
-
this.commentRangeDecorationMap = new Map();
|
|
34
31
|
// 默认在 file 协议和 git 协议中显示评论数据
|
|
35
|
-
this.shouldShowCommentsSchemes = new Set(['file', 'git'
|
|
32
|
+
this.shouldShowCommentsSchemes = new Set(['file', 'git']);
|
|
36
33
|
this.decorationProviderDisposer = ide_core_browser_1.Disposable.NULL;
|
|
37
|
-
this.activeThreadDecorationIds = [];
|
|
38
|
-
this.allEditors = [];
|
|
39
|
-
this.editorCommentingRangeSpaceReservedMap = new Map();
|
|
40
|
-
this.editorLineDecorationsWidthMap = new Map();
|
|
41
34
|
}
|
|
42
35
|
get commentsThreads() {
|
|
43
36
|
return [...this.threads.values()];
|
|
@@ -63,15 +56,6 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
63
56
|
get onThreadsCreated() {
|
|
64
57
|
return this.threadsCreatedEmitter.event;
|
|
65
58
|
}
|
|
66
|
-
get onCommentRangeProviderChange() {
|
|
67
|
-
return this.commentRangeProviderChangeEmitter.event;
|
|
68
|
-
}
|
|
69
|
-
get onDidChangeCurrentCommentThread() {
|
|
70
|
-
return this.onDidChangeCurrentCommentThreadEmitter.event;
|
|
71
|
-
}
|
|
72
|
-
setCurrentCommentThread(thread) {
|
|
73
|
-
this.onDidChangeCurrentCommentThreadEmitter.fire(thread);
|
|
74
|
-
}
|
|
75
59
|
/**
|
|
76
60
|
* -------------------------------- IMPORTANT --------------------------------
|
|
77
61
|
* 需要注意区分 model.IModelDecorationOptions 与 monaco.editor.IModelDecorationOptions 两个类型
|
|
@@ -86,78 +70,19 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
86
70
|
// 对于新增的空的 thread,默认显示当前用户的头像,否则使用第一个用户的头像
|
|
87
71
|
const avatar = thread.comments.length === 0 ? this.currentAuthorAvatar : (_a = thread.comments[0].author.iconPath) === null || _a === void 0 ? void 0 : _a.toString();
|
|
88
72
|
const icon = avatar
|
|
89
|
-
?
|
|
90
|
-
: this.iconService.fromString('$(comment)');
|
|
73
|
+
? this.iconService.fromIcon('', avatar, ide_theme_1.IconType.Background)
|
|
74
|
+
: this.iconService.fromString('$(comment-unresolved)');
|
|
91
75
|
const decorationOptions = {
|
|
92
76
|
description: 'comments-thread-decoration',
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
: ['comment-range', 'comment-thread', icon].join(' '),
|
|
96
|
-
};
|
|
97
|
-
return textModel.ModelDecorationOptions.createDynamic(decorationOptions);
|
|
98
|
-
}
|
|
99
|
-
updateActiveThreadDecoration(thread) {
|
|
100
|
-
var _a;
|
|
101
|
-
const editor = this.getCurrentEditor(thread === null || thread === void 0 ? void 0 : thread.uri);
|
|
102
|
-
if (!editor) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
(_a = this.currentThreadCollapseStateListener) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
106
|
-
const newDecoration = [];
|
|
107
|
-
if (thread) {
|
|
108
|
-
const range = thread.range;
|
|
109
|
-
if (!thread.isCollapsed) {
|
|
110
|
-
this.currentThreadCollapseStateListener = thread.onDidChangeCollapsibleState((state) => {
|
|
111
|
-
if (state === common_1.CommentThreadCollapsibleState.Collapsed) {
|
|
112
|
-
this.updateActiveThreadDecoration(undefined);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
newDecoration.push({
|
|
116
|
-
range,
|
|
117
|
-
options: this.createThreadRangeActiveDecoration(),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
this.activeThreadDecorationIds = editor.monacoEditor.deltaDecorations(this.activeThreadDecorationIds, newDecoration);
|
|
122
|
-
}
|
|
123
|
-
createDottedRangeDecoration() {
|
|
124
|
-
const decorationOptions = {
|
|
125
|
-
description: 'comments-multiline-hover-decoration',
|
|
126
|
-
linesDecorationsClassName: ['comment-range', 'multiline-add'].join(' '),
|
|
77
|
+
// 创建评论显示在 glyph margin 处
|
|
78
|
+
glyphMarginClassName: ['comments-decoration', 'comments-thread', icon].join(' '),
|
|
127
79
|
};
|
|
128
80
|
return textModel.ModelDecorationOptions.createDynamic(decorationOptions);
|
|
129
81
|
}
|
|
130
82
|
createHoverDecoration() {
|
|
131
83
|
const decorationOptions = {
|
|
132
84
|
description: 'comments-hover-decoration',
|
|
133
|
-
linesDecorationsClassName: ['
|
|
134
|
-
};
|
|
135
|
-
return textModel.ModelDecorationOptions.createDynamic(decorationOptions);
|
|
136
|
-
}
|
|
137
|
-
createThreadRangeActiveDecoration() {
|
|
138
|
-
const activeDecorationOptions = {
|
|
139
|
-
description: 'comments-thread-range-active-decoration',
|
|
140
|
-
isWholeLine: false,
|
|
141
|
-
zIndex: 20,
|
|
142
|
-
className: 'comment-thread-range-current',
|
|
143
|
-
shouldFillLineOnLineBreak: true,
|
|
144
|
-
};
|
|
145
|
-
return textModel.ModelDecorationOptions.createDynamic(activeDecorationOptions);
|
|
146
|
-
}
|
|
147
|
-
createThreadRangeDecoration() {
|
|
148
|
-
const activeDecorationOptions = {
|
|
149
|
-
description: 'comments-thread-range-decoration',
|
|
150
|
-
isWholeLine: false,
|
|
151
|
-
zIndex: 20,
|
|
152
|
-
className: 'comment-thread-range',
|
|
153
|
-
shouldFillLineOnLineBreak: true,
|
|
154
|
-
};
|
|
155
|
-
return textModel.ModelDecorationOptions.createDynamic(activeDecorationOptions);
|
|
156
|
-
}
|
|
157
|
-
createCommentRangeDecoration() {
|
|
158
|
-
const decorationOptions = {
|
|
159
|
-
description: 'comments-range-decoration',
|
|
160
|
-
linesDecorationsClassName: ['comment-range', 'comment-diff-added'].join(' '),
|
|
85
|
+
linesDecorationsClassName: ['comments-decoration', 'comments-add', (0, ide_core_browser_1.getIcon)('add-comments')].join(' '),
|
|
161
86
|
};
|
|
162
87
|
return textModel.ModelDecorationOptions.createDynamic(decorationOptions);
|
|
163
88
|
}
|
|
@@ -182,43 +107,34 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
182
107
|
}));
|
|
183
108
|
this.registerDecorationProvider();
|
|
184
109
|
}
|
|
185
|
-
getCurrentEditor(uri) {
|
|
186
|
-
var _a;
|
|
187
|
-
if (uri) {
|
|
188
|
-
for (const editor of this.allEditors) {
|
|
189
|
-
if ((_a = editor.currentUri) === null || _a === void 0 ? void 0 : _a.isEqual(uri)) {
|
|
190
|
-
this.editor = editor;
|
|
191
|
-
return editor;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return this.editor;
|
|
196
|
-
}
|
|
197
110
|
handleOnCreateEditor(editor) {
|
|
198
|
-
this.allEditors.push(editor);
|
|
199
|
-
this.editor = editor;
|
|
200
111
|
const disposer = new ide_core_browser_1.Disposable();
|
|
201
|
-
let commentRangeDecorationIds = [];
|
|
202
|
-
let hasHiddenArea = false;
|
|
203
112
|
disposer.addDispose(editor.monacoEditor.onMouseDown((event) => {
|
|
204
113
|
if (event.target.type === browser_2.monacoBrowser.editor.MouseTargetType.GUTTER_LINE_DECORATIONS &&
|
|
205
114
|
event.target.element &&
|
|
206
|
-
event.target.element.className.indexOf('
|
|
115
|
+
event.target.element.className.indexOf('comments-add') > -1) {
|
|
207
116
|
const { target } = event;
|
|
208
117
|
if (target && target.range) {
|
|
209
118
|
const { range } = target;
|
|
210
|
-
|
|
119
|
+
// 如果已经存在一个待输入的评论组件,则不创建新的
|
|
120
|
+
if (!this.commentsThreads.some((thread) => thread.comments.length === 0 &&
|
|
121
|
+
thread.uri.isEqual(editor.currentUri) &&
|
|
122
|
+
thread.range.startLineNumber === range.startLineNumber)) {
|
|
123
|
+
const thread = this.createThread(editor.currentUri, range);
|
|
124
|
+
thread.show(editor);
|
|
125
|
+
}
|
|
211
126
|
event.event.stopPropagation();
|
|
212
127
|
}
|
|
213
128
|
}
|
|
214
129
|
else if (event.target.type === browser_2.monacoBrowser.editor.MouseTargetType.GUTTER_GLYPH_MARGIN &&
|
|
215
130
|
event.target.element &&
|
|
216
|
-
event.target.element.className.indexOf('
|
|
131
|
+
event.target.element.className.indexOf('comments-thread') > -1) {
|
|
217
132
|
const { target } = event;
|
|
218
133
|
if (target && target.range) {
|
|
219
134
|
const { range } = target;
|
|
220
|
-
const threads = this.commentsThreads.filter((thread) => thread.uri.isEqual(editor.currentUri) && thread.range.
|
|
135
|
+
const threads = this.commentsThreads.filter((thread) => thread.uri.isEqual(editor.currentUri) && thread.range.startLineNumber === range.startLineNumber);
|
|
221
136
|
if (threads.length) {
|
|
137
|
+
// 判断当前 widget 是否是显示的
|
|
222
138
|
const isShowWidget = threads.some((thread) => thread.isShowWidget(editor));
|
|
223
139
|
if (isShowWidget) {
|
|
224
140
|
threads.forEach((thread) => thread.hide(editor));
|
|
@@ -231,412 +147,45 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
231
147
|
event.event.stopPropagation();
|
|
232
148
|
}
|
|
233
149
|
}));
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (hasHiddenArea) {
|
|
237
|
-
this.renderCommentRange(editor);
|
|
238
|
-
hasHiddenArea = false;
|
|
239
|
-
this.startCommentRange = null;
|
|
240
|
-
this.endCommentRange = null;
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
let range = this.startCommentRange;
|
|
244
|
-
if (this.endCommentRange) {
|
|
245
|
-
if (this.endCommentRange.startLineNumber < this.startCommentRange.startLineNumber) {
|
|
246
|
-
range.startColumn = this.endCommentRange.startColumn;
|
|
247
|
-
range.startLineNumber = this.endCommentRange.startLineNumber;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
range.endColumn = this.endCommentRange.endColumn;
|
|
251
|
-
range.endLineNumber = this.endCommentRange.endLineNumber;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (editor.currentUri) {
|
|
255
|
-
range = await this.getValidRange(range, editor.currentUri);
|
|
256
|
-
}
|
|
257
|
-
if (range) {
|
|
258
|
-
if (!this.commentsThreads.some((thread) => thread.comments.length === 0 &&
|
|
259
|
-
thread.uri.isEqual(editor.currentUri) &&
|
|
260
|
-
thread.range.startLineNumber === range.startLineNumber &&
|
|
261
|
-
thread.range.endLineNumber === range.endLineNumber)) {
|
|
262
|
-
const thread = this.createThread(editor.currentUri, range);
|
|
263
|
-
thread.show(editor);
|
|
264
|
-
}
|
|
265
|
-
event.event.stopPropagation();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else if (event.target.type === browser_2.monacoBrowser.editor.MouseTargetType.GUTTER_LINE_DECORATIONS &&
|
|
269
|
-
event.target.element &&
|
|
270
|
-
event.target.element.className.indexOf('comment-range') > -1 &&
|
|
271
|
-
event.target.element.className.indexOf('comment-thread') < 0) {
|
|
272
|
-
const { target } = event;
|
|
273
|
-
const range = target.range;
|
|
274
|
-
if (range) {
|
|
275
|
-
if (!this.commentsThreads.some((thread) => thread.comments.length === 0 &&
|
|
276
|
-
thread.uri.isEqual(editor.currentUri) &&
|
|
277
|
-
thread.range.startLineNumber === range.startLineNumber &&
|
|
278
|
-
thread.range.endLineNumber === range.endLineNumber)) {
|
|
279
|
-
const thread = this.createThread(editor.currentUri, range);
|
|
280
|
-
thread.show(editor);
|
|
281
|
-
}
|
|
282
|
-
event.event.stopPropagation();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
this.startCommentRange = null;
|
|
286
|
-
this.endCommentRange = null;
|
|
287
|
-
}));
|
|
288
|
-
disposer.addDispose(editor.monacoEditor.onMouseMove(async (event) => {
|
|
289
|
-
var _a, _b, _c;
|
|
150
|
+
let oldDecorations = [];
|
|
151
|
+
disposer.addDispose(editor.monacoEditor.onMouseMove((0, debounce_1.default)(async (event) => {
|
|
290
152
|
const uri = editor.currentUri;
|
|
291
153
|
const range = event.target.range;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
if (uri && range) {
|
|
301
|
-
let selection = {
|
|
302
|
-
startLineNumber: this.startCommentRange.startLineNumber,
|
|
303
|
-
endLineNumber: range.endLineNumber,
|
|
304
|
-
startColumn: this.startCommentRange.startColumn,
|
|
305
|
-
endColumn: range.endColumn,
|
|
306
|
-
};
|
|
307
|
-
if (this.startCommentRange.startLineNumber > range.startLineNumber) {
|
|
308
|
-
selection = {
|
|
309
|
-
startLineNumber: range.startLineNumber,
|
|
310
|
-
endLineNumber: this.startCommentRange.endLineNumber,
|
|
311
|
-
startColumn: range.startColumn,
|
|
312
|
-
endColumn: this.startCommentRange.endColumn,
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
this.renderCommentRange(editor, selection);
|
|
316
|
-
this.endCommentRange = range;
|
|
317
|
-
}
|
|
154
|
+
if (uri && range && (await this.shouldShowHoverDecoration(uri, range))) {
|
|
155
|
+
oldDecorations = editor.monacoEditor.deltaDecorations(oldDecorations, [
|
|
156
|
+
{
|
|
157
|
+
range: (0, ide_monaco_1.positionToRange)(range.startLineNumber),
|
|
158
|
+
options: this.createHoverDecoration(),
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
318
161
|
}
|
|
319
162
|
else {
|
|
320
|
-
|
|
321
|
-
const newDecorations = [
|
|
322
|
-
{
|
|
323
|
-
range: (0, ide_monaco_1.positionToRange)(range.startLineNumber),
|
|
324
|
-
options: this.createHoverDecoration(),
|
|
325
|
-
},
|
|
326
|
-
];
|
|
327
|
-
commentRangeDecorationIds = editor.monacoEditor.deltaDecorations(commentRangeDecorationIds, newDecorations);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}));
|
|
331
|
-
disposer.addDispose(editor.monacoEditor.onMouseLeave(async (event) => {
|
|
332
|
-
var _a;
|
|
333
|
-
const range = (_a = event.target) === null || _a === void 0 ? void 0 : _a.range;
|
|
334
|
-
const newDecorations = [];
|
|
335
|
-
if (!this.startCommentRange && range) {
|
|
336
|
-
newDecorations.push({
|
|
337
|
-
range: (0, ide_monaco_1.positionToRange)(range.startLineNumber),
|
|
338
|
-
options: this.createCommentRangeDecoration(),
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
commentRangeDecorationIds = editor.monacoEditor.deltaDecorations(commentRangeDecorationIds, newDecorations);
|
|
342
|
-
}));
|
|
343
|
-
disposer.addDispose(this.onCommentRangeProviderChange(() => {
|
|
344
|
-
this.renderCommentRange(editor);
|
|
345
|
-
}));
|
|
346
|
-
disposer.addDispose(ide_core_browser_1.Event.any(this.onThreadsChanged, this.onThreadsCommentChange, this.onThreadsCreated)((thread) => {
|
|
347
|
-
const editor = this.getCurrentEditor(thread.uri);
|
|
348
|
-
if (editor) {
|
|
349
|
-
this.renderCommentRange(editor);
|
|
163
|
+
oldDecorations = editor.monacoEditor.deltaDecorations(oldDecorations, []);
|
|
350
164
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}));
|
|
356
|
-
this.tryUpdateReservedSpace(editor);
|
|
357
|
-
disposer.addDispose(editor.monacoEditor.onDidChangeModel(() => {
|
|
358
|
-
this.renderCommentRange(editor);
|
|
359
|
-
this.tryUpdateReservedSpace(editor);
|
|
360
|
-
}));
|
|
165
|
+
}, 10)));
|
|
166
|
+
disposer.addDispose(editor.monacoEditor.onMouseLeave((0, debounce_1.default)(() => {
|
|
167
|
+
oldDecorations = editor.monacoEditor.deltaDecorations(oldDecorations, []);
|
|
168
|
+
}, 10)));
|
|
361
169
|
return disposer;
|
|
362
170
|
}
|
|
363
|
-
async getValidRange(range, uri) {
|
|
364
|
-
if (!uri) {
|
|
365
|
-
return range;
|
|
366
|
-
}
|
|
367
|
-
const contributionRanges = await this.getContributionRanges(uri);
|
|
368
|
-
if (contributionRanges.length === 0) {
|
|
369
|
-
return range;
|
|
370
|
-
}
|
|
371
|
-
const validRange = contributionRanges.find((contributionRange) => {
|
|
372
|
-
if (range.startLineNumber >= contributionRange.startLineNumber &&
|
|
373
|
-
range.startLineNumber <= contributionRange.endLineNumber) {
|
|
374
|
-
return true;
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
if (validRange) {
|
|
378
|
-
if (validRange.endLineNumber < range.endLineNumber) {
|
|
379
|
-
return {
|
|
380
|
-
startLineNumber: range.startLineNumber,
|
|
381
|
-
startColumn: range.startColumn,
|
|
382
|
-
endLineNumber: validRange.endLineNumber,
|
|
383
|
-
endColumn: validRange.endColumn,
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
return range;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
return range;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
ensureCommentingRangeReservedAmount(editor) {
|
|
395
|
-
const existing = this.getExistingCommentEditorOptions(editor);
|
|
396
|
-
const lineDecorationsWidth = this.editorLineDecorationsWidthMap.get(editor.getId());
|
|
397
|
-
if (existing.lineDecorationsWidth !== lineDecorationsWidth) {
|
|
398
|
-
editor.updateOptions({
|
|
399
|
-
lineDecorationsWidth: this.getWithCommentsLineDecorationWidth(editor, existing.lineDecorationsWidth),
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
async tryUpdateReservedSpace(editor) {
|
|
404
|
-
if (!editor) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
let commentingRangeSpaceReserved = this.editorCommentingRangeSpaceReservedMap.get(editor.getId()) || false;
|
|
408
|
-
const shouldShowComments = editor.currentUri ? this.shouldShowCommentsSchemes.has(editor.currentUri.scheme) : false;
|
|
409
|
-
const hasComments = this.commentsThreads.some((thread) => thread.uri.isEqual(editor.currentUri) && thread.comments.length > 0);
|
|
410
|
-
const hasCommentsOrRanges = shouldShowComments || hasComments;
|
|
411
|
-
if (hasCommentsOrRanges) {
|
|
412
|
-
if (!commentingRangeSpaceReserved) {
|
|
413
|
-
commentingRangeSpaceReserved = true;
|
|
414
|
-
const { lineDecorationsWidth, extraEditorClassName } = this.getExistingCommentEditorOptions(editor);
|
|
415
|
-
const newOptions = this.getWithCommentsEditorOptions(editor, extraEditorClassName, lineDecorationsWidth);
|
|
416
|
-
this.updateEditorLayoutOptions(editor, newOptions.extraEditorClassName, newOptions.lineDecorationsWidth);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
this.ensureCommentingRangeReservedAmount(editor);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
else if (!hasCommentsOrRanges && commentingRangeSpaceReserved) {
|
|
423
|
-
commentingRangeSpaceReserved = false;
|
|
424
|
-
const { lineDecorationsWidth, extraEditorClassName } = this.getExistingCommentEditorOptions(editor);
|
|
425
|
-
const newOptions = this.getWithoutCommentsEditorOptions(editor, extraEditorClassName, lineDecorationsWidth);
|
|
426
|
-
this.updateEditorLayoutOptions(editor, newOptions.extraEditorClassName, newOptions.lineDecorationsWidth);
|
|
427
|
-
}
|
|
428
|
-
this.editorCommentingRangeSpaceReservedMap.set(editor.getId(), commentingRangeSpaceReserved);
|
|
429
|
-
}
|
|
430
|
-
getExistingCommentEditorOptions(editor) {
|
|
431
|
-
const lineDecorationsWidth = editor.monacoEditor.getOption(monaco.EditorOption.lineDecorationsWidth);
|
|
432
|
-
let extraEditorClassName = [];
|
|
433
|
-
const configuredExtraClassName = editor.monacoEditor.getRawOptions().extraEditorClassName;
|
|
434
|
-
if (configuredExtraClassName) {
|
|
435
|
-
extraEditorClassName = configuredExtraClassName.split(' ');
|
|
436
|
-
}
|
|
437
|
-
return { lineDecorationsWidth, extraEditorClassName };
|
|
438
|
-
}
|
|
439
|
-
getWithoutCommentsEditorOptions(editor, extraEditorClassName, startingLineDecorationsWidth) {
|
|
440
|
-
let lineDecorationsWidth = startingLineDecorationsWidth;
|
|
441
|
-
const inlineCommentPos = extraEditorClassName.findIndex((name) => name === 'inline-comment');
|
|
442
|
-
if (inlineCommentPos >= 0) {
|
|
443
|
-
extraEditorClassName.splice(inlineCommentPos, 1);
|
|
444
|
-
}
|
|
445
|
-
const options = editor.monacoEditor.getOptions();
|
|
446
|
-
if (options.get(monaco.EditorOption.folding) && options.get(monaco.EditorOption.showFoldingControls) !== 'never') {
|
|
447
|
-
lineDecorationsWidth += 11; // 11 comes from https://github.com/microsoft/vscode/blob/94ee5f58619d59170983f453fe78f156c0cc73a3/src/vs/workbench/contrib/comments/browser/media/review.css#L485
|
|
448
|
-
}
|
|
449
|
-
lineDecorationsWidth -= 24;
|
|
450
|
-
return { extraEditorClassName, lineDecorationsWidth };
|
|
451
|
-
}
|
|
452
|
-
updateEditorLayoutOptions(editor, extraEditorClassName, lineDecorationsWidth) {
|
|
453
|
-
editor.updateOptions({
|
|
454
|
-
extraEditorClassName: extraEditorClassName.join(' '),
|
|
455
|
-
lineDecorationsWidth,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
getWithCommentsEditorOptions(editor, extraEditorClassName, startingLineDecorationsWidth) {
|
|
459
|
-
extraEditorClassName.push('inline-comment');
|
|
460
|
-
return {
|
|
461
|
-
lineDecorationsWidth: this.getWithCommentsLineDecorationWidth(editor, startingLineDecorationsWidth),
|
|
462
|
-
extraEditorClassName,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
getWithCommentsLineDecorationWidth(editor, startingLineDecorationsWidth) {
|
|
466
|
-
let lineDecorationsWidth = startingLineDecorationsWidth;
|
|
467
|
-
const options = editor.monacoEditor.getOptions();
|
|
468
|
-
if (options.get(monaco.EditorOption.folding) && options.get(monaco.EditorOption.showFoldingControls) !== 'never') {
|
|
469
|
-
lineDecorationsWidth -= 11;
|
|
470
|
-
}
|
|
471
|
-
lineDecorationsWidth += 24;
|
|
472
|
-
this.editorLineDecorationsWidthMap.set(editor.getId(), lineDecorationsWidth);
|
|
473
|
-
return lineDecorationsWidth;
|
|
474
|
-
}
|
|
475
|
-
async renderCommentRange(editor, selection = {
|
|
476
|
-
startLineNumber: 0,
|
|
477
|
-
endLineNumber: 0,
|
|
478
|
-
startColumn: 0,
|
|
479
|
-
endColumn: 0,
|
|
480
|
-
}) {
|
|
481
|
-
if (!editor.currentUri) {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const contributionRanges = await this.getContributionRanges(editor.currentUri);
|
|
485
|
-
if (contributionRanges.length > 0) {
|
|
486
|
-
const newDecorations = [];
|
|
487
|
-
contributionRanges.map((contributionRange) => {
|
|
488
|
-
if (selection.startLineNumber === 0 && selection.endLineNumber === 0) {
|
|
489
|
-
newDecorations.push({
|
|
490
|
-
range: contributionRange,
|
|
491
|
-
options: this.createCommentRangeDecoration(),
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
else if (selection.startLineNumber <= contributionRange.startLineNumber &&
|
|
495
|
-
selection.endLineNumber >= contributionRange.endLineNumber) {
|
|
496
|
-
newDecorations.push(...[
|
|
497
|
-
{
|
|
498
|
-
range: contributionRange,
|
|
499
|
-
options: this.createDottedRangeDecoration(),
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
range: contributionRange,
|
|
503
|
-
options: this.createThreadRangeDecoration(),
|
|
504
|
-
},
|
|
505
|
-
]);
|
|
506
|
-
}
|
|
507
|
-
else if (selection.endLineNumber >= contributionRange.endLineNumber) {
|
|
508
|
-
if (selection.startLineNumber <= contributionRange.endLineNumber) {
|
|
509
|
-
// 存在交集
|
|
510
|
-
const selectionRange = {
|
|
511
|
-
startLineNumber: selection.startLineNumber,
|
|
512
|
-
endLineNumber: contributionRange.endLineNumber,
|
|
513
|
-
startColumn: selection.startColumn,
|
|
514
|
-
endColumn: contributionRange.endColumn,
|
|
515
|
-
};
|
|
516
|
-
const topCommentRange = {
|
|
517
|
-
startLineNumber: contributionRange.startLineNumber,
|
|
518
|
-
endLineNumber: selectionRange.startLineNumber - 1,
|
|
519
|
-
startColumn: contributionRange.startColumn,
|
|
520
|
-
endColumn: selectionRange.endColumn,
|
|
521
|
-
};
|
|
522
|
-
newDecorations.push(...[
|
|
523
|
-
{
|
|
524
|
-
range: topCommentRange,
|
|
525
|
-
options: this.createCommentRangeDecoration(),
|
|
526
|
-
},
|
|
527
|
-
{
|
|
528
|
-
range: selectionRange,
|
|
529
|
-
options: this.createDottedRangeDecoration(),
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
range: selectionRange,
|
|
533
|
-
options: this.createThreadRangeDecoration(),
|
|
534
|
-
},
|
|
535
|
-
]);
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
newDecorations.push({
|
|
539
|
-
range: contributionRange,
|
|
540
|
-
options: this.createCommentRangeDecoration(),
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
else if (selection.endLineNumber < contributionRange.endLineNumber) {
|
|
545
|
-
if (selection.endLineNumber >= contributionRange.startLineNumber) {
|
|
546
|
-
// 存在交集
|
|
547
|
-
if (selection.startLineNumber >= contributionRange.startLineNumber) {
|
|
548
|
-
const topCommentRange = {
|
|
549
|
-
startLineNumber: contributionRange.startLineNumber,
|
|
550
|
-
startColumn: contributionRange.startColumn,
|
|
551
|
-
endLineNumber: selection.startLineNumber - 1,
|
|
552
|
-
endColumn: selection.startColumn,
|
|
553
|
-
};
|
|
554
|
-
const bottomCommentRange = {
|
|
555
|
-
startLineNumber: selection.endLineNumber + 1,
|
|
556
|
-
startColumn: selection.endColumn,
|
|
557
|
-
endLineNumber: contributionRange.endLineNumber,
|
|
558
|
-
endColumn: contributionRange.endColumn,
|
|
559
|
-
};
|
|
560
|
-
const decorations = selection.startLineNumber !== contributionRange.startLineNumber
|
|
561
|
-
? [
|
|
562
|
-
{
|
|
563
|
-
range: topCommentRange,
|
|
564
|
-
options: this.createCommentRangeDecoration(),
|
|
565
|
-
},
|
|
566
|
-
]
|
|
567
|
-
: [];
|
|
568
|
-
decorations.push({
|
|
569
|
-
range: selection,
|
|
570
|
-
options: this.createDottedRangeDecoration(),
|
|
571
|
-
});
|
|
572
|
-
decorations.push({
|
|
573
|
-
range: selection,
|
|
574
|
-
options: this.createThreadRangeDecoration(),
|
|
575
|
-
});
|
|
576
|
-
decorations.push({
|
|
577
|
-
range: bottomCommentRange,
|
|
578
|
-
options: this.createCommentRangeDecoration(),
|
|
579
|
-
});
|
|
580
|
-
newDecorations.push(...decorations);
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
const selectionRange = {
|
|
584
|
-
startLineNumber: contributionRange.startLineNumber,
|
|
585
|
-
startColumn: contributionRange.startColumn,
|
|
586
|
-
endLineNumber: selection.endLineNumber,
|
|
587
|
-
endColumn: selection.endColumn,
|
|
588
|
-
};
|
|
589
|
-
const bottomCommentRange = {
|
|
590
|
-
startLineNumber: selectionRange.endLineNumber + 1,
|
|
591
|
-
startColumn: selectionRange.endColumn,
|
|
592
|
-
endLineNumber: contributionRange.endLineNumber,
|
|
593
|
-
endColumn: contributionRange.endColumn,
|
|
594
|
-
};
|
|
595
|
-
newDecorations.push(...[
|
|
596
|
-
{
|
|
597
|
-
range: selectionRange,
|
|
598
|
-
options: this.createDottedRangeDecoration(),
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
range: selectionRange,
|
|
602
|
-
options: this.createThreadRangeDecoration(),
|
|
603
|
-
},
|
|
604
|
-
{
|
|
605
|
-
range: bottomCommentRange,
|
|
606
|
-
options: this.createCommentRangeDecoration(),
|
|
607
|
-
},
|
|
608
|
-
]);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
newDecorations.push({
|
|
613
|
-
range: contributionRange,
|
|
614
|
-
options: this.createCommentRangeDecoration(),
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
const commentRangeDecorationIds = this.commentRangeDecorationMap.get(editor.currentUri.toString()) || [];
|
|
620
|
-
this.commentRangeDecorationMap.set(editor.currentUri.toString(), editor.monacoEditor.deltaDecorations(commentRangeDecorationIds, newDecorations));
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
this.commentRangeDecorationMap.set(editor.currentUri.toString(), []);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
171
|
async shouldShowHoverDecoration(uri, range) {
|
|
627
172
|
if (!this.shouldShowCommentsSchemes.has(uri.scheme)) {
|
|
628
173
|
return false;
|
|
629
174
|
}
|
|
630
175
|
const contributionRanges = await this.getContributionRanges(uri);
|
|
631
|
-
const isProviderRanges = contributionRanges.some((contributionRange) => range.startLineNumber
|
|
632
|
-
|
|
176
|
+
const isProviderRanges = contributionRanges.some((contributionRange) => range.startLineNumber >= contributionRange.startLineNumber &&
|
|
177
|
+
range.startLineNumber <= contributionRange.endLineNumber);
|
|
178
|
+
// 如果不支持对同一行进行多个评论,那么过滤掉当前有 thread 行号的 decoration
|
|
179
|
+
const isShowHoverToSingleLine = this.isMultiCommentsForSingleLine ||
|
|
180
|
+
!this.commentsThreads.some((thread) => thread.uri.isEqual(uri) && thread.range.startLineNumber === range.startLineNumber);
|
|
181
|
+
return isProviderRanges && isShowHoverToSingleLine;
|
|
633
182
|
}
|
|
634
183
|
createThread(uri, range, options = {
|
|
635
184
|
comments: [],
|
|
636
185
|
readOnly: false,
|
|
637
186
|
}) {
|
|
638
187
|
// 获取当前 range 的 providerId,用于 commentController contextKey 的生成
|
|
639
|
-
const providerId = this.getProviderIdsByLine(range.
|
|
188
|
+
const providerId = this.getProviderIdsByLine(range.startLineNumber)[0];
|
|
640
189
|
const thread = this.injector.get(comments_thread_1.CommentsThread, [uri, range, providerId, options]);
|
|
641
190
|
thread.onDispose(() => {
|
|
642
191
|
this.threads.delete(thread.id);
|
|
@@ -677,16 +226,11 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
677
226
|
return childs;
|
|
678
227
|
}
|
|
679
228
|
handleCommentContentNode(parent) {
|
|
680
|
-
var _a;
|
|
681
229
|
const childs = [];
|
|
682
230
|
for (const thread of parent.threads) {
|
|
683
231
|
const [first] = thread.comments;
|
|
684
232
|
const comment = typeof first.body === 'string' ? first.body : first.body.value;
|
|
685
|
-
|
|
686
|
-
if (thread.range.startLineNumber !== thread.range.endLineNumber) {
|
|
687
|
-
description = `[Ln ${thread.range.startLineNumber}-${thread.range.endLineNumber}]`;
|
|
688
|
-
}
|
|
689
|
-
childs.push(new tree_node_defined_1.CommentContentNode(this, thread, comment, description, first.author.iconPath && ((_a = first.author.iconPath) === null || _a === void 0 ? void 0 : _a.authority)
|
|
233
|
+
childs.push(new tree_node_defined_1.CommentContentNode(this, thread, comment, `[Ln ${thread.range.startLineNumber}]`, first.author.iconPath
|
|
690
234
|
? this.iconService.fromIcon('', first.author.iconPath.toString(), ide_theme_1.IconType.Background)
|
|
691
235
|
: (0, ide_core_browser_1.getIcon)('message'), first.author, parent.resource, parent));
|
|
692
236
|
}
|
|
@@ -734,15 +278,12 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
734
278
|
if (cache) {
|
|
735
279
|
return await cache.promise;
|
|
736
280
|
}
|
|
737
|
-
const model = this.documentService.getModelReference(uri, '
|
|
281
|
+
const model = this.documentService.getModelReference(uri, 'get-contribution-rages');
|
|
738
282
|
const rangePromise = [];
|
|
739
283
|
for (const rangeProvider of this.rangeProviderMap) {
|
|
740
284
|
const [id, provider] = rangeProvider;
|
|
741
285
|
rangePromise.push((async () => {
|
|
742
|
-
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
const ranges = await provider.getCommentingRanges(model.instance);
|
|
286
|
+
const ranges = await provider.getCommentingRanges(model === null || model === void 0 ? void 0 : model.instance);
|
|
746
287
|
if (ranges && ranges.length) {
|
|
747
288
|
// FIXME: ranges 会被 Diff uri 的两个 range 互相覆盖,导致可能根据行查不到 provider
|
|
748
289
|
this.rangeOwner.set(id, ranges);
|
|
@@ -792,12 +333,7 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
792
333
|
return isCurrentThread;
|
|
793
334
|
})
|
|
794
335
|
.map((thread) => ({
|
|
795
|
-
range:
|
|
796
|
-
startLineNumber: thread.range.endLineNumber,
|
|
797
|
-
endLineNumber: thread.range.endLineNumber,
|
|
798
|
-
startColumn: thread.range.endColumn,
|
|
799
|
-
endColumn: thread.range.endColumn,
|
|
800
|
-
},
|
|
336
|
+
range: thread.range,
|
|
801
337
|
options: this.createThreadDecoration(thread),
|
|
802
338
|
})),
|
|
803
339
|
});
|
|
@@ -823,7 +359,6 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
823
359
|
this.rangeProviderMap.set(id, provider);
|
|
824
360
|
// 注册一个新的 range provider 后清理掉之前的缓存
|
|
825
361
|
this.providerDecorationCache.clear();
|
|
826
|
-
this.commentRangeProviderChangeEmitter.fire();
|
|
827
362
|
return ide_core_browser_1.Disposable.create(() => {
|
|
828
363
|
this.rangeProviderMap.delete(id);
|
|
829
364
|
this.rangeOwner.delete(id);
|
|
@@ -843,6 +378,7 @@ let CommentsService = class CommentsService extends ide_core_browser_1.Disposabl
|
|
|
843
378
|
getProviderIdsByLine(line) {
|
|
844
379
|
const result = [];
|
|
845
380
|
if (this.rangeOwner.size === 1) {
|
|
381
|
+
// 只有一个provider,直接返回
|
|
846
382
|
return [this.rangeOwner.keys().next().value];
|
|
847
383
|
}
|
|
848
384
|
for (const rangeOwner of this.rangeOwner) {
|