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

Support for top level statements is broken #4706

Closed
Banyc opened this issue Aug 16, 2021 · 4 comments
Closed

Support for top level statements is broken #4706

Banyc opened this issue Aug 16, 2021 · 4 comments

Comments

@Banyc
Copy link

Banyc commented Aug 16, 2021

Environment data

dotnet --info output:

.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.7.21379.14
 Commit:    22d70b47bc

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.5
 OS Platform: Darwin
 RID:         osx.11.0-x64

VS Code version: 1.59.0
C# Extension version: v1.23.14

OmniSharp log

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: position
  at Microsoft.CodeAnalysis.SyntaxNode.FindTokenCore (System.Int32 position, System.Boolean findInsideTrivia) [0x0002e] in <e35e1300a2244b519599a96bd7d3112e>:0 
  at Microsoft.CodeAnalysis.SyntaxNode.FindToken (System.Int32 position, System.Boolean findInsideTrivia) [0x00000] in <e35e1300a2244b519599a96bd7d3112e>:0 
  at Microsoft.CodeAnalysis.CodeRefactorings.AbstractRefactoringHelpersService`3[TExpressionSyntax,TArgumentSyntax,TExpressionStatementSyntax].GetTokensToRightOrInToLeftAndUpdatedLocationAsync (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.Text.TextSpan selectionTrimmed, System.Threading.CancellationToken cancellationToken) [0x0001e] in <2a90131e1b864e9a940d8feec08fc12d>:0 
  at Microsoft.CodeAnalysis.CodeRefactorings.AbstractRefactoringHelpersService`3[TExpressionSyntax,TArgumentSyntax,TExpressionStatementSyntax].GetRelevantNodesAsync[TSyntaxNode] (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan selectionRaw, System.Threading.CancellationToken cancellationToken) [0x00220] in <2a90131e1b864e9a940d8feec08fc12d>:0 
  at Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContextExtensions.TryGetRelevantNodeAsync[TSyntaxNode] (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Threading.CancellationToken cancellationToken) [0x00075] in <2a90131e1b864e9a940d8feec08fc12d>:0 
  at Microsoft.CodeAnalysis.CSharp.CodeRefactorings.UseType.AbstractUseTypeCodeRefactoringProvider.GetDeclarationAsync (Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext context) [0x00087] in <70e8cdbb0f994f429c2e0c4f08cfb986>:0 
  at Microsoft.CodeAnalysis.CSharp.CodeRefactorings.UseType.AbstractUseTypeCodeRefactoringProvider.ComputeRefactoringsAsync (Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext context) [0x000fc] in <70e8cdbb0f994f429c2e0c4f08cfb986>:0 
  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].CollectRefactoringActions (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Collections.Generic.List`1[T] codeActions) [0x0010b] in <d1e6bdc84f6a4f49a16e7c05bb903d52>:0 
[fail]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService
        Error computing refactorings for Microsoft.CodeAnalysis.CSharp.CodeRefactorings.PullMemberUp.CSharpPullMemberUpCodeRefactoringProvider

Steps to reproduce

Create the three files.

File WhenAny.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

File Program.cs

Program.cs
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
using WhenAny;

Console.WriteLine("Hello, World!");

List<Task> tasks = new();

Task task1 = TaskBuilder.GetTask1();
Task task2 = TaskBuilder.GetTask2();

tasks.Add(task1);
tasks.Add(task2);

Task taskDone;

taskDone = await Task.WhenAny(tasks);
if (taskDone == task1)
{
    Task<int> task1Value = (Task<int>) taskDone;
    Console.WriteLine($"[Task1] {task1Value.Result}");
}
else
if (taskDone == task2)
{
    Task<string> task1Value = (Task<string>) taskDone;
    Console.WriteLine($"[Task2] {task1Value.Result}");
}

await Task.WhenAll(tasks);

File TaskBuilder.cs

TaskBuilder.cs
using System.Threading.Tasks;
namespace WhenAny
{
    public static class TaskBuilder
    {
        public static async Task<int> GetTask1()
        {
            await Task.Delay(10);

            return 10;
        }

        public static async Task<string> GetTask2()
        {
            await Task.Delay(200);

            return "hi";
        }
    }
}

Finally

Restart the Omnisharp to rule out the irrelevant factors.

Expected behavior

  • Omnisharp recognizes the project as a whole.
  • Omnisharp successfully creates ready-to-run launch.json and tasks.json files.
  • Omnisharp recognizes the existence of the classes defined in files other than Program.cs.
  • When removing the line using WhenAny;, Omnisharp should notice that something is go wrong.

Actual behavior

  • Omnisharp does not recognize the project as a whole.
  • Omnisharp does not successfully create ready-to-run launch.json and tasks.json files.
  • Omnisharp does not recognize the existence of the classes defined in files other than Program.cs.
  • When removing the line using WhenAny;, Omnisharp does not notice that something is go wrong.
@333fred
Copy link
Member

333fred commented Aug 18, 2021

Please include your omnisharp logs. It's worked for me with top level statements since they were introduced, so there's something else going on.

@Banyc
Copy link
Author

Banyc commented Aug 19, 2021

@333fred The logs are following:

Omnisharp log

Starting OmniSharp server at 8/19/2021, 3:50:40 PM
Target: /Users/[redacted]/Documents/code/csharp/_tests/WhenAny

OmniSharp server started.
Path: /Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/run
PID: 58106

Starting OmniSharp on MacOS 11.5.1 (x64)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 17.0.0 - "/Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild/Current/Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 17.0.0 - "/Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild/Current/Bin"
CscToolExe = csc.exe
MSBuildToolsPath = /Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild/Current/Bin
CscToolPath = /Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild/Current/Bin/Roslyn
BypassFrameworkInstallChecks = true
MSBuildExtensionsPath = /Users/[redacted]/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.14/omnisharp/.msbuild
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
No solution files found in '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny'.
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny' on host 58076.
info: OmniSharp.MSBuild.ProjectManager
Loading project: /Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj'.
/Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj(0,0)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. /Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00040] in :0
at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1] (System.Boolean condition, System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00003] in :0
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1] (Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00000] in :0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].ExpandAndLoadImportsFromUnescapedImportExpressionConditioned (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, System.Collections.Generic.List1[Microsoft.Build.Construction.ProjectRootElement]& projects, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult, System.Boolean throwOnFileNotExistsError) [0x0032a] in :0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].ExpandAndLoadImports (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult) [0x00027] in <e78286a6f9b047bca66ad86e9b031ef5>:0 at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x0000d] in :0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x000e6] in <e78286a6f9b047bca66ad86e9b031ef5>:0 at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].Evaluate () [0x0013b] in :0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCacheBase projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService sdkResolverService, System.Int32 submissionId, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext, System.Boolean interactive) [0x00047] in :0
at Microsoft.Build.Evaluation.Project+ProjectImpl.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00063] in :0
at Microsoft.Build.Evaluation.Project+ProjectImpl.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00035] in :0
at Microsoft.Build.Evaluation.Project+ProjectImpl.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00000] in :0
at Microsoft.Build.Evaluation.Project+ProjectImpl.ReevaluateIfNecessary (Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00007] in :0
at Microsoft.Build.Evaluation.Project+ProjectImpl.Initialize (System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00127] in <e78286a6f9b047bca66ad86e9b031ef5>:0 at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00073] in :0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <e78286a6f9b047bca66ad86e9b031ef5>:0 at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in :0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) [0x00000] in <e78286a6f9b047bca66ad86e9b031ef5>:0 at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.Collections.Generic.IDictionary2[TKey,TValue] globalProperties, System.String toolsVersion) [0x000f7] in :0
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.String toolsVersion) [0x00000] in :0
at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore (System.String filePath, System.Collections.Generic.IReadOnlyDictionary2[TKey,TValue] projectConfigurationsInSolution) [0x00160] in <123e9399922f43fb93d71bfa60dd04d6>:0 at OmniSharp.MSBuild.ProjectLoader.BuildProject (System.String filePath, System.Collections.Generic.IReadOnlyDictionary2[TKey,TValue] configurationsInSolution) [0x0000d] in <123e9399922f43fb93d71bfa60dd04d6>:0
at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load (System.String filePath, OmniSharp.MSBuild.ProjectIdInfo projectIdInfo, OmniSharp.MSBuild.ProjectLoader loader, System.Guid sessionId, OmniSharp.Services.DotNetInfo dotNetInfo) [0x00023] in <123e9399922f43fb93d71bfa60dd04d6>:0
at OmniSharp.MSBuild.ProjectManager+<>c__DisplayClass31_0.b__0 () [0x00000] in <123e9399922f43fb93d71bfa60dd04d6>:0
at (wrapper delegate-invoke) System.Func1[System.ValueTuple3[OmniSharp.MSBuild.ProjectFile.ProjectFileInfo,System.Collections.Immutable.ImmutableArray1[OmniSharp.MSBuild.Logging.MSBuildDiagnostic],OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs]].invoke_TResult() at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject (System.String projectFilePath, System.Func1[TResult] loader) [0x0001b] in <123e9399922f43fb93d71bfa60dd04d6>:0

Attempted to update project that is not loaded: /Users/[redacted]/Documents/code/csharp/_tests/WhenAny/WhenAny.csproj
info: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
Solution initialized -> queue all documents for code analysis. Initial document count: 0.

But I'm sure the SDK is installed.

.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.7.21379.14
 Commit:    22d70b47bc

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.5
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/

Host (useful for support):
  Version: 6.0.0-preview.7.21377.19
  Commit:  91ba01788d

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.7.21379.14 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.7.21378.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.7.21377.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

@Banyc
Copy link
Author

Banyc commented Aug 19, 2021

Update

The solution is to restart the computer. Brutal but effective. It does turn out to be something else.

@333fred thanks for the help!!!

@Banyc Banyc closed this as completed Aug 19, 2021
@333fred
Copy link
Member

333fred commented Aug 19, 2021

Glad to hear it, thanks.

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

2 participants