Search code examples
visual-studio-codecomments

What is a comment thread in the vs code api?


In the Api docs of VS Code there is a concept of Comment Thread under the workspace. Is there an example of this? What are these threads? Can developers have discussions on comments? Where are these comments saved?

https://code.visualstudio.com/api/references/vscode-api#CommentThread

I tried googling and the closest I came to an example was this issue thread.

https://github.com/microsoft/vscode/issues/71171

How could I open this comment discussions in my workspace? Sorry if this is a newbie VS Code question - just recently converted.


Solution

  • How could I open this comment discussions in my workspace? Sorry if this is a newbie VS Code question - just recently converted.

    This is an API used by extension developers. This is relevant to you if you want to create your own VS Code extension, and you need a way to display comments/discussions inside the code.

    See https://github.com/microsoft/vscode-extension-samples/tree/main/comment-sample for an example + screencast. You first need to create a CommentController. The CommentController allows you to create a CommentThread. A CommentThread is a list of comments. Each Comment will have a body (text or markdown), author, date, etc.

    A common use-case of this API is to show code review comments. In particular, this is used by the GitHub Pull Requests extension, but you could imagine other use-cases for showing comments discussions inside a file.

    Where are these comments saved?

    This API deals only with the UI. You decide where the discussions are stored (e.g. make request to a service, or store them on disk). Once you have the data inside your extension, use this API to render them.