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

add accessible view for comment thread widget #228018

Merged
merged 19 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions src/vs/platform/accessibility/browser/accessibleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const enum AccessibleViewProviderId {
Notification = 'notification',
EmptyEditorHint = 'emptyEditorHint',
Comments = 'comments',
CommentThread = 'commentThread',
Repl = 'repl',
ReplHelp = 'replHelp',
RunAndDebug = 'runAndDebug',
Expand Down
38 changes: 38 additions & 0 deletions src/vs/workbench/contrib/comments/browser/commentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface ICommentService {
readonly onDidChangeCommentingEnabled: Event<boolean>;
readonly isCommentingEnabled: boolean;
readonly commentsModel: ICommentsModel;
readonly activeCommentInfo: { thread: CommentThread<IRange>; comment?: Comment; owner: string } | undefined;
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void;
setWorkspaceComments(uniqueOwner: string, commentsByResource: CommentThread<IRange | ICellRange>[]): void;
removeWorkspaceComments(uniqueOwner: string): void;
Expand All @@ -111,6 +112,7 @@ export interface ICommentService {
setActiveEditingCommentThread(commentThread: CommentThread<IRange | ICellRange> | null): void;
setCurrentCommentThread(commentThread: CommentThread<IRange | ICellRange> | undefined): void;
setActiveCommentAndThread(uniqueOwner: string, commentInfo: { thread: CommentThread<IRange | ICellRange>; comment?: Comment } | undefined): Promise<void>;
navigateToCommentAndThread(type: 'next' | 'previous'): void;
enableCommenting(enable: boolean): void;
registerContinueOnCommentProvider(provider: IContinueOnCommentProvider): IDisposable;
removeContinueOnComment(pendingComment: { range: IRange | undefined; uri: URI; uniqueOwner: string; isReply?: boolean }): PendingCommentThread | undefined;
Expand Down Expand Up @@ -175,6 +177,11 @@ export class CommentService extends Disposable implements ICommentService {
private _commentingRangeResources = new Set<string>(); // URIs
private _commentingRangeResourceHintSchemes = new Set<string>(); // schemes

private _activeCommentInfo: { owner: string; thread: CommentThread<IRange>; comment?: Comment } | undefined;
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
get activeCommentInfo() {
return this._activeCommentInfo;
}

constructor(
@IInstantiationService protected readonly instantiationService: IInstantiationService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
Expand Down Expand Up @@ -307,9 +314,40 @@ export class CommentService extends Disposable implements ICommentService {
await this._lastActiveCommentController?.setActiveCommentAndThread(undefined);
}
this._lastActiveCommentController = commentController;
if (commentInfo) {
this._activeCommentInfo = { owner: uniqueOwner, thread: commentInfo.thread, comment: commentInfo?.comment };
} else {
this._activeCommentInfo = undefined;
}
return commentController.setActiveCommentAndThread(commentInfo);
}

/**
* Navigate to the next or previous comment thread
* @param type
*/
navigateToCommentAndThread(type: 'next' | 'previous') {
const commentInfo = this.activeCommentInfo;
if (!commentInfo?.comment || !commentInfo?.thread?.comments) {
return;
}
const currentIndex = this.activeCommentInfo?.thread.comments?.indexOf(commentInfo.comment);
if (currentIndex === undefined || currentIndex < 0) {
return;
}
if (type === 'previous' && currentIndex === 0) {
return;
}
if (type === 'next' && currentIndex === commentInfo.thread.comments.length - 1) {
return;
}
const comment = this.activeCommentInfo?.thread.comments?.[type === 'previous' ? currentIndex - 1 : currentIndex + 1];
if (!comment) {
return;
}
this.setActiveCommentAndThread(this.activeCommentInfo.owner, { comment, thread: commentInfo.thread });
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}

setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { MarshalledCommentThreadInternal } from '../../../common/comments.js';
import { accessibleViewCurrentProviderId, accessibleViewIsShown } from '../../accessibility/browser/accessibilityConfiguration.js';
import { AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js';
import { AccessibleViewRegistry } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';
import { CommentsAccessibleView } from './commentsAccessibleView.js';
import { CommentsAccessibleView, CommentThreadAccessibleView } from './commentsAccessibleView.js';
import { CommentsAccessibilityHelp } from './commentsAccessibility.js';

registerAction2(class Collapse extends ViewAction<CommentsPanel> {
Expand Down Expand Up @@ -193,4 +193,5 @@ export class UnresolvedCommentsBadge extends Disposable implements IWorkbenchCon
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(UnresolvedCommentsBadge, LifecyclePhase.Eventually);

AccessibleViewRegistry.register(new CommentsAccessibleView());
AccessibleViewRegistry.register(new CommentThreadAccessibleView());
AccessibleViewRegistry.register(new CommentsAccessibilityHelp());
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import { AccessibilityVerbositySettingId } from '../../accessibility/browser/acc
import { COMMENTS_VIEW_ID, CommentsMenus } from './commentsTreeViewer.js';
import { CommentsPanel, CONTEXT_KEY_COMMENT_FOCUSED } from './commentsView.js';
import { IViewsService } from '../../../services/views/common/viewsService.js';
import { ICommentService } from './commentService.js';
import { CommentContextKeys } from '../common/commentContextKeys.js';
import { revealCommentThread } from './commentsController.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js';
import { isCodeEditor } from '../../../../editor/browser/editorBrowser.js';
import { URI } from '../../../../base/common/uri.js';

export class CommentsAccessibleView extends Disposable implements IAccessibleViewImplentation {
readonly priority = 90;
Expand All @@ -26,6 +33,7 @@ export class CommentsAccessibleView extends Disposable implements IAccessibleVie
const menuService = accessor.get(IMenuService);
const commentsView = viewsService.getActiveViewWithId<CommentsPanel>(COMMENTS_VIEW_ID);
const focusedCommentNode = commentsView?.focusedCommentNode;

if (!commentsView || !focusedCommentNode) {
return;
}
Expand All @@ -39,6 +47,28 @@ export class CommentsAccessibleView extends Disposable implements IAccessibleVie
}
}


export class CommentThreadAccessibleView extends Disposable implements IAccessibleViewImplentation {
readonly priority = 85;
readonly name = 'commentThread';
readonly when = CommentContextKeys.commentFocused;
readonly type = AccessibleViewType.View;
getProvider(accessor: ServicesAccessor) {
const commentService = accessor.get(ICommentService);
const editorService = accessor.get(IEditorService);
const uriIdentityService = accessor.get(IUriIdentityService);
const threads = commentService.commentsModel.hasCommentThreads();
if (!threads) {
return;
}
return new CommentsThreadWidgetAccessibleContentProvider(commentService, editorService, uriIdentityService);
}
constructor() {
super();
}
}


class CommentsAccessibleContentProvider extends Disposable implements IAccessibleViewContentProvider {
constructor(
private readonly _commentsView: CommentsPanel,
Expand Down Expand Up @@ -84,3 +114,53 @@ class CommentsAccessibleContentProvider extends Disposable implements IAccessibl
return this.provideContent();
}
}

class CommentsThreadWidgetAccessibleContentProvider extends Disposable implements IAccessibleViewContentProvider {
readonly id = AccessibleViewProviderId.CommentThread;
readonly verbositySettingKey = AccessibilityVerbositySettingId.Comments;
readonly options = { type: AccessibleViewType.View };
constructor(@ICommentService private readonly _commentService: ICommentService,
@IEditorService private readonly _editorService: IEditorService,
@IUriIdentityService private readonly _uriIdentityService: IUriIdentityService,
) {
super();
}
provideContent(): string {
if (!this._commentService.activeCommentInfo) {
throw new Error('No current comment thread');
}
const comment = this._commentService.activeCommentInfo.comment?.body;
const commentLabel = typeof comment === 'string' ? comment : comment?.value ?? '';
const resource = this._commentService.activeCommentInfo.thread.resource;
const range = this._commentService.activeCommentInfo.thread.range;
let contentLabel = '';
if (resource && range) {
const editor = this._editorService.findEditors(URI.parse(resource)) || [];
const codeEditor = this._editorService.activeEditorPane?.getControl();
if (editor?.length && isCodeEditor(codeEditor)) {
const content = codeEditor.getModel()?.getValueInRange(range);
if (content) {
contentLabel = '\nCorresponding code: \n' + content;
}
}
}
return commentLabel + contentLabel;
}
onClose(): void {
const commentInfo = this._commentService.activeCommentInfo;
if (!commentInfo) {
return;
}
// TODO: is there a way to focus the comment not the thread?
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
this._commentService.setActiveCommentAndThread(commentInfo.owner, { comment: commentInfo.comment, thread: commentInfo.thread });
revealCommentThread(this._commentService, this._editorService, this._uriIdentityService, commentInfo.thread, commentInfo.comment);
}
provideNextContent(): string | undefined {
this._commentService.navigateToCommentAndThread('next');
return this.provideContent();
}
providePreviousContent(): string | undefined {
this._commentService.navigateToCommentAndThread('previous');
return this.provideContent();
}
}
Loading