-
Notifications
You must be signed in to change notification settings - Fork 418
/
Copy pathGotoDefinitionHandler.cs
72 lines (65 loc) · 2.62 KB
/
GotoDefinitionHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Extensions;
using OmniSharp.Mef;
using OmniSharp.Models.GotoDefinition;
using OmniSharp.Models.Metadata;
using OmniSharp.Roslyn;
using OmniSharp.Utilities;
namespace OmniSharp.Cake.Services.RequestHandlers.Navigation
{
[OmniSharpHandler(OmniSharpEndpoints.GotoDefinition, Constants.LanguageNames.Cake), Shared]
public class GotoDefinitionHandler : CakeRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse>
{
private readonly MetadataExternalSourceService _metadataExternalSourceService;
[ImportingConstructor]
public GotoDefinitionHandler(
OmniSharpWorkspace workspace,
MetadataExternalSourceService metadataExternalSourceService)
: base(workspace)
{
_metadataExternalSourceService = metadataExternalSourceService ?? throw new ArgumentNullException(nameof(metadataExternalSourceService));
}
protected override async Task<GotoDefinitionResponse> TranslateResponse(GotoDefinitionResponse response, GotoDefinitionRequest request)
{
if (string.IsNullOrEmpty(response.FileName) ||
!response.FileName.Equals(Constants.Paths.Generated))
{
if (PlatformHelper.IsWindows && !string.IsNullOrEmpty(response.FileName))
{
response.FileName = response.FileName.Replace('/', '\\');
}
return response;
}
if (!request.WantMetadata)
{
return new GotoDefinitionResponse();
}
var alias = (await GotoDefinitionHandlerHelper.GetAliasFromMetadataAsync(
Workspace,
request.FileName,
response.Line,
request.Timeout,
_metadataExternalSourceService
)).FirstOrDefault();
if (alias == null)
{
return new GotoDefinitionResponse();
}
return new GotoDefinitionResponse
{
FileName = alias.MetadataDocument.FilePath ?? alias.MetadataDocument.Name,
Line = alias.LineSpan.StartLinePosition.Line,
Column = alias.LineSpan.StartLinePosition.Character,
MetadataSource = new MetadataSource
{
AssemblyName = alias.Symbol.ContainingAssembly.Name,
ProjectName = alias.Document.Project.Name,
TypeName = alias.Symbol.GetSymbolName()
}
};
}
}
}