eclipse-wildwebdeveloper / wildwebdeveloper

Simple and productive Web Development Tools in the Eclipse IDE
https://projects.eclipse.org/projects/tools.wildwebdeveloper
Eclipse Public License 2.0
189 stars 70 forks source link

Javascript editor 'Save actions' remove trailing whitespace spaces from all lines is not working #474

Open kevinwhine opened 4 years ago

kevinwhine commented 4 years ago

I have been asked to report this issue here from https://bugs.eclipse.org/bugs/show_bug.cgi?id=565046.

Within Eclipse IDE I am using File type = Javascript Editor = Javascript Window > Preferences > Javascript > Editor > Save Action > Additional actions > Configure > Code Organizing > Formatter Tick Remove trailing whitespace checkbox Select 'All lines' radio button option

Expected: The white space should be removed upon saving the file. Actual: Upon saving the file I can see that trailing white space remains

This can be easily seen as I use SonarLint to highlight coding standards transgressions.

Thank you for your time.

Kevin

Eclipse Installation details: Axis2 Tools 1.1.401.v201909051708 org.eclipse.jst.ws.axis2tools.feature.feature.group Eclipse Web Tools Platform Buildship: Eclipse Plug-ins for Gradle 3.1.4.v20200326-1743 org.eclipse.buildship.feature.group Eclipse Buildship Cloud Foundry Tools Core 1.2.3.v201805291812 org.eclipse.cft.server.core.feature.feature.group Eclipse Tools for Cloud Foundry Cloud Foundry Tools UI 1.0.10.v201805291812 org.eclipse.cft.server.ui.feature.feature.group Eclipse Tools for Cloud Foundry CXF Web Services 1.1.600.v202004091240 org.eclipse.jst.ws.cxf.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - Common 1.5.100.v201903221940 org.eclipse.jpt.common.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - EclipseLink Common 1.3.200.v201903221940 org.eclipse.jpt.common.eclipselink.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - EclipseLink JAXB Support 1.4.202.v201903221940 org.eclipse.jpt.jaxb.eclipselink.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - EclipseLink JPA Support 3.4.101.v201903221940 org.eclipse.jpt.jpa.eclipselink.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - JAXB Support 1.5.100.v201903221940 org.eclipse.jpt.jaxb.feature.feature.group Eclipse Web Tools Platform Dali Java Persistence Tools - JPA Support 3.6.0.v202002052252 org.eclipse.jpt.jpa.feature.feature.group Eclipse Web Tools Platform Data Tools Platform Connectivity 1.14.102.201911250848 org.eclipse.datatools.connectivity.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Connectivity Documentation 1.14.102.201911250848 org.eclipse.datatools.connectivity.doc.user.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement 1.14.102.201911250848 org.eclipse.datatools.enablement.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement Extender SDK 1.14.102.201911250848 org.eclipse.datatools.enablement.sdk.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Apache Derby 1.14.102.201911250848 org.eclipse.datatools.enablement.apache.derby.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for HSQLDB 1.14.102.201911250848 org.eclipse.datatools.enablement.hsqldb.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for IBM 1.14.102.201911250848 org.eclipse.datatools.enablement.ibm.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Ingres 1.14.102.201911250848 org.eclipse.datatools.enablement.ingres.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for JDBC 1.14.102.201911250848 org.eclipse.datatools.enablement.jdbc.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Microsoft 1.14.102.201911250848 org.eclipse.datatools.enablement.msft.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for MySQL 1.14.102.201911250848 org.eclipse.datatools.enablement.mysql.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for ODA Designer 1.14.102.201911250848 org.eclipse.datatools.enablement.oda.designer.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for ODA Runtime 1.14.102.201911221603 org.eclipse.datatools.enablement.oda.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Oracle 1.14.102.201911250848 org.eclipse.datatools.enablement.oracle.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for PostgreSQL 1.14.102.201911250848 org.eclipse.datatools.enablement.postgresql.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for SAP MaxDB 1.14.102.201911250848 org.eclipse.datatools.enablement.sap.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Sqlite 1.14.102.201911250848 org.eclipse.datatools.enablement.sqlite.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Enablement for Sybase 1.14.102.201911250848 org.eclipse.datatools.enablement.sybase.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Extender SDK 1.14.102.201911250848 org.eclipse.datatools.sdk.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Intro 1.14.102.201911250848 org.eclipse.datatools.intro.feature.group Eclipse Data Tools Platform Data Tools Platform JDT Enablement 1.14.102.201911250848 org.eclipse.datatools.enablement.jdt.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Model Base 1.14.102.201911250848 org.eclipse.datatools.modelbase.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Open Data Access Designer 1.14.102.201911250848 org.eclipse.datatools.connectivity.oda.designer.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Open Data Access Designer Core 1.14.102.201911250848 org.eclipse.datatools.connectivity.oda.designer.core.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Open Data Access Runtime 1.14.102.201911250848 org.eclipse.datatools.connectivity.oda.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Dev Tools Documentation 1.14.102.201911250848 org.eclipse.datatools.sqltools.doc.user.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Development Tools 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Development Tools Data Functions 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.data.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Development Tools DDL Functionality 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.ddl.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Development Tools DDL Generation Functionality 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.ddlgen.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Development Tools Results View 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.results.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Parsers 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.parsers.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Query Builder 1.14.102.201911221603 org.eclipse.datatools.sqldevtools.sqlbuilder.feature.feature.group Eclipse Data Tools Platform Data Tools Platform SQL Schema Object Editor Feature 1.14.102.201911250848 org.eclipse.datatools.sqldevtools.schemaobjecteditor.feature.feature.group Eclipse Data Tools Platform Data Tools Platform Tutorial Documentation 1.14.102.201911250848 org.eclipse.datatools.common.doc.user.feature.group Eclipse Data Tools Platform Data Tools Platform User Documentation 1.14.102.201911250848 org.eclipse.datatools.doc.user.feature.group Eclipse Data Tools Platform EclEmma Java Code Coverage 3.1.3.202003132300 org.eclipse.eclemma.feature.feature.group Eclipse EclEmma Eclipse Faceted Project Framework 3.7.2.v201903222010 org.eclipse.wst.common.fproj.feature.group Eclipse Web Tools Platform Eclipse Faceted Project Framework JDT Enablement 3.13.0.v202005211433 org.eclipse.jst.common.fproj.enablement.jdt.feature.group Eclipse Web Tools Platform Eclipse IDE for Enterprise Java Developers 4.16.0.20200615-1200 epp.package.jee Eclipse Packaging Project Eclipse Java Development Tools 3.18.400.v20200604-0540 org.eclipse.jdt.feature.group Eclipse.org Eclipse Java EE Developer Tools 3.18.0.v202003201241 org.eclipse.jst.enterprise_ui.feature.feature.group Eclipse Web Tools Platform Eclipse Java Web Developer Tools 3.18.0.v202005181429 org.eclipse.jst.web_ui.feature.feature.group Eclipse Web Tools Platform Eclipse Platform 4.16.0.v20200604-0951 org.eclipse.platform.feature.group Eclipse.org Eclipse Plug-in Development Environment 3.14.400.v20200604-0540 org.eclipse.pde.feature.group Eclipse.org Eclipse RCP 4.16.0.v20200604-0951 org.eclipse.rcp.feature.group Eclipse.org Eclipse XSL Developer Tools 1.3.900.v202005251734 org.eclipse.wst.xsl.feature.feature.group Eclipse Web Tools Platform Git integration for Eclipse 5.8.0.202006091008-r org.eclipse.egit.feature.group Eclipse EGit Git integration for Eclipse - Task focused interface 5.8.0.202006091008-r org.eclipse.egit.mylyn.feature.group Eclipse EGit JavaScript Development Tools 2.1.5.v202002141644 org.eclipse.wst.jsdt.feature.feature.group Eclipse Web Tools Platform JAX-WS DOM Tools 1.0.303.v201909051708 org.eclipse.jst.ws.jaxws.dom.feature.feature.group Eclipse Web Tools Platform JAX-WS Tools 1.2.501.v201909051708 org.eclipse.jst.ws.jaxws.feature.feature.group Eclipse Web Tools Platform JSF Tools 3.10.0.v202003241443 org.eclipse.jsf.feature.feature.group Eclipse Web Tools Platform JSF Tools - Tag Library Metadata (Apache Trinidad) 2.6.1.v201902121810 org.eclipse.jst.jsf.apache.trinidad.tagsupport.feature.feature.group Eclipse Web Tools Platform JSF Tools - Web Page Editor 2.9.1.v202003241443 org.eclipse.jst.webpageeditor.feature.feature.group Eclipse Web Tools Platform JST Server Adapters 3.2.600.v201910252115 org.eclipse.jst.server_adapters.feature.feature.group Eclipse Web Tools Platform JST Server Adapters Extensions 3.3.700.v201910252115 org.eclipse.jst.server_adapters.ext.feature.feature.group Eclipse Web Tools Platform JST Server UI 3.4.400.v201910252115 org.eclipse.jst.server_ui.feature.feature.group Eclipse Web Tools Platform m2e - Maven Integration for Eclipse (includes Incubating components) 1.16.0.20200610-1735 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e m2e - slf4j over logback logging (Optional) 1.16.0.20200318-1040 org.eclipse.m2e.logback.feature.feature.group Eclipse.org - m2e m2e-wtp - JAX-RS configurator for WTP (Optional) 1.4.4.20200220-1005 org.eclipse.m2e.wtp.jaxrs.feature.feature.group Eclipse.org - m2e-wtp m2e-wtp - JPA configurator for WTP (Optional) 1.4.4.20200220-1005 org.eclipse.m2e.wtp.jpa.feature.feature.group Eclipse.org - m2e-wtp m2e-wtp - JSF configurator for WTP (Optional) 1.4.4.20200220-1005 org.eclipse.m2e.wtp.jsf.feature.feature.group Eclipse.org - m2e-wtp m2e-wtp - Maven Integration for WTP 1.4.4.20200220-1005 org.eclipse.m2e.wtp.feature.feature.group Eclipse.org - m2e-wtp Marketplace Client 1.8.3.v20200526-1554 org.eclipse.epp.mpc.feature.group Eclipse Marketplace Client Mylyn Context Connector: Eclipse IDE 3.25.1.v20200512-2113 org.eclipse.mylyn.ide_feature.feature.group Eclipse Mylyn Mylyn Context Connector: Java Development 3.25.1.v20200512-2113 org.eclipse.mylyn.java_feature.feature.group Eclipse Mylyn Mylyn Task List 3.25.1.v20200514-1748 org.eclipse.mylyn_feature.feature.group Eclipse Mylyn Mylyn Task-Focused Interface 3.25.1.v20200512-2113 org.eclipse.mylyn.context_feature.feature.group Eclipse Mylyn Mylyn Tasks Connector: Bugzilla 3.25.1.v20200512-0316 org.eclipse.mylyn.bugzilla_feature.feature.group Eclipse Mylyn Mylyn WikiText 3.0.36.202002070035 org.eclipse.mylyn.wikitext_feature.feature.group Eclipse Mylyn Oomph Setup 1.17.0.v20200606-0914 org.eclipse.oomph.setup.feature.group Eclipse Oomph Project SonarLint for Eclipse 5.2.1.18852 org.sonarlint.eclipse.feature.feature.group SonarSource Tip of the Day UI Feature 0.2.1000.v20200522-1444 org.eclipse.tips.feature.feature.group Eclipse.org TM Terminal 4.6.0.202001311822 org.eclipse.tm.terminal.feature.feature.group Eclipse CDT Wild Web Developer 0.10.0.202006021616 org.eclipse.wildwebdeveloper.feature.feature.group Eclipse Wild Web Developer project WST Server Adapters 3.2.801.v201912051849 org.eclipse.wst.server_adapters.feature.feature.group Eclipse Web Tools Platform

