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

Workaround for the issue https://github.com/OmniSharp/omnisharp-vscode/issues/4818 #2390

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#nullable enable
#nullable enable

using Microsoft.CodeAnalysis;
using OmniSharp.Extensions;
using OmniSharp.Mef;
using OmniSharp.Models.Metadata;
using OmniSharp.Models.v1.SourceGeneratedFile;
using OmniSharp.Models.V2.GotoDefinition;
using OmniSharp.Options;
using System.Composition;
Expand Down Expand Up @@ -46,15 +48,38 @@ public async Task<GotoDefinitionResponse> Handle(GotoDefinitionRequest request)

if (symbol.Locations[0].IsInSource)
{
return new GotoDefinitionResponse()
{
Definitions = symbol.Locations
.Select(location => new Definition
var definitions = symbol.Locations
.Select(location =>
{
MetadataSource? metadataSource = null;
SourceGeneratedFileInfo? sourceGeneratedFileInfo = null;

if (IsMetaDataSource(location.SourceTree))
{
metadataSource = new MetadataSource()
{
AssemblyName = symbol.ContainingAssembly.Name,
ProjectName = document.Project.Name,
TypeName = symbol.GetSymbolName()
};
}
else
{
sourceGeneratedFileInfo = GoToDefinitionHelpers.GetSourceGeneratedFileInfo(_workspace, location);
}

return new Definition
{
Location = location.GetMappedLineSpan().GetLocationFromFileLinePositionSpan(),
SourceGeneratedFileInfo = GoToDefinitionHelpers.GetSourceGeneratedFileInfo(_workspace, location)
})
.ToList()
MetadataSource = metadataSource,
SourceGeneratedFileInfo = sourceGeneratedFileInfo
};
})
.ToList();

return new GotoDefinitionResponse()
{
Definitions = definitions
};
}
else
Expand Down Expand Up @@ -83,6 +108,11 @@ public async Task<GotoDefinitionResponse> Handle(GotoDefinitionRequest request)

return new GotoDefinitionResponse();
}

static bool IsMetaDataSource(SyntaxTree? syntaxTree)
{
return syntaxTree?.FilePath.StartsWith("$metadata$\\Project\\") == true;
}
}
}
}