lifeart / vscode-ember

VSCode client for the Ember Language Server
https://marketplace.visualstudio.com/items?itemName=lifeart.vscode-ember-unstable
Other
30 stars 9 forks source link

Code folding lost when `vscode-glimmer` enabled #43

Open evoactivity opened 1 year ago

evoactivity commented 1 year ago

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 commented 1 year ago

Hi @evoactivity! Thank you for your report!

You may try to disable builtin code folding in uELS (https://github.com/lifeart/ember-language-server/pull/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 commented 1 year ago

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

So to set the scene

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 commented 1 year ago

@evoactivity i'm wondering, is manual lang config is working for pure vscode? (like mentioned in https://github.com/microsoft/TypeScript/issues/23382#issuecomment-416890363)

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 commented 1 year ago

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 https://github.com/typed-ember/glint/issues/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 commented 1 year ago

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

mattmcmanus commented 1 year ago

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

evoactivity commented 1 year ago

@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 :)