nitind commented 4 years ago

@kevinwhine as I mentioned in the bug, that action only ever applied to files saved in designated JavaScript Source Folders using that specific editor. You didn't confirm that that's where the source file was, but in any event, that editor is no longer present in 4.16/2020-06.

kevinwhine commented 4 years ago

Are you confirming that this is not an issue are Eclipse 4.16 no longer uses the wild web Javascript editor?

I am double checking as the Eclipse folks pointed to here to this area when I raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=565046.

nitind commented 4 years ago

Quite the opposite, as it's what remains. The previous JavaScript Editor is not part of 2020-06, so this functionality is no longer offered, AFAIK.

kevinwhine commented 4 years ago

I apologise that my comprehension is not working to the level I want it to. I need to understand where is the correct place to report this issue.

thank you.

nitind commented 4 years ago

Since there is no longer a distinct "JavaScript Editor", I would have to guess here, as a feature request for the editor support you will have.

kevinwhine commented 4 years ago

For Wild Tools it is probably a feature request, but I trust you will understand that from a Eclipse JSDT history position it is now a gap/deficit

p-bakker commented 1 year ago

Any idea where such a feature ought to go? Is that something language servers take care of? Or some option in tm4e? Or is that something that must be implemented in WWD, either for all editors WWD 'controls' or on a per language basis?

