-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Comments API refactor #68020
Comments
@rebornix Would extensions be able to forgo the visible |
@eamodio do you mean allowing extensions to provide their own implementation of the Comment Widget in the editor? |
While that would be nice -- I'm assuming that is a no-go. But alternatively something that in response to someone trying to open/edit a comment an extension could provide an alternative hook. For example, CodeStream today lets you comment on code, but our comment box lives inside our webview (for many reasons) -- but if we could still use the comment + button in the editor to trigger our comment box (in our webview) that would be quite helpful |
@eamodio if I understand correctly, taking what we have implemented in VS Code into consideration, what you ask you is more like
Did I miss anything? |
@rebornix yeah mostly
Alternatively providing much more control to the CommentWidget itself (host a mini webview?) and also some control over the rendering of the comment itself when not editing? |
We finished the major part of refactoring and the new SCM like did make authoring easier than before based on my experience on rewriting GH PR commenting support (will send out pr lately), below is the first draft of the new API.
Now the extension is responsible for creating the comment threads when an editor is being opened or the extension detects the current workspace is in review mode. All comment threads registered will show up in Comments Panel and disappear when they are disposed.
const commentControl = vscode.comment.createCommentControl('ghpr', 'GitHub PullRequest');
const startReviewCommand = {
title: 'Start Review',
command: 'ghpr.startReview',
arguments: [ commentControl ];
}
...
const thread = commentControl.createCommentThread(id, resource, range, [],[startReviewCommand]);
vscode.commands.registerCommand('ghpr.startReview', (commentControl) => {
let input = commentControl.widget.input;
let currentCommentThread = commentControl.widget.commentThread;
// start review ...
}); cc @RMacfarlane |
As we discussed last Friday and today's API syncup, we are going to simply the API a bit more
As extensions have access to the comment thread when creating the commands, we don't need
Any optional property should not be in constructor.
Instead of this explicit function, we can ask extensions to provide a |
@rebornix Given the current proposed addition of Basically ensuring enough hook points and control over the ui comment points and a programmatic api to handle the data. |
Extension example demonstrating how the API can be used microsoft/vscode-extension-samples#160 |
@rebornix Are there any plans to support nested comments as part of this API similar to the pull request comments on Bitbucket (eg. https://bitbucket.org/pbusam/test-repo/pull-requests/1). |
@prkb thanks for the feedback. we don't have plan for nested comments right now. |
@rebornix Is |
@IlyaBiryukov |
@rebornix How the extension can populate the comment panel then? |
When we started brainstorming about supporting Comments in VS Code, we went through existing stable APIs to see if there is any pattern we can follow.
Provider Like
Firstly, we have dozens of languages specific APIs. Even though there are many languages and they vary a lot in syntaxes or semantics, the editor provides an API that makes it simple to provide common features like code navigation, completion or code checking, by having all UI and actions already in place, and by allowing you to participate by providing data only.
For example, to introduce a CodeLens, what you need to do is simply providing a function that can be called with a TextDocument returning CodeLens info. In the CodeLens info, you need to provide a range where the CodeLens should be rendered above, and a [command](VS Code API | Visual Studio Code Extension API) which should be executed when users click the CodeLens.
The rest, like tracking the mouse, positioning the CodeLens, re-requesting the CodeLens when document or content changes, etc, is taken care of the editor.
The benefits of having an API similar to Language APIs (or we can call it Provider like APIs, as the API only provides data), is that users can always have the same experience, no matter which provider is regisitered under the hood, as the editor maintains how the UI is being rendered and how users interact with the editor.
The drawback is we need to define all actions explicitly in the APIs, and the actions should be generic enough, for instance, the CodeLens info has one action, and it represents the command which should be executed when users click on the CodeLens.
SCM Like
The other type of API got our interest is SCM. Instead of being Provider Like, SCM API introduces its own Domain Language and has more control of what and when the data should be rendered in the SCM Viewlet.
For example, Git extension listens to the git status change in local repository and when it finds dirty files, it will create
ResourceGroup
andResourceGroupState
accordingly, which represents Staged Changes and Changes shown in below image.Git extension also registers commands for
ResourceGroup
andResourceGroupState
entries it just creates. VS Code will decide which commands to render for eachResourceGroup
andResourceGroupState
based on the condition Git extension specifies incontributes
as below.When users commit current code change, Git extension can read the content from the textarea, by accessing
inputBox
property onSourceControl
object it creates (theinputBox
is a mirror of the textarea rendered at the top of the SCM Viewlet).The SCM API doesn’t predefine types for file/content changes, and it doesn’t define what actions a user can operate on a file change either. Instead it allows extensions to define themselves and register commands based on its own logic.
The SCM like API is more freeform compared to the Provider Like API but when we start GH PR extension, we don’t know yet how it should look like and how users would love to interact with comments in the editor. To allow us move fast, we started with Provider Like APIs and it works pretty well at the beginning.
We introduced two providers to provide comments data for opened editors and the Comments Panel
To support creating comments and replying to comments, we then added two buttons labeled as
Add comment
andReply comment
, and two more methods intoDocumentCommentsProvider
Since the extension doesn’t have access to the textarea in the Comment Widget, the core will pass in the content in the textarea when it calls
createNewCommentThread
andreplyToCommentThread
functions.The process for adding a feature for Comments was kind of finalized at that moment, we’ll firstly add a button to the Comment Widget, and then add a new method to
DocumentCommentProvider
. The methods list ofDocumentCommentProvider
keeps getting longer as a result.Even though we did make the API generic enough but still make quite a few assumptions like, Comment Provider can have a draft system, or it can allow users to post reactions on comments. After doing more investigation and discussions #63609 , we think the Provider Like API can’t serve us well and it’s the best time to move to the SCM like pattern.
Migration Plan
As discussed in Issue #63609 , the new API will allow extension to create a
CommentControl
and through which we can read the content of the textare in Comment Widget. The way extensions provide comment threads for opened documents doesn’t change too much but now the extensions control what actions should be rendered in a comment thread by providingacceptInputCommands
.When the extension modify
CommentControl
orCommentThread
properties, VS Code will rerender the Comment Widget and Comment Panel accordingly.We will also add a new section in
contributes
section inpackage.json
, within which the extension can register specific commands/actions for CommentThread or Comment. For example, GH PR extension can probably implement Reaction as commands.Related issues
Comments Provider API #53598
CommentProvider draft api proposals #63609
The text was updated successfully, but these errors were encountered: