zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
99 stars 14 forks source link

For some language servers (example: Elixir), adding ANY folding rule disables all other folding #26

Closed lastobelus closed 3 years ago

lastobelus commented 3 years ago

VSCode Version: 1.50.1

With this extension installed and a folding rule added, Elixir code folds only by this extension's rules (as though your explicit strategy PR were implemented :) )

This also seems to be happening in other folding extensions and/or language servers (ex: see this issue).

Not all languages have this problem, for example javascript files seemed fine.

Some elixir code for testing (using the ElixirLS extension):

defmodule KV.Registry do
  use GenServer

  @impl true
  @spec init(:ok) :: {:ok, %{}}
  def init(:ok) do
    {:ok, %{}}
  end

  # region [ callbacks ]
  @impl true
  def handle_call({:lookup, name}, _from, names) do
    {:reply, Map.fetch(names, name), names}
  end

  # endregion [callbacks]
end

Adding any rule to "folding" settings will break default folding, whether or not it matches.

(my reason for using your extension is that the built-in VSCode # region folding requires no indent on the # region comment, but the elixir ls autoformats all comments to match the indent of surrounding code.)

daiyam commented 3 years ago

+1

daiyam commented 3 years ago

@lastobelus I've took another look at the issue. It seems that ElixirLS doesn't provide any foldings so VSCode uses the indentation provider as a fallback. So when my extension provides a folding, that fallback doesn't happened and so the rest of the code doesn't have any foldings...

I'm not sure how the language foldings are defined but here what I've found in ElixirLS:

elixir-language-configuration.json
  "folding": {
    "markers": {
      "start": "^\\s*(@(moduledoc|typedoc|doc)\\b\\s+\"\"\")|(#\\s*region\\b)",
      "end": "^\\s+(\"\"\")|(#\\s*endregion\\b)",
    }
  }

syntaxes/elixir.json
"foldingStartMarker": "(after\|else\|catch\|rescue\|\\-\\>\|\\{\|\\[\|do)\\s*$",
"foldingStopMarker": "^\\s*((\\}\|\\]\|after\|else\|catch\|rescue)\\s*$\|end\\b)",

Looks like # region should have been already folded. If you remove the do and the end of the first line of your code, VSCode is still folding the module when it shouldn't based on the given regexes (it's folded due to the indent).

I've just added the support for "editor.foldingStrategy": "explicit & indentation" in MrCode (my version of VSCode). With that config, both my extension and the indentation provider can provide foldings at the same time. I've tested it and it's working.

daiyam commented 3 years ago

@lastobelus Can you try the following configuration with the latest version of the extension?

"folding": {
    "elixir": [
        {
            "beginRegex": "#\\s*region\\b",
            "endRegex": "#\\s*endregion\\b"
        },
        {
            "indentation": true
        }
    ],
}
kalingibbons commented 3 years ago
"folding": {
        "python": [
            {
                "beginRegex": "\"\"\"",
                "endRegex": "\"\"\""
            },
            {
                "indentation": true
            }
        ],
    },

Works fantastic in Python 🥳