public static async Task <CodeStructureResponse> TranslateAsync(this CodeStructureResponse response, OmniSharpWorkspace workspace, CodeStructureRequest request) { var zeroIndex = await LineIndexHelper.TranslateToGenerated(request.FileName, 0, workspace); var elements = new List <CodeElement>(); foreach (var element in response.Elements) { if (element.Ranges.Values.Any(x => x.Start.Line < zeroIndex)) { continue; } var translatedElement = await element.TranslateAsync(workspace, request); if (translatedElement.Ranges.Values.Any(x => x.Start.Line < 0)) { continue; } elements.Add(translatedElement); } response.Elements = elements; return(response); }
public static async Task <TRequest> TranslateAsync <TRequest>(this TRequest request, OmniSharpWorkspace workspace) where TRequest : Request { request.Line = await LineIndexHelper.TranslateToGenerated(request.FileName, request.Line, workspace); if (request.Changes == null) { return(request); } var changes = new List <LinePositionSpanTextChange>(); foreach (var change in request.Changes) { var oldStartLine = change.StartLine; change.StartLine = await LineIndexHelper.TranslateToGenerated(request.FileName, change.StartLine, workspace); change.EndLine = oldStartLine == change.EndLine ? change.StartLine : await LineIndexHelper.TranslateToGenerated(request.FileName, change.EndLine, workspace); changes.Add(change); } request.Changes = changes; return(request); }
public async Task TranslateToGenerated_Should_Translate_Index_In_Single_File(int index, int expected) { var fileName = SingleCakePath; var workspace = CreateSimpleWorkspace(fileName, GetGeneratedFileContent(fileName)); var actual = await LineIndexHelper.TranslateToGenerated(fileName, index, workspace); Assert.Equal(expected, actual); Assert.Equal(GetFileContent(fileName).Split('\n')[index], GetGeneratedFileContent(fileName).Split('\n')[actual]); }
protected override async Task <TRequest> TranslateRequestAsync(TRequest request) { if (request.Selection != null) { var startLine = await LineIndexHelper.TranslateToGenerated(request.FileName, request.Selection.Start.Line, Workspace); request.Selection.End.Line = request.Selection.Start.Line != request.Selection.End.Line ? await LineIndexHelper.TranslateToGenerated(request.FileName, request.Selection.End.Line, Workspace) : startLine; request.Selection.Start.Line = startLine; } return(await base.TranslateRequestAsync(request)); }
protected override async Task <TRequest> TranslateRequestAsync(TRequest request) { if (request.Selection != null) { var startLine = await LineIndexHelper.TranslateToGenerated(request.FileName, request.Selection.Start.Line, Workspace); var endLine = request.Selection.Start.Line != request.Selection.End.Line ? await LineIndexHelper.TranslateToGenerated(request.FileName, request.Selection.End.Line, Workspace) : startLine; request = (TRequest)request.WithSelection( request.Selection with { Start = request.Selection.Start with { Line = startLine }, End = request.Selection.End with { Line = endLine } });
public static async Task <FileMemberTree> TranslateAsync(this FileMemberTree response, OmniSharpWorkspace workspace, Request request) { var zeroIndex = await LineIndexHelper.TranslateToGenerated(request.FileName, 0, workspace); var topLevelTypeDefinitions = new List <FileMemberElement>(); foreach (var topLevelTypeDefinition in response.TopLevelTypeDefinitions) { if (topLevelTypeDefinition.Location.Line < zeroIndex) { continue; } await topLevelTypeDefinition.TranslateAsync(workspace, request); if (topLevelTypeDefinition.Location.Line >= 0) { topLevelTypeDefinitions.Add(topLevelTypeDefinition); } } response.TopLevelTypeDefinitions = topLevelTypeDefinitions; return(response); }