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

Fold All Regions feature doesn't work #2621

Closed
aeschli opened this issue Oct 24, 2018 · 24 comments · Fixed by OmniSharp/omnisharp-roslyn#1748
Closed

Fold All Regions feature doesn't work #2621

aeschli opened this issue Oct 24, 2018 · 24 comments · Fixed by OmniSharp/omnisharp-roslyn#1748
Assignees
Labels

Comments

@aeschli
Copy link
Contributor

aeschli commented Oct 24, 2018

From @suadev on October 18, 2018 8:42

  • VSCode Version: 1.28.2
  • OS Version: Windows

"Fold All Regions" feature doesn't work neither by ctrl+k, ctrl+8 nor by F1 menu.

Copied from original issue: microsoft/vscode#61220

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

From @vscodebot[bot] on October 18, 2018 8:42

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

Please add a code sample. I tried with the folloing sample and it worked
foo.ts

//#region
Test
//#endregion
//#region
Test2
//#endregion
  • ctrl + k / ctrl + 8: folds all regions
  • ctrl + k / ctrl + 9: unfolds all regions

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

From @suadev on October 23, 2018 10:43

@aeschli sorry, i should have specified the language.

It looks, it's ok for .ts file.

But for .cs file, it doesn't work.

public class foo
{
    #region newregion
    int i = 0;
    #endregion
}

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

Do you use an extension for c# ?

Out of the box you get indentation based folding with region markers sand your example works the same way as my example.
But maybe an extension adds language specific folding and doesn't mark the regions correctly.

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

From @suadev on October 23, 2018 14:14

Yes, i use c# extension that powered by omnisharp. My whole extension list;

image

@aeschli
Copy link
Contributor Author

aeschli commented Oct 24, 2018

The problem is with the C# extension's foldingRangeProvider: Ranges originating from #region/#endregion need be marked with Kind: FoldingRangeKind.Region.

@akshita31
Copy link
Contributor

@suadev What are the keys you are using to fold the region. I tried the combination specified here https://code.visualstudio.com/docs/editor/codebasics#_folding and it seems to work fine for me. Note that in using Fold Level X (Ctrl+K Ctrl+2 for level 2) folds all regions of level X, except the region at the current cursor position the region at the current cursor position will not be folded.

@suadev
Copy link

suadev commented Oct 31, 2018

@akshita31 as i said in my first post;

"Fold All Regions" feature doesn't work neither by ctrl+k, ctrl+8 nor by F1 menu.

@akshita31
Copy link
Contributor

akshita31 commented Oct 31, 2018

@suadev As per the vscode documentation here : https://code.visualstudio.com/docs/editor/codebasics#_folding, "Fold All" is Ctrl K+ Ctrl 0(zero) and that seems to work fine for me. Can you try that once ?

@akshita31
Copy link
Contributor

However I do agree that Fold All regions through F1 doesnt work here.

@suadev
Copy link

suadev commented Oct 31, 2018

@akshita31

It's not "Fold All", The feature that i am talking about is "Fold all regions" :)

@akshita31
Copy link
Contributor

@suadev Apologies I got a bit confused here. I am totally able to reproduce the problem.

@akshita31
Copy link
Contributor

akshita31 commented Oct 31, 2018

On further investigation, I realised that we are using the "BlockStructureService" from roslyn to provide the spans for CodeFolding. The "BlockType" defined in roslyn doesn't have an explicit type for a "Region" - http://source.roslyn.io/#Microsoft.CodeAnalysis.Features/Structure/BlockTypes.cs,863b31bd5e041d18. For regions it returns the base type called "NonStructural".

In omnisharp-roslyn - https://github.com/OmniSharp/omnisharp-roslyn/blob/94114978fdfa233c1391b6f630f092db5aa87053/src/OmniSharp.Roslyn.CSharp/Services/Structure/BlockStructureService.cs#L80 we are comparing the type and checking if the type == "Region" which is not returned by roslyn as of now, hence we return the null type to the extension and the given region is not marked as a "Region"

@rchande Thoughts here ?

@zeroskyx
Copy link

@rchande: anything I can do to help you with the issue? Would be really great to have this working again :) Thanks in advance!

@rchande
Copy link

rchande commented May 22, 2019

@zeroskyx The issue is that OmniSharp isn't properly marking "region" folding units as having the "region" kind. Thus, when you issue the command in VS Code, the C# extension doesn't think it has any regions to fold.

@zeroskyx
Copy link

@rchande: thank you for the clarification -- what would be the steps to fix the issue? It would be really great to have it working again with .NET Core 3 coming up :)

Keep up the great work!

@zeroskyx
Copy link

Have you given up on this issue? With region support in almost every language now (even Bash) it's sad to see that this feature only does not work in C# 😕

@JoeRobich
Copy link
Member

This issue is fixed in 1.21.17

@suadev
Copy link

suadev commented Apr 14, 2020

@JoeRobich it doesn't work. Between, when i start vscode, i see this exception;

