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 languages.configuration.onEnterRules and add OnEnterRule#previousLineText #11225

Merged

Conversation

planger
Copy link
Contributor

@planger planger commented May 31, 2022

What it does

With this change, we read languages.configuration.onEnterRules defined via the package.json in a VS Code extension and pass them on to the language configuration for Monaco, which was previously only supported for programmatically added language configurations (#11202), and add support for the optional property OnEnterRule#previousLineText in enter rules, which was missing before (#11131).

Fixes #11202
Fixes #11131

Contributed on behalf of STMicroelectronics

How to test

The Theia example app includes the vscode.python extension, which defines the following onEnterRules in its package.json.

vscode.python defines that hitting enter after e.g. if TRUE: the next line should indent once:

  "onEnterRules": [
    {
      "beforeText": "^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$",
      "action": {
        "indent": "indent"
      }
    }
  ]

Before this change, the indentation didn't work:
Peek 2022-05-25 20-46

After this change, the indentation should work:
Peek 2022-05-31 11-04

To test OnEnterRule#previousLineText, we can add the following rule to plugins/vscode.python/extension/language-configuration.json and restart the Theia backend:

    {
      "beforeText": "^\\s*(?:DONALD)$",
      "previousLineText": "^\\s*(?:WHOIS)$",
      "action": {
        "indent": "none",
        "appendText": "DUCK"
      }
    }

After that the previousLineText should be considered as follows:
Peek 2022-05-31 11-07

Finally, it'd be good to very that programmatically defined enter rules are still working as expected, which can be verified e.g. with an HTML file in the Theia example app:
Peek 2022-05-31 11-08

Review checklist

Reminder for reviewers

Fixes eclipse-theia#11131

Contributed on behalf of STMicroelectronics

Change-Id: Ieff708dedac5bcb9c387eccf6c58dffabb2b455f
Signed-off-by: Philip Langer <[email protected]>
Fixes eclipse-theia#11202

Contributed on behalf of STMicroelectronics

Change-Id: I8ad0ba28204f959d43de2f49e2d5467f40093316
Signed-off-by: Philip Langer <[email protected]>
@colin-grant-work colin-grant-work self-requested a review May 31, 2022 16:38
@msujew msujew self-requested a review May 31, 2022 22:31
Copy link
Contributor

@colin-grant-work colin-grant-work 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 are correct and the functionality works as described. 👍

@planger
Copy link
Contributor Author

planger commented Jun 3, 2022

Thanks a lot for the review @colin-grant-work!
@msujew do you want to look at the change too, or can we merge it?

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

@planger I took a look and everything works correctly. Code also looks good to me 👍

@planger
Copy link
Contributor Author

planger commented Jun 7, 2022

Awesome, thanks @msujew!

@martin-fleck-at martin-fleck-at merged commit b7e763b into eclipse-theia:master Jun 7, 2022
@martin-fleck-at martin-fleck-at deleted the planger/issues/11131 branch June 7, 2022 15:10
@vince-fugnitto vince-fugnitto added this to the 1.27.0 milestone Jun 30, 2022
@vince-fugnitto vince-fugnitto added the vscode issues related to VSCode compatibility label Jun 30, 2022
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
None yet
5 participants