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

Editor always indents with tabs, not spaces #58

Closed
jalbr74 opened this issue May 19, 2016 · 12 comments
Closed

Editor always indents with tabs, not spaces #58

jalbr74 opened this issue May 19, 2016 · 12 comments
Milestone

Comments

@jalbr74
Copy link

jalbr74 commented May 19, 2016

I'm not sure if I'm doing something wrong, but I can't seem to get the TypeScript editor to indent with spaces. It always uses tab characters.

I've verified my preferences for General > Editors > Text Editors are set to "Insert spaces for tabs", but I still always get the tab character.

I've also verified that if I open a *.txt file using Open With > Other > JavaScript (Salsa) Editor, I always get tab characters.

Any idea what I can do differently?

@angelozerr
Copy link
Owner

@jalbr74 ndeed it is not supported.

Your requirement is about formatting configuration. Today you can use Ctrl+Shift+F to format your ts file which uses tsserver which uses spaces instead of using tabs.

So to resolve this issue:

  • we need to add preferences to customize format (and set it to tsserver with 'configiuration' command). We could add an UI preferences for that (use tabs, spaces) or using JavaSCript JSDT UI preferences, but there are too options. So I think the better idea is to add an UI preferences with format configuration supported by tsserver. An another idea is to set your format configuration inside a .editorconfig (see http://editorconfig.org/)
  • call 'configure' command of tsserver to send to the tsserver the format preferences.

@jalbr74 @piotrtomiak @micaelgallego @atsu85 what do you think about where we can save the format configuration.

  • in an Eclipse preferences?
  • in an editorconfig
  • both?

I think I will start with an UI preferences.

@jalbr74
Copy link
Author

jalbr74 commented May 20, 2016

I wouldn't mind just editing an Eclipse plugin config file directly, if that would be easiest.

I just looked in the JSDT config file:
${workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.jsdt.ui.prefs

... and saw the configuration parameter: "org.eclipse.wst.jsdt.ui.formatterprofiles" with the following values:
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.wst.jsdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>

Do you think it would make sense to add the file: "ts.eclipse.ide.ui.prefs", and add the parameter: "ts.eclipse.ide.ui.formatterprofiles" with the same values as JSDT?:
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.wst.jsdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>

I already tried it, and it didn't work. But do you think that would be good way to go, to at least get there quickly for now?

@angelozerr
Copy link
Owner

@jalbr74 this file preference is managed with UI preferences. So I don't want to develop something that I will remove it.

As I said, I will start to implement an UI preferences with the supported formatting of tsserver (like VSCode does).

@atsu85
Copy link

atsu85 commented May 20, 2016

what do you think about where we can save the format configuration.

I have also thought about .editorconfig - that would embrace the concept of this plugin to allow sharing the project between Eclipse and other IDEs.
So I'd say, that whenever possible, for the teams where at least on person doesn't use this plugin, it is good to store the settings in a place, that other IDEs can recognize it without extra effort (or at least provide a way to store the settings there).

But I understand that You'll also need to consider other factors, such as time to implement it.

@angelozerr
Copy link
Owner

The big problem with .editorconfig' is that you can host it anywhere and you can have a format configuration different from 2 files which are not hosted in the same folder.

And tsserver supports format option for the whole ts files of the project. You cannot have a format option for a file and and an another for an another file.

I have suggsted to TypeScript team to support "formatOption" inside tsconfig.json at microsoft/TypeScript#8709

With that we could share configuration between IDE.

So for the moment I will store preferences with standard Eclipse preferences.

@atsu85
Copy link

atsu85 commented May 20, 2016

The big problem with .editorconfig' is that you can host it anywhere and you can have a format configuration different from 2 files which are not hosted in the same folder. And tsserver supports format option for the whole ts files of the project.

Yes I know, that in theory the user can add several .editorconfig files for the same project, but how often is it happening in practice? I'd still vote for .editorconfig file that is located next to tsconfig (the one in the root, if there are several tsconfig.json files and tsserver doesn't support different formatting for several tsconfig.json configurations).

But to be honest, at this maturity level of this plugin, it really isn't important how You solve it - already having any kind of formatting support by the plugin by the plugin is good before the official release. Having the opportunity to configure it in any way just makes it great!

@angelozerr
Copy link
Owner

angelozerr commented Aug 10, 2016

@jalbr74 @atsu85 I have implemented editor+format options configuration. Once the following job https://opensagres.ci.cloudbees.com/job/typescript.java/138/ will be finished you will able to install typescript.java.

To configure tabs, spaces, typescript format, you can do it with a classic preferences page:

TypeScriptFormatterPreferences

Please tell me if it is OK for you.

See https://github.com/angelozerr/typescript.java/wiki/Editor-Features#formatting for more information.

In the future I would like to support .editorconfig, but it's little hard since Eclipse doesn't support the capability to update preferences for a given editor (it's project preferences). See ncjones/editorconfig-eclipse#30 for more information.

I hope @mickaelistria will have time to work about this issue.

@mickaelistria
Copy link
Contributor

The default value should be to inherit the default setting for platform text IMO. Multiplying the options to override indentation seems nice but if every editor does that, it can become a terrible mess for end-users to figure out what to change.

Rather than boolean, I'd rather see combo such as

  • Indentation |Inherit default (tabs) |v| with possible values being "Inherit default" (with a decrorator to explain where to set default), "spaces", "tabs".

@jalbr74
Copy link
Author

jalbr74 commented Aug 17, 2016

@angelozerr Indenting has been working perfectly for me now. Thanks for the fix!

@atsu85
Copy link

atsu85 commented Aug 17, 2016

@angelozerr, actually great place to store formatting preferences would be tslint.json. Tslint uses that file to lint typescript source files and in addition to checking for errors there are rules to check indent and other formatting rules related to whitespaces, linebreak style, no trailing whitespaces and many more.

Using this file would have multiple benefits:

  1. formatting styles are defined in a format that is not related to any specific IDE
  2. usage can be checked by build tools, IDEs (Atom, IntelliJ IDEA and probably many more) and command-line tools.

What do You think?

@angelozerr
Copy link
Owner

What do You think?

Yes sure! @atsu85 please create a new issue with your idea. If we do that we must think which config to use (eclipse preferences, tslint, etc)

@angelozerr
Copy link
Owner

angelozerr commented Aug 17, 2016

Rather than boolean, I'd rather see combo such as

@mickaelistria I have used the same config than TypeScript (and VSCode).

The default value should be to inherit the default setting for platform text IMO.

Yes I agree but never see that ? JSDT has her own config too.

Multiplying the options to override indentation seems nice but if every editor does that, it can become a terrible mess for end-users to figure out what to change.

I agree,I don't know if it's easy to inherit from platform text (and support changes too of this preference)

Please create a new issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants