Skip to content
Merged
Changes from all 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;
}
}
}
}