Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
73dccf2
feat: support comments on multi diff view
erha19 May 21, 2025
5eea198
refactor: implement BaseMonacoEditorWrapper and DiffEditorPart for en…
erha19 May 21, 2025
b65f15a
feat: support lazy load comments with multi-diff view
erha19 May 22, 2025
c124028
chore: fix build
erha19 May 22, 2025
6d56838
Merge branch 'main' of github.com:opensumi/core into feat/support-com…
erha19 May 22, 2025
c237be2
feat: improve style and comment attatch
erha19 May 22, 2025
bac3371
chore: fix build
erha19 May 22, 2025
cf87b54
chore: export multi-diff api
erha19 May 23, 2025
2e0fba3
chore: fix build
erha19 May 23, 2025
d89d11d
feat: improve comments rendered
erha19 May 28, 2025
ff3db69
fix: comments visibility
erha19 Jun 6, 2025
aec0be9
chore: update editor handler
erha19 Jun 6, 2025
c1cc694
feat: support update docuemt model for diff edit part
erha19 Jun 9, 2025
862246b
fix: multi comment rendered
erha19 Jun 10, 2025
584d5f4
chore: fix comments service
erha19 Jun 10, 2025
8cdbaa5
Merge branch 'main' of github.com:opensumi/core into feat/support-com…
erha19 Jun 10, 2025
ce4ec15
style: improve scroller style and add reval function
erha19 Jun 10, 2025
10cc145
chore: add resource label metadata
erha19 Jun 10, 2025
f4f48c4
chore: fix types
erha19 Jun 10, 2025
351a757
chore: update relative path
erha19 Jun 10, 2025
5fed70d
chore: update icon color
erha19 Jun 10, 2025
93aaad1
chore: delay comments display
erha19 Jun 11, 2025
7c47904
chore: fix tests
erha19 Jun 11, 2025
da828d5
chore: fix typos
erha19 Jun 11, 2025
88e04dd
chore: fix test
erha19 Jun 12, 2025
0dc8033
chore: fix test
erha19 Jun 12, 2025
4c2d124
chore: fix comment update
erha19 Jun 12, 2025
2e96dc0
fix: comment range rendered
erha19 Jun 12, 2025
ae16f99
chore: fix comments
erha19 Jun 13, 2025
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
2 changes: 1 addition & 1 deletion packages/ai-native/src/browser/components/ChatEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
localize,
runWhenIdle,
} from '@opensumi/ide-core-common';
import { insertSnippetWithMonacoEditor } from '@opensumi/ide-editor/lib/browser/editor-collection.service';
import { insertSnippetWithMonacoEditor } from '@opensumi/ide-editor/lib/browser/base-editor-wrapper';
import { MonacoCommandRegistry } from '@opensumi/ide-editor/lib/browser/monaco-contrib/command/command.service';
import { ITheme, IThemeService } from '@opensumi/ide-theme';
import { WorkbenchThemeService } from '@opensumi/ide-theme/lib/browser/workbench.theme.service';
Expand Down
9 changes: 8 additions & 1 deletion packages/comments/__test__/browser/comment-thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Injector } from '@opensumi/di';
import { IContextKeyService } from '@opensumi/ide-core-browser';
import { URI } from '@opensumi/ide-core-common';
import { createBrowserInjector } from '@opensumi/ide-dev-tool/src/injector-helper';
import { MockInjector } from '@opensumi/ide-dev-tool/src/mock-injector';
import { MockInjector, mockService } from '@opensumi/ide-dev-tool/src/mock-injector';
import { EditorCollectionService } from '@opensumi/ide-editor';
import { positionToRange } from '@opensumi/ide-monaco';
import { createMockedMonaco } from '@opensumi/ide-monaco/__mocks__/monaco';
import { MockContextKeyService } from '@opensumi/ide-monaco/__mocks__/monaco.context-key.service';
Expand All @@ -28,6 +29,12 @@ describe('comment service test', () => {
token: IIconService,
useClass: IconService,
},
{
token: EditorCollectionService,
useValue: mockService({
listEditors: () => [],
}),
},
]),
);
commentsService = injector.get<ICommentsService>(ICommentsService);
Expand Down
5 changes: 3 additions & 2 deletions packages/comments/__test__/browser/comment.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('comment service test', () => {
currentEditor = mockService({
monacoEditor,
updateOptions: updateEditorLayoutOptions,
currentUri: URI.file('/test'),
});
injector = createBrowserInjector(
[CommentsModule],
Expand All @@ -95,7 +96,7 @@ describe('comment service test', () => {
{
token: EditorCollectionService,
useValue: mockService({
listEditors: () => [currentEditor],
listEditors: () => [],
}),
},
{
Expand Down Expand Up @@ -293,7 +294,7 @@ describe('comment service test', () => {
const thread = createTestThreads(URI.file('/test'))[0];
jest.clearAllMocks();
commentsService.setCurrentCommentThread(thread);
expect(currentEditor.monacoEditor.deltaDecorations).toHaveBeenCalledTimes(9);
expect(currentEditor.monacoEditor.deltaDecorations).toHaveBeenCalledTimes(1);
});

function createTestThreads(uri: URI) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Injector } from '@opensumi/di';
import { CommentContentNode, CommentRoot } from '@opensumi/ide-comments/lib/browser/tree/tree-node.defined';
import { IContextKeyService, URI } from '@opensumi/ide-core-browser';
import { createBrowserInjector } from '@opensumi/ide-dev-tool/src/injector-helper';
import { MockInjector, mockService } from '@opensumi/ide-dev-tool/src/mock-injector';
import { EditorCollectionService } from '@opensumi/ide-editor';
import { positionToRange } from '@opensumi/ide-monaco';
import { createMockedMonaco } from '@opensumi/ide-monaco/__mocks__/monaco';
import { MockContextKeyService } from '@opensumi/ide-monaco/__mocks__/monaco.context-key.service';
import { IIconService } from '@opensumi/ide-theme';
import { IconService } from '@opensumi/ide-theme/lib/browser';

import { createBrowserInjector } from '../../../../tools/dev-tool/src/injector-helper';
import { MockInjector } from '../../../../tools/dev-tool/src/mock-injector';
import { createMockedMonaco } from '../../../monaco/__mocks__/monaco';
import { MockContextKeyService } from '../../../monaco/__mocks__/monaco.context-key.service';
import { CommentsModule } from '../../src/browser';
import { CommentMode, ICommentsFeatureRegistry, ICommentsService } from '../../src/common';

Expand All @@ -29,6 +30,12 @@ describe('comment service test', () => {
token: IIconService,
useClass: IconService,
},
{
token: EditorCollectionService,
useValue: mockService({
listEditors: () => [],
}),
},
]),
);
commentsService = injector.get<ICommentsService>(ICommentsService);
Expand Down
40 changes: 35 additions & 5 deletions packages/comments/src/browser/comments-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class CommentsThread extends Disposable implements ICommentsThread {

private onDidChangeEmitter: Emitter<void> = new Emitter();

// 用于跟踪待执行的 setTimeout,避免快速滚动时的竞态条件
private pendingShowTimeouts = new Set<NodeJS.Timeout>();

get onDidChange() {
return this.onDidChangeEmitter.event;
}
Expand Down Expand Up @@ -111,6 +114,14 @@ export class CommentsThread extends Disposable implements ICommentsThread {
commentThreadIsEmptyContext.set(!length);
}),
);
const editors = this.getEditorsByUri(this.uri);
editors.forEach((editor) => {
const widget = this.widgets.get(editor);
// 说明是在新的 group 中打开
if (!widget) {
this.addWidgetByEditor(editor);
}
});
this.addDispose(
autorun((reader) => {
const isCollapsed = this.isCollapsed.read(reader);
Expand All @@ -132,6 +143,9 @@ export class CommentsThread extends Disposable implements ICommentsThread {
this.addDispose({
dispose: () => {
this.updateComments([]);
// 清理待执行的 timeout
this.pendingShowTimeouts.forEach((timeout) => clearTimeout(timeout));
this.pendingShowTimeouts.clear();
},
});
this.onDidChangeEmitter.fire();
Expand Down Expand Up @@ -182,7 +196,7 @@ export class CommentsThread extends Disposable implements ICommentsThread {

private addWidgetByEditor(editor: IEditor) {
const widget = this.injector.get(CommentsZoneWidget, [editor, this, { arrowColor: 'var(--peekView-border)' }]);
// 如果当前 widget 发生高度变化,通知同一个 同一个 editor 的其他 range 相同的 thread 也重新计算一下高度
// 如果当前 widget 发生高度变化,通知同一个 editor 的其他 range 相同的 thread 也重新计算一下高度
this.addDispose(
widget.onChangeZoneWidget(() => {
const threads = this.commentsService.commentsThreads.filter((thread) => this.isEqual(thread));
Expand Down Expand Up @@ -236,14 +250,23 @@ export class CommentsThread extends Disposable implements ICommentsThread {
widget = this.addWidgetByEditor(editor);
}
// 如果标记之前是已经展示的 widget,则调用 show 方法
if (editor.currentUri?.isEqual(this.uri)) {
if (widget && editor.currentUri?.isEqual(this.uri)) {
widget.show();
}
});
}
}

public removePendingShowedWidgets() {
this.pendingShowTimeouts.forEach((timeout) => clearTimeout(timeout));
this.pendingShowTimeouts.clear();
}

public showWidgetsIfShowed() {
// 清除之前的待执行 timeout,避免竞态条件
this.pendingShowTimeouts.forEach((timeout) => clearTimeout(timeout));
this.pendingShowTimeouts.clear();

for (const editor of this.getEditorsByUri(this.uri)) {
let widget = this.widgets.get(editor);
// 说明是在新的 group 中打开
Expand All @@ -252,9 +275,16 @@ export class CommentsThread extends Disposable implements ICommentsThread {
}
// 如果标记之前是已经展示的 widget,则调用 show 方法
if (editor.currentUri?.isEqual(this.uri)) {
setTimeout(() => {
widget?.show();
}, 0);
const timeout = setTimeout(() => {
// 在异步回调中再次检查编辑器的当前 URI 是否仍然匹配 thread 的 URI
// 防止用户快速滚动时 widget 渲染到错误的文件中
if (widget && editor.currentUri?.isEqual(this.uri)) {
widget.show();
}
// 执行完成后从跟踪集合中移除
this.pendingShowTimeouts.delete(timeout);
}, 100);
this.pendingShowTimeouts.add(timeout);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/comments/src/browser/comments-zone.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ export class CommentsZoneWidget extends ResizeZoneWidget implements ICommentsZon
</ConfigProvider>,
);

const disposer = editor.monacoEditor.onDidChangeModel(() => {
thread.hide();
});

this.addDispose({
dispose: () => {
this.wrapperRoot?.unmount();
this.wrapperRoot = undefined;
disposer.dispose();
},
});
}
Expand Down
Loading
Loading