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

Menu to select default formatter for the document #8446

Merged

Conversation

vitaliy-guliy
Copy link
Contributor

What it does

Adds quick pick menu to select document formatter.
The menu is appeared only when the extensions registered several formatters for the same language.
ID of selected formatter is saved to preferences, so the menu will not appear next time when formatting.

Fixes #8354

Screenshot from 2020-08-29 00-25-00

Screenshot from 2020-08-29 00-27-06

How to test

Option 1

  • build Thena and launch it with several extensions that register formatters for the same language

Option 2

  • use prepared script to build Theia from sources and launch it with Java and Quarkus extensions. Both of them register document formatters for java language.

To test

  • download the script somewhere on the file system
  • launch
  • open browser, go to http://localhost:3000/
  • open any java file, wait for the language server to being initialized
  • right click on the document and select 'Format Document'

Review checklist

Reminder for reviewers

@akosyakov akosyakov added monaco issues related to monaco vscode issues related to VSCode compatibility labels Sep 2, 2020
@azatsarynnyy
Copy link
Member

When I run Theia with the following plugins:

I've got
image

root ERROR [hosted-plugin: 95750] Promise rejection not handled in one second: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object , reason: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
root ERROR [hosted-plugin: 95750] With stack trace: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at Object.join (path.js:1039:7)
    at /tmp/vscode-unpacked/java-0.63.0-2222.vsix/extension/dist/extension.js:7:10673
    at new Promise (<anonymous>)
    at /tmp/vscode-unpacked/java-0.63.0-2222.vsix/extension/dist/extension.js:7:10643
    at Object.<anonymous> (/tmp/vscode-unpacked/java-0.63.0-2222.vsix/extension/dist/extension.js:7:11385)
    at Generator.next (<anonymous>)
    at o (/tmp/vscode-unpacked/java-0.63.0-2222.vsix/extension/dist/extension.js:7:8792)

@@ -1276,8 +1276,8 @@ export interface LanguagesMain {
$registerQuickFixProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], codeActionKinds?: string[]): void;
$clearDiagnostics(id: string): void;
$changeDiagnostics(id: string, delta: [string, MarkerData[]][]): void;
$registerDocumentFormattingSupport(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void;
$registerRangeFormattingProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void;
Copy link
Member

Choose a reason for hiding this comment

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

Why renaming these is needed?
Why not keep it in sync with the corresponding VS Code interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aligned with VS Code, thanks!

@azatsarynnyy
Copy link
Member

How do you run Theia? Did you try to run the test script?

@vitaliy-guliy I used "Option 1" from "How to test" section.

@vitaliy-guliy
Copy link
Contributor Author

How do you run Theia? Did you try to run the test script?

@vitaliy-guliy I used "Option 1" from "How to test" section.

Could you please describe the steps what exactly are you doing?

Did you use fork with fixes?
https://github.com/vitaliy-guliy/theia/tree/default-formatter-8354

@azatsarynnyy
Copy link
Member

@vitaliy-guliy
I've built https://github.com/vitaliy-guliy/theia/tree/default-formatter-8354
Then, I've downloaded the following plugins into theia/plugins folder:

https://download.jboss.org/jbosstools/vscode/3rdparty/vscode-java-debug/vscode-java-debug-0.26.0.vsix
https://download.jboss.org/jbosstools/static/jdt.ls/stable/java-0.63.0-2222.vsix
https://download.jboss.org/jbosstools/vscode/stable/vscode-quarkus/vscode-quarkus-1.5.0-324.vsix

It would be nice if someone else could try it as well.

Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

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

@azatsarynnyy
I tested according to #8446 (comment)
I didn't see such errors.

formatter

@vitaliy-guliy
I tried to remove a formatter from preferences to see the dialog about preferred formatter again, but looks like it always uses my first choice and I can not change formatter then.
Could you try this cases?
Does it work for you?
Maybe something wrong on my side...

Update: the problem was on my side - now it works for me and I can select another formatter after removing the previous one.
The only thing which I noticed - quarkus formatter do nothing
quarkus

@vitaliy-guliy
Copy link
Contributor Author

@azatsarynnyy
I tested according to #8446 (comment)
I didn't see such errors.

formatter

@vitaliy-guliy
I tried to remove a formatter from preferences to see the dialog about preferred formatter again, but looks like it always uses my first choice and I can not change formatter then.
Could you try this cases?
Does it work for you?
Maybe something wrong on my side...

Update: the problem was on my side - now it works for me and I can select another formatter after removing the previous one.
The only thing which I noticed - quarkus formatter do nothing
quarkus

After removing preference the menu must appear again.
About Quarkus formatter, it does not format the document. It seems something wrong with formatter directly.
Thanks for the review!

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Sep 14, 2020

After removing preference the menu must appear again.

Yes, now it works for me - I mentioned above that the problem was on my side

About Quarkus formatter, it does not format the document. It seems something wrong with formatter directly.

OK, thanks!

Copy link
Member

@azatsarynnyy azatsarynnyy left a comment

Choose a reason for hiding this comment

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

After fixing my JDK_HOME env. var. everything works as expected. Thanks @RomanNikitenko for the hint!

Copy link
Member

@azatsarynnyy azatsarynnyy left a comment

Choose a reason for hiding this comment

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

@vitaliy-guliy please, check the failed tests before merging

Comment on lines 80 to 84
'editor.defaultFormatter': {
'type': 'string',
'default': 'default',
'description': 'Default formatter'
},
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we do not want to support this same schema as vscode, especially the default value (null)?
I believe it will cause inconsistencies:

https://github.com/microsoft/vscode/blob/68410abc36030d3fb321145d2e4945f72f6e6bee/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts#L157-L164

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR is updated. For default value I used undefined, as we cannot use null. Thanks

lerna ERR! /home/vitaliy/projects/vitaliy-guliy-theia/packages/editor/src/browser/editor-preferences.ts
lerna ERR!   82:20  error  Use undefined instead of null  no-null/no-null

Copy link
Member

Choose a reason for hiding this comment

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

We could use it if we disable the rule for it, I think in this case it is fine since we want compatibility:

// eslint-disable-next-line no-null/no-null

My only concern is when reading .vscode settings where they use null as a value since it is allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with

// eslint-disable no-null/no-null

as null can be used also to initialize other properties

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
@vitaliy-guliy vitaliy-guliy merged commit a89d725 into eclipse-theia:master Sep 15, 2020
@vitaliy-guliy vitaliy-guliy deleted the default-formatter-8354 branch September 15, 2020 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
monaco issues related to monaco vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[preferences] Add ability to set default formatter
5 participants