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

Extension development: commenting ranges not shown when commentingRangeProvider added after a delay #126475

Closed
viktomas-gitlab opened this issue Jun 16, 2021 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug comments Comments Provider/Widget/Panel issues insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Milestone

Comments

@viktomas-gitlab
Copy link

Does this issue occur when all extensions are disabled?: No, this issue is related to extension development

Version: 1.57.0-insider
Commit: b4c1bd0
Date: 2021-06-09T10:41:06.148Z
Electron: 12.0.9
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Darwin x64 19.6.0

CommentController can have commentingRangeProvider assigned. This provider is responsible for indicating where commenting ranges should be shown.

If the assignment happens after a delay (e.g. after API call), the commenting ranges are not shown in the active editor.

In the following video, I demonstrate the issue. I used the yeoman generated example extension and replaced the extension.ts with:

import * as vscode from 'vscode';

const createCommentingRangeProvider = (): vscode.CommentingRangeProvider => ({
  provideCommentingRanges: (document) => [
    new vscode.Range(
      new vscode.Position(0, 0),
      new vscode.Position(document.lineCount - 1, 0)
    ),
  ],
});

export async function activate(context: vscode.ExtensionContext) {
  const disposable = vscode.commands.registerCommand(
    'commenting-range-bug-demonstration.helloWorld',
    async () => {
      const commentController = vscode.comments.createCommentController(
        'id',
        'label'
      );
      // interruption here causes the bug
      await new Promise((res) => setTimeout(res, 100));
      commentController.commentingRangeProvider =
        createCommentingRangeProvider();
    }
  );

  context.subscriptions.push(disposable);
}

The video shows how having a delay between vscode.comments.createCommentController and commentController.commentingRangeProvider causes the active editor not to have commenting ranges.

commenting-ranges-bug.mp4

I pushed the example extension to a public repository: https://gitlab.com/viktomas/demonstrate-commenting-ranges-bug/-/blob/master/src/extension.ts

This issue is an edge case and the fix could probably be just mentioning this bug in the JS Doc: https://github.com/microsoft/vscode/blob/main/src/vs/vscode.d.ts#L13448 I'm happy to create a PR.

The best fix would be either to make VS Code react to commentingRangeProvider being set on the CommentController or add commentingRangeProvider as an argument to the vscode.comments.createCommentController function call to signal that the commenting range provider must be ready at the time of creation

@rebornix rebornix added polish Cleanup and polish issue comments Comments Provider/Widget/Panel issues labels Jun 16, 2021
@rebornix rebornix added this to the June 2021 milestone Jun 16, 2021
@rebornix rebornix modified the milestones: June 2021, July 2021 Jul 1, 2021
@rebornix rebornix modified the milestones: July 2021, August 2021 Jul 28, 2021
@rebornix rebornix modified the milestones: August 2021, September 2021 Aug 22, 2021
@rebornix rebornix modified the milestones: September 2021, On Deck Sep 29, 2021
@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Oct 11, 2021
@rebornix rebornix modified the milestones: On Deck, October 2021 Oct 19, 2021
@rebornix rebornix removed the polish Cleanup and polish issue label Oct 19, 2021
@mjbvz mjbvz added the author-verification-requested Issues potentially verifiable by issue author label Oct 28, 2021
@roblourens roblourens added the verified Verification succeeded label Oct 28, 2021
@viktomas-gitlab
Copy link
Author

/verified

@viktomas-gitlab
Copy link
Author

Thank you for fixing the issue @rebornix 🙏 🙇

@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug comments Comments Provider/Widget/Panel issues insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants
@roblourens @rebornix @mjbvz @viktomas-gitlab and others