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

[vscode] support editor/linenumber/context menu #12638

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

rschnekenbu
Copy link
Contributor

What it does

Adds a missing predefined entry in the menus
This enables the possibility to contribute menus to editor/linenumber/context entry as defined in vscode 1.78 (see https://code.visualstudio.com/updates/v1_78#_editorlinenumbercontext-menu)

Fixes #12560

Contributed on behalf of ST Microelectronics

How to test

  1. Install following extension:
  1. Try to open a menu on any text file, no menu shall open when right-clicking a line number. An error shall also be displayed in the console when the extension is activated.

  2. Update your theia repository to use this PR

  3. Any text file shall now display at least one menu on line numbers. If line selected is above 11, then a second menu shall also be displayed. This demonstrates the context key editorLineNumber is set correctly. The information displayed when selecting the action shows the current URI for the edited resource, and the line number, as expected by vscode.

  4. The build-in github extension shall also start without displaying a comment on a missing menu entry for editor/linenumber/context.

Review checklist

Reminder for reviewers

@vince-fugnitto vince-fugnitto added the vscode issues related to VSCode compatibility label Jun 21, 2023
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I have some minor comments about the code and formatting.

When testing I noticed some odd behaviours:

  • the lineNumber is 1 position less than what is selected
  • the extension might have a typo in the command registration of sample-menu-extension.helloWorld - in vscode this command is never available in the context-menu (as it has no title) while theia displays it

The error in definition is the missing context in the id:

"contributes": {
  "commands": [
    {
      "command": "sample-menu-extension.context.helloWorld",
      "title": "Sample Extension Editor LineNumber Context"
    },
    {
      "command": "sample-menu-extension.lineGreaterThan10",
      "title": "LineNumber Greater than 10!"
    } 
  ],
  "menus": {
    "editor/lineNumber/context": [
      {
        "command": "sample-menu-extension.helloWorld",
        "icon" : "$(notebook-execute)"
      },
      {
        "command": "sample-menu-extension.lineGreaterThan10",
        "icon" : "$(notebook-execute)",
        "when": "editorLineNumber > 10"
      } 
    ] 
  }
}

@rschnekenbu
Copy link
Contributor Author

Thanks a lot for your review, @vince-fugnitto!

I fixed the formatting issues in a first commit.
In the second one, I addressed the line number issue, but I am not very pleased on the current fix. The issue comes from the position in MouseTarget, which is a 0-based position. The interesting element is that monaco editor position line number is 1-based, which is kind of confusing here.

I updated the examples, so the basic line number menu is now visible in theia and vscode.

Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution. It does not work for me, please see the screencast. The code can be improved a bit.

protected readonly quickInputService: QuickInputService;

onStart(): void {
this.editorManager.onCreated(editor => this.addLineNumberContextMenu(editor));
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work. If two editors are open, the context menu on the line number works, close one of the editors, and the feature stops working.

line_context_menu.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each editor contribution is now disposed on its own editor disposal.

@rschnekenbu
Copy link
Contributor Author

@kittaakos, thanks for your review!
I have already updated the contribution and resolved conflicts, I will be just pushing as soon as I have your feedback on m2p converter.

@vince-fugnitto
Copy link
Member

@rschnekenbu please ping me when you address the feedback and conflicts, and I'll happily re-review 👍

@rschnekenbu
Copy link
Contributor Author

@vince-fugnitto, thanks for taking care again of this PR! I rebased and resolved the conflicts, and I addressed the comments from you and Akos. The menu is now disposed by its own editor, so there can be several editors opened and closed, the menu contribution remains for an editor until the editor itself is disposed.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

The changes look good to me, and work well as well 👍

* Adds contextual menu to line number area in text editors
* map the predefined vscode entry  "editor/linenumber/context" to theia

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
@rschnekenbu
Copy link
Contributor Author

All comments have been addressed, this PR can now be merged. Thanks @vince-fugnitto and @kittaakos for your help 👍

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] Add missing editor/lineNumber/context menu
3 participants