I myself only do js/ts development, but I cannot think of any language where you'd not want to have the option to remove trailing whitespace and potentially subsequent empty lines.

I think using onEnterRules in tm4e one could at least remove whitespace on empty lines when hitting enter, so that if you hit enter on an indented line with some code and then hit enter again, at least the whitespace characters on the first empty line are removed. Maybe this is already part of the new tm4e onEnterrules config, but I haven't been able to test that out yet

mickaelistria commented 1 year ago

I myself only do js/ts development, but I cannot think of any language where you'd not want to have the option to remove trailing whitespace and potentially subsequent empty lines.

There is https://en.wikipedia.org/wiki/Whitespace_%28programming_language%29 , but not sure it's really industry-strandard ;) Do the "Format" action on the editor, provided by the language server, remove the lind endings? The language server would be free to implement that, as part of formatting or with onTypeFormatting or by sending some applyEdit upon receiving didChange. However, I don't think one should require a LS to be able to remove whitespaces on a random file. Eclipse IDE already has a command to remove whitespaces (Ctrl+3 > Remove trailing whitespaces), the tricky part becomes how to automate that on save; for that I don't have a good answer at the moment.

p-bakker commented 1 year ago

The rightclick > source > format option on .ts files does remove trailing.

Note that the rightclick > source > format option also replaces my space-based indents with tabs. Looks like WWD reads from Preferences > General > Editors > Text Editors > Insert spaces for tabs? Cause when I change that setting, it affects what formatting does.

