Skip to content

Conversation

rschnekenbu
Copy link
Contributor

@rschnekenbu rschnekenbu commented Feb 24, 2025

What it does

Introduce the support for Commenting Ranges and capability to create comments on file rather than on a specific range.

also it fixes the creation of comments, with arguments passed to the command being the one expected by argument processor

fix #14941

It is interesting to note that commenting range is supported, but the API do not let the extensions create Thread with not range (see https://github.com/microsoft/vscode/blob/c5549bc00e5f2e17773e9cffa694996fff318772/src/vscode-dts/vscode.d.ts#L17413). So this is hard to test and debug, even on vscode itself... For now, theia code support the ranges to be undefined, but it is not possible to test at runtime. Weird!

How to test

Steps to test:

  1. Install this extension to test the feature on comparing markdown or typescript files (commenting ruler is available on Theia on diff comparator):
  1. Open the comparison between 2 files (for example, 2 typescript files or 2 markdown files using compare with each other menu

  2. You can see in the diff editor the comment gutter (grey bar) on the side of the text editors, you can create a comment while clicking on the gutter. Notice that the md files have a gutter that is starting every 20 lines for a length of 10 lines. ts files have a gutter for the whole file length.

comment-sample-extension-ranges

The UI seems currently broken on comments, I commented on a followup issue for comments action and UI: #12452. (css are bad, actions do no support the 'when' condition, etc.). But this is not relevant for this API implementation

Follow-ups

Improvements on Comment support:

Improvements on buttons and UI: #12452

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

contributed on behalf of STMicroelectronics

Review checklist

Reminder for reviewers

also fix creation of comments, with arguments passed to the command being the one expected by argument processor

fix eclipse-theia#14941

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
@rschnekenbu rschnekenbu added the vscode issues related to VSCode compatibility label Feb 24, 2025
@rschnekenbu rschnekenbu requested a review from tsmaeder February 24, 2025 11:03
@tsmaeder
Copy link
Member

@rschnekenbu not sure how to test this: is the commenting UI available in Theia before this PR? It's not clear to me how I can invoke the commenting functionality from the video 🤷 Side note: is this an animated gif? If so, that is very inconvenient for Firefox users, because I don't get the video controls: I have to watch it from the start each time I want to go back.

@rschnekenbu
Copy link
Contributor Author

@tsmaeder , the UI is existing (and was not working) prior to this PR. To test it, you have to compare 2 different files (in my case, a markdown file and a copy of it) using the compare with each other menu when the 2 are selected. In this case, the comment gutter (a grey bar) is shown in the Diff Editor.
The area covered by the gutter is the one given by the comment providers in the extension. In the case of MD files, 10 lines can be commented, 10 not, and the same again. For typescript, any line can be commented.
For the gif, that is the most portable solution over the OS and the browsers but indeed with no controls.

@tsmaeder
Copy link
Member

tsmaeder commented Feb 25, 2025

I'm not seeing the "comment gutter" 🤷 And if I see it, how do I invoke the comment UI?
image

@rschnekenbu
Copy link
Contributor Author

Do you have any error in the log when the app is supposed to activate?
When you see it and your mouse is on top of the gutter, a [+] grey icon is showing on top of the gutter.

@tsmaeder
Copy link
Member

I see

Error: AbstractContextKeyService has been disposed
    at E.contextMatchesRules (contextKeyService.ts:319:10)
    at o.createActionGroups (menuService.ts:285:33)
    at C.getActions (menuService.ts:453:25)
    at h._getValue (gutterFeature.ts:39:97)
    at b.handleEvent [as value] (utils.ts:129:25)
    at t.DebounceEmitter._deliver (event.ts:1243:13)
    at t.DebounceEmitter.fire (event.ts:1274:9)
    at t.DebounceEmitter.resume (event.ts:1423:12)
    at event.ts:1462:10

in the browser log.

@tsmaeder
Copy link
Member

tsmaeder commented Feb 25, 2025

Now I did a "Compare with each other" again. No error in the log this time, but still not gutter. I'm using the 1.59 preview build on Windows for testing this, btw.

@rschnekenbu
Copy link
Contributor Author

I will test again on my side, but I never see such an issue. I do not get why the contextKeyService shall be disposed.

@rschnekenbu
Copy link
Contributor Author

@tsmaeder I added some steps to clarify the testing.

@tsmaeder
Copy link
Member

What I was missing is that you need to install the extension in order to make the UI show up 🤷

@tsmaeder
Copy link
Member

@rschnekenbu I get the "+" signs in the gutter as well on the left side of the left editor in the diff for removed sections. However, when I click on the plus, nothing happens (no error log either).

@@ -651,8 +653,10 @@ export class CommentActions extends React.Component<CommentActions.Props> {
commands={commands}
node={node}
onClick={() => {
console.log('CommentActions.onClick: ' + commentThread);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Development leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! 🤕

@@ -221,7 +245,8 @@ export class ExtHostCommentThread implements theia.CommentThread, theia.Disposab
readonly onDidUpdateCommentThread = this._onDidUpdateCommentThread.event;

set range(range: theia.Range) {
if (!range.isEqual(this._range)) {
if ( ((range === undefined) !== (this._range === undefined))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of the range parameter does not allow it to be undefined. It probably should, considering we're checking for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now possible to change to an undefined range. Evolution should come later with the ability to create comments without range from the API.

@@ -256,8 +256,8 @@ export class CommentThreadWidget extends BaseWidget {
const frameThickness = Math.round(lineHeight / 9) * 2;
const body = this.zoneWidget.containerNode.getElementsByClassName('body')[0];

const computedLinesNumber = Math.ceil((headHeight + body.clientHeight + arrowHeight + frameThickness + 8 /** margin bottom to avoid margin collapse */) / lineHeight);
this.zoneWidget.show({ afterLineNumber: this._commentThread.range.startLineNumber, heightInLines: computedLinesNumber });
const computedLinesNumber = Math.ceil((headHeight + body?.clientHeight + arrowHeight + frameThickness + 8 /** margin bottom to avoid margin collapse */) / lineHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs body?.clientHeight ?? 0, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in next commit

if (ranges) {
return ranges.map(x => fromRange(x));
const commentingRanges:
| theia.Range[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not let type inference determine the type here?

fileComments: commentingRanges.enableFileComments
};
} else {
return commentingRanges ?? undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already now that !commentingRanges here, why not just return undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, being null or undefined, we don't care as we want undefined only. Removed in next commit.

@rschnekenbu
Copy link
Contributor Author

@tsmaeder could you finally get the comment dialog to open ?

@tsmaeder
Copy link
Member

@rschnekenbu I get the "+" signs in the gutter as well on the left side of the left editor in the diff for removed sections. However, when I click on the plus, nothing happens (no error log either).

@rschnekenbu ping?

@rschnekenbu
Copy link
Contributor Author

@tsmaeder, indeed, the left editor can't have comments. That does not make sense for the set of changes I have introduced, probably some other defect existing prior to this change. But in any case, I will have a look and check why left editor does not support commenting.

@tsmaeder
Copy link
Member

If it's not a regression, I don't have a problem merging this one, but I can't really test that because the plugin does not work without the PR.

@rschnekenbu
Copy link
Contributor Author

The onMouseDownEvent in comments-contribution.ts is not send when clicking on the left gutter. This seems an issue with the current implementation of the comments contribution and not from the API evolution.

@tsmaeder tsmaeder merged commit 03751ab into eclipse-theia:master Feb 26, 2025
10 of 11 checks passed
@github-actions github-actions bot added this to the 1.59.0 milestone Feb 26, 2025
laemmleint pushed a commit to mvtecsoftware/theia that referenced this pull request Aug 18, 2025
* [vscode] introduction of the CommentingRange type

also fix creation of comments, with arguments passed to the command being the one expected by argument processor

fix eclipse-theia#14941

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[vscode] introduction of the CommentingRange type
2 participants