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

CommentController should be able to enumerate its own threads/comments #243152

Open
bolinfest opened this issue Mar 11, 2025 · 1 comment
Open
Assignees

Comments

@bolinfest
Copy link
Contributor

Given that VS Code has a Comments pane, it clearly knows all of the threads/comments contributed by a CommentController. It would be helpful if it were possible to get your own threads/comments back via the CommentController because it appears there are attributes of the comment that only VS Code knows. Specifically, as the content before the thread changes in the file, the range associated with the thread can change [the gutter decoration updates immediately, though it seems you have to click on a comment in the Comments pane before the associated [Ln XXX] text updates there], but I do not believe it is possible to get the updated range for a thread programmatically without tedious bookkeeping.

I tried to maintain my own set of vscode.CommentThread objects to see whether the range property would get updated automatically. I tried to capture every vscode.CommentThread as it was created, but as best I can tell, there is no way to intercept calls to createCommentThread() on a vscode.CommentController because even if I try something like:

const originalCreateCommentThread = commentController.createCommentThread;
commentController.createCommentThread = function (
  uri: vscode.Uri,
  range: vscode.Range,
  comments: readonly vscode.Comment[]
): vscode.CommentThread {
  console.log(`intercepted createCommentThread uri=${uri} range=${range}`);
  const thread = originalCreateCommentThread.call(
    commentController,
    uri,
    range,
    comments
  );
  console.log(`created thread=${thread}`);
  return thread;
};

I get a runtime error that createCommentThread is read only and cannot be reassigned.

My next best attempt was to instrument the function associated with the command I added to the comments/commentThread/context menu, as the corresponding callback function receives a vscode.CommentReply object, from which I can get the vscode.CommentThread via its thread property. I tried adding logic to capture these and maintain a set of these vscode.CommentThread objects, but their range properties to not appear to get updated as lines shift in the file.

All of this would be considerably simpler if I could just ask CommentController for the threads/comments so I don't have to do my own bookkeeping that will almost inevitably get out of sync with reality.

Before filing this issue, I did look for other closed issues for CommentController, and the most similar one I found was #200371, but that was asking for programmatic access to comments from other extensions whereas I am only asking for access to comments from one's own extension.

@bolinfest
Copy link
Contributor Author

Even if I add a command to the comments/commentThread/title menu where the associated callback receives a vscode.CommentThread directly, the range on that argument is still stale, so it's not even like I can add a "refresh" button to that menu because there is no way to tell at that point that the true range has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants