12

Closed

Visual Studio indenting and regions collapsing

description

(from: https://typescript.codeplex.com/discussions/470775)

Hey.

I'd like to suggest you guys to use the same "code formatting/indenting" engine that is used on javascript, also for typescript editor (the same or something inherited from it). I don't know if you guys are the responsible on embedding the TS in the Visual Studio, but anyway, I think you could forward this, so here are the reasons:

Code Indentation
In JS file, I can format my code as follow:
$.get(url, null, null, "json").done(function (data)
{
    //ok
})
.fail(function (err)
{
    //fail
});
And, if I press Ctrl+K+D (reformat), the engine respects the way it is formatted.
But if I reformat the same code above in a TS file, the result is:
$.get(url, null, null, "json").done(function (data)
{
    //ok
})
    .fail(function (err)
    {
        //fail
    });
It throws the .fail to right!


Regions collapsing
I'm used to code with brackets in new lines. The typescript options permits me to set the brackets on new lines. Also, I like to collapse the functions so I can give a quick look if the class face is pretty. But, collapsing + brackes on new lines are behaving a little weird. See:
In a JS file, if I collapse the functions, I got this visual.
    method1() [...]
    method2() [...]
    method3() [...]
Beautifull collapsed!

But in a TS file, the visual is:
    method1()
[...]
    method2()
[...]
    method3()
[...]
It shows the double of lines, and causes the lose of focus, because the method is indented, and the collapsed glyph is always at first column, no matter where the code starts.
Closed Jul 28 at 10:18 PM by jonturner
As part of our move to GitHub, we're closing our CodePlex suggestions and asking that people move them to the GitHub issue tracker for further discussion. Some feature requests may already be active on GitHub, so please make sure to look for an existing issue before filing a new one.

You can find our GitHub issue tracker here:
https://github.com/microsoft/typeScript/issues

comments

ronchese wrote Nov 26, 2013 at 4:04 PM

Hey. Thanks for watching the work item.

Don't forget about this situation also, this does not collapse:
//this does not collapse
loadNextPage = () =>
{
    this.loadNextPageWithCallbacks();
}

//neither
loadNextPage = () => {
    this.loadNextPageWithCallbacks();
}

prgjonas wrote Dec 21, 2013 at 9:48 AM

+1 for the collapse feature!

We use json within ts to describe data structure, which works very well together with typescript typechecking:
var formdescriber:IFormDescriber = {
    "name" : "Sample form",
    "sections": [
        {
            "start": [
                {
                    "name": {
                        "type": "text",
                        "label" : "Name"
                    }
...
With the collapse feature we're used to from the js editor the big json structure will get much easier to handle:
var formdescriber:IFormDescriber = {
    "name" : "Sample form",
    "sections": [
        {
            "start": [
            ...
           ],
            "describe": [
            ...
           ],
 

MichaelHawker wrote Jan 23 at 8:35 PM

Also, if you put your arguments to a function on separate lines the indenting gets weird.
function someFunction(
    id: number,
    title: string
    ) {
            someOtherFunction(); // typescript forces a double indent here when hitting 'enter' - formatting the document returns it to proper indenting.
}
It'd be nice to be able to put the first argument on the same line as the function and have them line up though too:
function someFunction(id: number,
                      title: string) {
}