System.InvalidCastException: Specified cast is not valid.
at Roslyn.Utilities.EventMap.GetRegistries_NoLock[TEventHandler](String eventName)
at Roslyn.Utilities.EventMap.AddEventHandler[TEventHandler](String eventName, TEventHandler eventHandler)
at lambda_method(Closure , LifetimeContext , CompositionOperation )
at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate(Int32 sharingId, CompositionOperation operation, CompositeActivator creator)
at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider.<>c__DisplayClass3_21.<GetImportManyDescriptor>b__4(ExportDescriptor e) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()
at System.Linq.Buffer1..ctor(IEnumerable1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at lambda_method(Closure , LifetimeContext , CompositionOperation ) at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate(Int32 sharingId, CompositionOperation operation, CompositeActivator creator) at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider.<>c__DisplayClass3_21.b__4(ExportDescriptor e)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at System.Composition.Hosting.Core.CompositionOperation.Run(LifetimeContext outermostLifetimeContext, CompositeActivator compositionRootActivator)
at System.Composition.Hosting.Core.LifetimeContext.TryGetExport(CompositionContract contract, Object& export)
at System.Composition.CompositionContext.GetExport(CompositionContract contract)
at System.Composition.CompositionContext.GetExports(Type exportType, String contractName)
at System.Composition.CompositionContext.GetExports[TExport](String contractName)
at OmniSharp.Stdio.Host.Initialize() in D:\a\1\s\src\OmniSharp.Stdio\Host.cs:line 57
at OmniSharp.Stdio.Host..ctor(TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource) in D:\a\1\s\src\OmniSharp.Stdio\Host.cs:line 51
at OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_1.

b__1() in D:\a\1\s\src\OmniSharp.Stdio.Driver\Program.cs:line 66
at OmniSharp.HostHelpers.Start(Func`1 action) in D:\a\1\s\src\OmniSharp.Host\HostHelpers.cs:line 29

@suadev
Copy link

suadev commented Apr 14, 2020

It seems, OmniSharp doesn't start properly on my machine. The exception is added on above. Any idea? @aeschli @filipw

@filipw
Copy link
Contributor

filipw commented Apr 14, 2020

do you have a repro project?
also, can you post full Omnisharp log?

@suadev
Copy link

suadev commented Apr 14, 2020

@filipw i am working on a dotnet core 3.1 web api project. Tried on another project and got same exception. The whole log:

Starting OmniSharp server at 4/14/2020, 9:31:30 AM
Target: c:\source\Pms.Backend\PMS.sln

OmniSharp server started.
Path: C:\Users\skose.vscode\extensions\ms-dotnettools.csharp-1.21.17.omnisharp\1.34.5-beta.28\OmniSharp.exe
PID: 15168

Starting OmniSharp on Windows 6.2.9200.0 (x64)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: Visual Studio Enterprise 2019 16.4.29806.167 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"
2: StandAlone 16.0 - "C:\Users\skose.vscode\extensions\ms-dotnettools.csharp-1.21.17.omnisharp\1.34.5-beta.28.msbuild\Current\Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Enterprise 2019 16.4.29806.167 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"
System.InvalidCastException: Specified cast is not valid.
at Roslyn.Utilities.EventMap.GetRegistries_NoLock[TEventHandler](String eventName)
at Roslyn.Utilities.EventMap.AddEventHandler[TEventHandler](String eventName, TEventHandler eventHandler)
at lambda_method(Closure , LifetimeContext , CompositionOperation )
at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate(Int32 sharingId, CompositionOperation operation, CompositeActivator creator)
at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider.<>c__DisplayClass3_21.<GetImportManyDescriptor>b__4(ExportDescriptor e) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()
at System.Linq.Buffer1..ctor(IEnumerable1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at lambda_method(Closure , LifetimeContext , CompositionOperation ) at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate(Int32 sharingId, CompositionOperation operation, CompositeActivator creator) at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider.<>c__DisplayClass3_21.b__4(ExportDescriptor e)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at System.Composition.Hosting.Core.CompositionOperation.Run(LifetimeContext outermostLifetimeContext, CompositeActivator compositionRootActivator)
at System.Composition.Hosting.Core.LifetimeContext.TryGetExport(CompositionContract contract, Object& export)
at System.Composition.CompositionContext.GetExport(CompositionContract contract)
at System.Composition.CompositionContext.GetExports(Type exportType, String contractName)
at System.Composition.CompositionContext.GetExports[TExport](String contractName)
at OmniSharp.Stdio.Host.Initialize() in D:\a\1\s\src\OmniSharp.Stdio\Host.cs:line 57
at OmniSharp.Stdio.Host..ctor(TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource) in D:\a\1\s\src\OmniSharp.Stdio\Host.cs:line 51
at OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_1.

b__1() in D:\a\1\s\src\OmniSharp.Stdio.Driver\Program.cs:line 66
at OmniSharp.HostHelpers.Start(Func`1 action) in D:\a\1\s\src\OmniSharp.Host\HostHelpers.cs:line 29

@filipw
Copy link
Contributor

filipw commented Apr 14, 2020

according to your log, you are on the old version of omnisharp
Path: C:\Users\skose.vscode\extensions\ms-dotnettools.csharp-1.21.17.omnisharp\1.34.5-beta.28\OmniSharp.exe

it should be 1.35.0.

check if you have any omnisharp.path setting in VS Code config and if you do, remove it.
Then try removing the extension and installing it again.

@suadev
Copy link

suadev commented Apr 14, 2020

@filipw done :) Thank you !

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

Successfully merging a pull request may close this issue.

7 participants