From c0d5f3efb65bfde3c2ab50ce2d84fddc8536ff30 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 9 Mar 2022 15:45:08 +0100 Subject: [PATCH] Show comments view when file with comments is opened Fixes #143948 --- .../comments/browser/comments.contribution.ts | 13 ++++++++----- .../browser/commentsEditorContribution.ts | 19 +++++++++++++++++-- .../contrib/comments/browser/timestamp.ts | 5 ++--- .../comments/common/commentsConfiguration.ts | 11 +++++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 src/vs/workbench/contrib/comments/common/commentsConfiguration.ts diff --git a/src/vs/workbench/contrib/comments/browser/comments.contribution.ts b/src/vs/workbench/contrib/comments/browser/comments.contribution.ts index f2c6b1d3b4b..0d515f2ae79 100644 --- a/src/vs/workbench/contrib/comments/browser/comments.contribution.ts +++ b/src/vs/workbench/contrib/comments/browser/comments.contribution.ts @@ -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(ConfigurationExtensions.Configuration).registerConfiguration({ id: 'comments', order: 20, @@ -24,13 +20,20 @@ Registry.as(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').") - } } }); diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index e8abd1ef104..f967fcde19f 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -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(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 { diff --git a/src/vs/workbench/contrib/comments/browser/timestamp.ts b/src/vs/workbench/contrib/comments/browser/timestamp.ts index ad7ae7fbd38..cf68da654d6 100644 --- a/src/vs/workbench/contrib/comments/browser/timestamp.ts +++ b/src/vs/workbench/contrib/comments/browser/timestamp.ts @@ -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(USE_RELATIVE_TIME_CONFIGURATION); + return this.configurationService.getValue(COMMENTS_SECTION).useRelativeTime; } public async setTimestamp(timestamp: Date | undefined) { diff --git a/src/vs/workbench/contrib/comments/common/commentsConfiguration.ts b/src/vs/workbench/contrib/comments/common/commentsConfiguration.ts new file mode 100644 index 00000000000..1ef2ba67cb7 --- /dev/null +++ b/src/vs/workbench/contrib/comments/common/commentsConfiguration.ts @@ -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';