Show comments view when file with comments is opened

Fixes #143948
This commit is contained in:
Alex Ross
2022-03-09 15:45:56 +01:00
parent c08eb19479
commit c0d5f3efb6
4 changed files with 38 additions and 10 deletions
@@ -10,10 +10,6 @@ import 'vs/workbench/contrib/comments/browser/commentsEditorContribution';
import { ICommentService, CommentService } from 'vs/workbench/contrib/comments/browser/commentService';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
export interface ICommentsConfiguration {
openPanel: 'neverOpen' | 'openOnSessionStart' | 'openOnSessionStartWithComments';
}
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
id: 'comments',
order: 20,
@@ -24,13 +20,20 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
enum: ['neverOpen', 'openOnSessionStart', 'openOnSessionStartWithComments'],
default: 'openOnSessionStartWithComments',
description: nls.localize('openComments', "Controls when the comments panel should open."),
restricted: false,
markdownDeprecationMessage: nls.localize('comments.openPanel.deprecated', "This setting is deprecated in favor of `comments.openView`.")
},
'comments.openView': {
enum: ['never', 'file'],
enumDescriptions: [nls.localize('comments.openView.never', "The comments view will never be opened."), nls.localize('comments.openView.file', "The comments view will open when a file with comments is active.")],
default: 'file',
description: nls.localize('comments.openView', "Controls when the comments view should open."),
restricted: false
},
'comments.useRelativeTime': {
type: 'boolean',
default: true,
description: nls.localize('useRelativeTime', "Determines if relative time will be used in comment timestamps (ex. '1 day ago').")
}
}
});
@@ -36,6 +36,10 @@ import { ctxCommentEditorFocused, SimpleCommentEditor } from 'vs/workbench/contr
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { IViewsService } from 'vs/workbench/common/views';
import { COMMENTS_VIEW_ID } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { COMMENTS_SECTION, ICommentsConfiguration } from 'vs/workbench/contrib/comments/common/commentsConfiguration';
export const ID = 'editor.contrib.review';
@@ -167,7 +171,9 @@ export class CommentController implements IEditorContribution {
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@IContextMenuService readonly contextMenuService: IContextMenuService,
@IQuickInputService private readonly quickInputService: IQuickInputService
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IViewsService private readonly viewsService: IViewsService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
this._commentInfos = [];
this._commentWidgets = [];
@@ -399,7 +405,12 @@ export class CommentController implements IEditorContribution {
}));
this.beginCompute();
this.beginCompute().then(() => {
if (this._commentWidgets.length
&& (this.configurationService.getValue<ICommentsConfiguration>(COMMENTS_SECTION).openView === 'file')) {
this.viewsService.openView(COMMENTS_VIEW_ID);
}
});
}
private displayCommentThread(owner: string, thread: languages.CommentThread, pendingComment: string | null): void {
@@ -630,6 +641,10 @@ export class CommentController implements IEditorContribution {
this._commentWidgets = [];
}
public hasComments(): boolean {
return !!this._commentWidgets.length;
}
}
export class NextCommentThreadAction extends EditorAction {
@@ -7,8 +7,7 @@ import * as dom from 'vs/base/browser/dom';
import { fromNow } from 'vs/base/common/date';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
const USE_RELATIVE_TIME_CONFIGURATION = 'comments.useRelativeTime';
import { COMMENTS_SECTION, ICommentsConfiguration } from 'vs/workbench/contrib/comments/common/commentsConfiguration';
export class TimestampWidget extends Disposable {
private _date: HTMLElement;
@@ -24,7 +23,7 @@ export class TimestampWidget extends Disposable {
}
private get useRelativeTimeSetting(): boolean {
return this.configurationService.getValue<boolean>(USE_RELATIVE_TIME_CONFIGURATION);
return this.configurationService.getValue<ICommentsConfiguration>(COMMENTS_SECTION).useRelativeTime;
}
public async setTimestamp(timestamp: Date | undefined) {
@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface ICommentsConfiguration {
openView: 'never' | 'file';
useRelativeTime: boolean;
}
export const COMMENTS_SECTION = 'comments';