Am not seeing any incoming applyEdits or onTypeFormatting

Which got me looking into being able to configure this on a project level, but that doesn't seem possible, correct?

I did find references to .editorconfig and found https://github.com/angelozerr/ec4e, which I installed, added a .editorconfig to my project, but it doesn't seem to have any effect: what is send to the lsp still seems to read from Eclipse prefs. Any thoughts on that @angelozerr?

And I found references to tsfmt.json, but it seems that is a legacy option that is only applicable for the TS lsp that shouldn't really be used

@mickaelistria tnx for the tip on Eclipse offering a command to remove trailing whitespace in the entire file. Been using Eclipse for over a decade, never knew that existed :-)

mickaelistria commented 1 year ago

Note that the rightclick > source > format option also replaces my space-based indents with tabs. Looks like WWD reads from Preferences > General > Editors > Text Editors > Insert spaces for tabs

Yes.

Which got me looking into being able to configure this on a project level, but that doesn't seem possible, correct?

Correct, unless the language server itself supports it (eg reading some configuration file on the project level, exactly like tsfmt.json). But I don't think this language server does support such configuration.

what is send to the lsp still seems to read from Eclipse prefs

The issue is that the language server is usually shared between multiple projects, so we cannot send configuration of 1 project and assume it's right for for the language server to use it for all projects.

Been using Eclipse for over a decade, never knew that existed :-)

Yes, it happens often to me as well. Fortunately now it's easier to search thanks to Ctrl+3 listing about everything available in the IDE, it often shows some good surprises like this one.

angelozerr commented 1 year ago

I did find references to .editorconfig and found https://github.com/angelozerr/ec4e, which I installed, added a .editorconfig to my project, but it doesn't seem to have any effect: what is send to the lsp still seems to read from Eclipse prefs. Any thoughts on that @angelozerr?

You can see in the README that only indent_style and indent_size aply is supported. The other preferences cannot be supported because of limitation of preferences scope of Eclipse IDE (you cannot have editor scope)

p-bakker commented 1 year ago

The issue is that the language server is usually shared between multiple projects, so we cannot send configuration of 1 project and assume it's right for for the language server to use it for all projects.

But when the client sends the format request to the LSP, it can send along several formatting options, see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_rangeFormatting. WWD already sends "options":{"tabSize":4,"insertSpaces":false} with the textDocument/rangeFormatting request

