flow / flow-for-vscode

Flow for Visual Studio Code
Other
996 stars 111 forks source link

Support proper code folding with Flow syntax #389

Open SillyFreak opened 4 years ago

SillyFreak commented 4 years ago

VS Code does not understand Flow type syntax and therefore gets confused by some non-js constructs when it comes to properly fold code blocks. Take this example code:

// @flow

type Ex1 = {
  // this is visible but shouldn't be

  foo: number,

  // this is visible but shouldn't be
};

function ex2() {
  // this is folded away

  type foo = {| x: number |};

  // this is visible but shouldn't be
}

function ex3() {
  // this is folded away

  function foo(x: { ... }) {}

  // this is visible but shouldn't be
}

function ex4() {
  // this is folded away

  const foo = (x: { ... }) => null;

  // this is visible but shouldn't be
}

function ex5() {
  // this is folded away

  function inner() {
    const foo = (x: { ... }) => null;
  }

  // this is visible but shouldn't be
}

image

When using the Fold All action, some of the comments will not be hidden because

With nested blocks (ex5), the interruption seems to end exactly the enclosing block, derailing the ancestor blocks by one closing brace each: the inner function ends one line too early at line 39, making its closing brace at line 40 end the ex5 function.

As even in Flow all braces match up, just in non-JS ways, I'm not sure if that is something that would have to be fixed in VS Code or here; I decided to report here because it is definitely impacting the Flow development experience.

dandean commented 11 months ago

It's amazing to me that this hasn't been fixed yet.