Open simark opened 7 years ago
That would require have more preferences than "tabSize". In vim, for example, you have these:
set tabstop=8 : Width of a tab character when displayed (or more precisely, the multiple of columns to which the tab characters will span to)
set shiftwidth=2 : When you press `>>` or `<<` in Vim, of how many columns should it move left of right, I am not sure we would have an equivalent in Theia.
set softtabstop=2 : When you press the tab key, of how many columns should it move right
set noexpandtab : When you have one full tabstop worth of space, replace that with a tab. "set expandtab" would mean the opposite, expand tab characters with the equivalent amount of spaces.
This is my interpretation, you can find the real doc by doing :help tabstop
for example.
So at the very least, we will need a setting for:
Note I tried to use that indent in VSCode and Atom and they both do not support it at all. Nor is there any extensions that do :(
So I'm pretty sure monaco doesn't.
I think the best thing would be to support auto indentation based on indent. (indent supports pretty much any indentation style). That way we could define the indentation in indent terms.
That would be for C/C++ only however, so providing a hook for auto indent based on the language would help.
So that clang-format could be used too for example. Or a language server.
IMO TAB should default to autoindent the line too rather than placing whatever character. Or have an easy option to make it so.
The behavior of the tab key could be configurable, but I think we should always have a basic mode where tab just indents manually. We won't always know the language being edited and know how to indent it, so we need to have a solid way for the user to do whatever they want. After that, we can get more fancy for some languages we want to have better support for.
Should we file an issue with the monaco project to show that there is interest in supporting this kind of behavior?
I'm not sure this should go into the editor directly ? If you know the number of tabs or the number of spaces you can know the indent level of a line in an extension then rewrite a number of spaces to tabs etc... I've seen some extensions do things like that.
formatting is part of the LSP and is already in Clangd although I don't think its possible to configure it well. It might be better to experiment with clang-format and document what's missing there.
IIRC clang-format supports the gnu indent style, but not the actual formatting of GDB code.
I wonder if it could do indent only
The current issue is not related to any language support. It should be possible to set some preferences such that if the user creates a new .txt file and presses tab a few times, Theia follows the rules outlined above. So let's say you pressed tab a few times in an empty plain text file, it would successively contain this:
Press tab once:
<space><space>
and again:
<space><space><space><space>
and again:
<space><space><space><space><space><space>
and again:
<tab>
I suppose it will be possible for some language support to override this if the language dictates a standard, but it should still be possible to set the preferences to alter the basic indentation behavior of all files.
When working on GNU projects (e.g. GDB), we have to use a particular indent style. I think that style is funky enough that when we are able to support this, we will be able to support pretty much anything. I don't know if Monaco is flexible enough out of the box to support that only through configuration, that will have to be investigated.
Each indentation level is two spaces, so when you press tab or shift-tab, it should increase or reduce the indentation of by two spaces. However, when you reach 8 consecutive spaces, that should be replaced by a tab.
Here's an example of properly indented code:
Here's the same code with spaces replaced with
<s>
and tabs with<t>
To be clear, this issue is not about the editor being smart about where to place brackets or auto-ident (although that would be nice in the future), but just being able to specify what whitespaces are inserted when pressing tab.