exactly like tsfmt.json). But I don't think this language server does support such configuration.

The TypeScript LSP does support tsfmt.json I think, see https://github.com/typescript-language-server/typescript-language-server/blob/92ccb07fec4fc8a4c76c89b061ab8a31f808c7a4/src/lsp-server.ts#L428

p-bakker commented 1 year ago

You can see in the README that only indent_style and indent_size aply is supported

I saw that, but those don't work for me either :-/

This is the .editorconfig placed in the root of my project:

root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

When I press TAB in the typescript editor or when I select something to do Ctrl-Shift-F to format, still tabs are used

mickaelistria commented 1 year ago

But when the client sends the format request to the LSP, it can send along several formatting options, see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_rangeFormatting. WWD already sends "options":{"tabSize":4,"insertSpaces":false} with the textDocument/rangeFormatting request

OK, you're right. Then this is a bug in LSP4E that seems to not read project settings. Can you please report it to LSP4E?

angelozerr commented 1 year ago

When I press TAB in the typescript editor or when I select something to do Ctrl-Shift-F to format, still tabs are used

Perhaps it is broken, I have no time today to support this project.

p-bakker commented 1 year ago

I have no time today to support this project.

Maybe tomorrow then :-)

Then this is a bug in LSP4E that seems to not read project settings But where are the project level settings for this? To my knowledge there are none, but that is where ec4e would come in (if it still works and if LSP4E then reads of the IPreferenceStore of the editor.

Or are you sure that LSP4E wouldn't ready it from from the editors preference store and thus that would be the bug to file with LSP4E?

p-bakker commented 1 year ago

The other preferences cannot be supported because of limitation of preferences scope of Eclipse IDE (you cannot have editor scope)

Bare with me for a sec...

So, couldn't the combination of ec4e, WWD and LSP4e get the following done:

Or am I over simplifying things here?

mickaelistria commented 1 year ago

The editors preference store is global and affects all projects. Here you want project-scope settings. So the various settings need to be set per-project and consumers also need to read project settings 1st before falling back to the global preference store.

ec4e is supposed to set project settings according to .editorconfig already.

But if LSP4E doesn't read project settings but only reads global preference store, then those project-specific settings aren't forwarded to the language server. This is most likely the only remaining issue/bug for this combination to work.

akurtakov commented 1 year ago

I wasn't aware of ec4e. Is there any reason to not have it in platform.text by default?

p-bakker commented 1 year ago

The editors preference store is global and affects all projects

My understanding is that ec4e modifies a Preference store per editor, not the global, workspace-level pref store (see last bullit on https://github.com/angelozerr/ec4e#similar-project)

But if LSP4E doesn't read project settings but only reads global preference store, then those project-specific settings aren't forwarded to the language server. This is most likely the only remaining issue/bug for this combination to work.

ok, so I'll file an issue with LSP4E then :-)

What then remains though is 2 things:

Personally I'm not that keen on the 'format on save', but particularly the trim_trailing_whitespace while editing I find a big miss

angelozerr commented 1 year ago

I wasn't aware of ec4e. Is there any reason to not have it in platform.text by default?

It was my goal when I started this project long time ago. IMHO I think platform should support .editorconfig, the main problem with Eclipse preferences is that it is not possible to support preference for a resource scope that editorconfig requires.

p-bakker commented 1 year ago

the main problem with Eclipse preferences is that it is not possible to support preference for a resource scope that editorconfig requires

@angelozerr in your opinion, is https://github.com/eclipse/lsp4e/issues/245 doable though?

mickaelistria commented 1 year ago

FWIW, I do believe it's doable, as we have access to ProjectPreferences object (that could be wrapped in a PreferenceStore, added to a ChainedPreferenceStore and so on).

angelozerr commented 1 year ago

@mickaelistria @akurtakov do you think platform could host ec4e?

mickaelistria commented 1 year ago

do you think platform could host ec4e?

please open an issue to eclipse.platform.text where we can discuss it.

p-bakker commented 1 year ago

FWIW, I do believe it's doable

@mickaelistria I'll take your word for it then :-)

angelozerr commented 1 year ago

please open an issue to eclipse.platform.text where we can discuss it.

done with https://github.com/eclipse-platform/eclipse.platform.ui/issues/877