Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code folding lost when vscode-glimmer enabled #43

Open
evoactivity opened this issue Jul 11, 2023 · 7 comments
Open

Code folding lost when vscode-glimmer enabled #43

evoactivity opened this issue Jul 11, 2023 · 7 comments

Comments

@evoactivity
Copy link

evoactivity commented Jul 11, 2023

I'm using vscode-glimmer and working with template tags in gts files through ember-template-imports. I'm seeing an issue where code folding is only supplied to the template tag. Very breifly I see the mostly correct code folding arrows, then I think when the ember language server starts the folding arrows are only applied to the template tag and it's contents.

If I disabe ELS but not vscode-glimmer the folding returns. If I disable vscode-glimmer but not ELS the folding returns. There is something that happens between them to break code folding. I don't know anything about LSP's otherwise I'd tackle this myself.

image

As a side note I'm using vscode-glimmer instead of Glimmer Templates Syntax for VS Code because it supports ember-template-imports and glint.

@lifeart
Copy link
Owner

lifeart commented Jul 11, 2023

Hi @evoactivity! Thank you for your report!

You may try to disable builtin code folding in uELS (lifeart/ember-language-server#364)
Here is general implementation: https://github.com/lifeart/ember-language-server/tree/component-context-info-origin/src/folding-provider

I'm looking forward to improve ember-template-imports and gts support for Glimmer Templates Syntax for VS Code and open for any related PR's.

@evoactivity
Copy link
Author

When I try disabling the builtin code folding I get no code folding at all.

So to set the scene

  • vscode provides basic built in code folding for any text without an active language serve (this is just based on observation)
  • I am in a glimer-ts filetype instead of typescript
  • typescript language server will not start up for a glimmer-ts file so no TS language features provided
  • ELS will start up for a glimmer-ts file
    • vscode sees folding provided by ELS and turns off default folding
    • ELS provides code folding for templates only
  • Glint will start up for a glimmer-ts file
    • No code folding provided

If the above is correct I think it will mean the code folding of ELS might need to be expanded to work with JS and TS. Hopefully that just means copying the implementation from https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/folding.ts

@lifeart
Copy link
Owner

lifeart commented Jul 12, 2023

@evoactivity i'm wondering, is manual lang config is working for pure vscode? (like mentioned in microsoft/TypeScript#23382 (comment))

this.client.execute('getOutliningSpans' in https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/folding.ts#L30C26-L30C65 seems calling ls itself, we have to figure out how properly call it, and keep in mind it may be not initialized (disabled) due to glint.

In general, I think we could copy-paste whole https://github.com/Kingwl/TypeScript/blob/cbaefad491f06b521d70426f61da5bad0c722fae/src/services/outliningElementsCollector.ts to uELS, because it's likely quite stable.

Or we could write our own minimal folding logic for js/ts (for blocks, functions, classes)

Editor options may specify custom folding strategies: https://github.com/microsoft/vscode/blob/48cd8e0c1b142a46f0956b593d8331145634658e/src/vs/editor/common/config/editorOptions.ts#L586

It seems we could use multiple providers: https://github.com/microsoft/vscode/blob/main/src/vs/editor/contrib/folding/browser/folding.ts#L78

Also, vscode may resolve folding rules from lang configuration: https://github.com/microsoft/vscode/blob/48cd8e0c1b142a46f0956b593d8331145634658e/src/vs/editor/common/model/guidesTextModelPart.ts#L53

@evoactivity
Copy link
Author

i'm wondering, is manual lang config is working for pure vscode?

This certainly helped! It doesn't match one-to-one with what typescript provides (most obviously missing import folding) but much better than no folding at all.

Also, vscode may resolve folding rules from lang configuration

The lang config can provide folding rules but they are regex based, I don't think it's powerful enough to replace the language server folding providers. Happy to be proven wrong here though.


A possible related topic I'm tracking is missing semantic token scopes typed-ember/glint#601. Originally I thought this would be something Glint should handle but now I'm thinking it might be more appropriate for ELS if we end up copying chunks of the typescript language features. What are your thoughts on that?

@lifeart
Copy link
Owner

lifeart commented Jul 12, 2023

In general I'm good with semantic tokens in uELS (already checked it before for glimmer syntax)

@mattmcmanus
Copy link

I'm also seeing this issue. I'm loosing folder in all files though at the moment. (PTL for extension bisect!)

@evoactivity
Copy link
Author

evoactivity commented Jul 27, 2023

@mattmcmanus if you install this extension instead of vscode-glimmer you should get folding back, myself and @lifeart made a number of updates to support gjs/gts. Right now the folding strategy is just indentation based instead of what the TS language server provides but it is better than nothing.

I plan to circle back on this soon but if you feel like a challenge a PR would be most welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants