zokugun / vscode-explicit-folding

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

Have to refresh VS Code folding setting for the extension to work #24

Closed AgamlaRage closed 3 years ago

AgamlaRage commented 3 years ago

VS Code 1.48.0 Explicit Folding 0.8.2

Issue

When opening VS Code the Explicit Folding extension seems to not be initialized.

In my case, the extension won't work until I refresh the settings.json by adding/removing/commenting any folding setting key.

GIF explanation:

  1. I just started VS Code (as I said, Explicit Folding is not working yet, you can see it on the style.scss)
  2. Then I move my cursor to the settings.json
  3. I comment a line of the Explicit Folding configuration
  4. Save settings.json
  5. After few seconds, VS Code seems to reinitialized something
  6. Explicit Folding is NOW working
  7. I uncomment the commented line
  8. Explicit Folding is STILL working

screen

Tests

Config

Here is my Explicit Folding config in VS Code settings.json

settings.json ```json { "folding": { "javascript": [ { "begin": "/*", "end": "*/", }, { "begin": "(", "end": ")", }, { "begin": "[", "end": "]", }, { "begin": "{", "end": "}", }, ], "json": [ { "begin": "{", "end": "}" }, { "begin": "[", "end": "]" }, ], "php": [ { "begin": "/*", "end": "*/", }, { "begin": "[", "end": "]", }, { "begin": "{", "end": "}", }, ], "css": [ { "begin": "{", "end": "}" }, ], "scss": [ { "begin": "{", "end": "}" }, { "begin": "(", "end": ")" }, ], "html": [ { "beginRegex": "<[a-z]+(>|.*?[^/]>)", "endRegex": "<\/[a-z]+>", }, ], } } ```
daiyam commented 3 years ago

@AgamlaRage Ya, I can reproduce the issue with VS Code 1.48.0. I will look at what has been changed into VS Code.

daiyam commented 3 years ago

I can't locate the regression since no code regarding the folding has recently been modified... You can try my spin of VS Code (MrCode) which doesn't suffer from this issue...

AgamlaRage commented 3 years ago

@daiyam I have this issue since I installed your extension (~1year). I don't think the problem comes from a recent change. I didn't report it because I found this workaround (modifying settings.json) that take me only a few seconds when I start VS Code again.

I will give a look to your MrCode for sure!

daiyam commented 3 years ago

So you had the issue before the updates I've made this spring ?

AgamlaRage commented 3 years ago

@daiyam Yes, I think so. As long as I remember using your plugin, I had this issue. I use your plugin, at least, since July 2019 (The proof is the issue I reported at this time #8 )

daiyam commented 3 years ago

Wow, I can't believe I've never catch this bug (I've always run a custom build to be able to control the folding...). I've tested on VS Code 1.36.1 and the bug is there. Damn! I will try to fix it asap but it might take some time...

daiyam commented 3 years ago

@AgamlaRage I've found the bug and a fix is on its way. Basically, the registry provides the folding providers in an FILO way. Since the extensions providers are registered before the default ones, you get the issue you are getting. (By editing the config, you are re-registering the providers) The fastest fix, it's to add a delay on the first registration of the providers... by default, it will be: 1000ms

AgamlaRage commented 3 years ago

@daiyam Sounds great! Thx for your reactivity.

As an additional idea : Be able to set a custom delay using VS Code settings.json (You already seem to had this idea, but just in case).

daiyam commented 3 years ago

I've already added it: explicitFolding.startupDelay :wink: The new version is up. Tell me if everything is ok.

AgamlaRage commented 3 years ago

Explicit Folding 0.9.0

I confirm that is working for the open AND visible files languages.

But it's initialized only:

Steps to reproduce:

Test 1 - NOT WORKING

  1. Open blank VS Code (run vscode.exe or open blank workspace)
  2. Open any file (tested with .js, .php, .scss)

Test 2 - NOT WORKING

Let say we have a workspace with a .php file visible. And a .js file, that is also open but not visible because on an other tab.

  1. Open the workspace.
  2. Explicit Folding is working for the .php file (The file that is visible when VS Code starts)
  3. Switch to the .js file. Explicit Folding is not working for Javascript files

screen

Test 3 - HALF WORKING (only with PHP language, I don't know why)

Let say we have a workspace with .js file visible. A .php file AND a .scss file, that are also open but not visibles because on an other tabs.

  1. Open the workspace.
  2. Explicit Folding is working for the .js file (The file that is visible when VS Code starts)
  3. Switch to the .php file. Explicit folding is working (I don't know why)
  4. Switch to the .scssfile. Explicit folding is not working (As intended, like in Test2)

screen2

In this case (Test 3), .php files don't need to be visible on a tab for Explicit Folding to work. This happend only with .php files. Also tested with no PHP extension enabled on VS Code, same result.

Possible solution

Maybe the only way is to re-initialized the extension every time a language is initialized. (But I don't know if it's possible)

daiyam commented 3 years ago

Ya, I'm having the same issues... Still the same bug, the default foldings are overwriting the foldings provided by the extension... My hacky way doesn't work in those cases. The PR microsoft/vscode#54200 would be the perfect fix since we could select which folding providers to use (default one or this extension). I will try to revive the PR or find another bypass.

daiyam commented 3 years ago

@AgamlaRage Thanks you for your detailed reports, it was of great help. I have a more hacky way to fix the issue but I can push it directly to the extension because it would require to list all the languages... Let me explain so you can try it.

In the file package.json (located at %USERPROFILE%\.vscode\extensions\zokugun.explicit-folding-0.9.0), if you replace:

"activationEvents": [
    "*"
],

with

"activationEvents": [
    "onLanguage:javascript",
    "onLanguage:php",
    "onLanguage:scss",
    "*"
],

and restart VS Code, the extension will be reloaded when a file in those languages is viewed.

AgamlaRage commented 3 years ago

Hello,

it seems to work randomly. I made two GIF to show you what is happening but I can't find an explanation or a pattern.

Modifications

TEST 1:

screen-not-working-when-starting-vs-code

TEST 2:

screen


PS:

daiyam commented 3 years ago

VSCode reloads the extensions when it's viewing a new file type. Keep explicitFolding.startupDelay at 1000 and wait just after viewing a new file type.

You should try MrCode which avoids any conflict between folding providers.

daiyam commented 3 years ago

@AgamlaRage Have you tried MrCode?

AgamlaRage commented 3 years ago

@daiyam Sorry, no. I have no time to code at the moment, I also didn't open VSCode in a while (I hope soon). If you prefer to close the issue, I'll understand.

daiyam commented 3 years ago

When doing a final review of your issue and still able to reproduce the issue, I've found the solution: using deferred provider. So the real folding provider is always loaded after the language's folding provider which fix the issue. I just wonder why I haven't thought of that solution before... The fix is in the version v0.13.0.

AgamlaRage commented 3 years ago

@daiyam Hello, since I updated to v0.13.0 I didn't see this bug again! šŸ”„ šŸ”„ šŸ”„

Thank you so much

daiyam commented 3 years ago

I'm happy that it's finally working but it's a hacky solution. Basically, when the deferred provider is called to provide the folding ranges of a file, for only the first time, it will register of the real provider (with the delay) and will unregister itself.