private static async Task <CodeElement> TranslateAsync(this CodeElement element, OmniSharpWorkspace workspace, SimpleFileRequest request) { var builder = new CodeElement.Builder { Kind = element.Kind, DisplayName = element.DisplayName, Name = element.Name }; foreach (var property in element.Properties ?? Enumerable.Empty <KeyValuePair <string, object> >()) { builder.AddProperty(property.Key, property.Value); } foreach (var range in element.Ranges ?? Enumerable.Empty <KeyValuePair <string, Range> >()) { builder.AddRange(range.Key, await range.Value.TranslateAsync(workspace, request)); } foreach (var childElement in element.Children ?? Enumerable.Empty <CodeElement>()) { var translatedElement = await childElement.TranslateAsync(workspace, request); // This is plain stupid, but someone might put a #load directive inside a method or class if (translatedElement.Ranges.Values.Any(x => x.Start.Line < 0)) { continue; } builder.AddChild(translatedElement); } return(builder.ToCodeElement()); }
private static async Task <Range> TranslateAsync(this Range range, OmniSharpWorkspace workspace, SimpleFileRequest request) { var(line, _) = await LineIndexHelper.TranslateFromGenerated(request.FileName, range.Start.Line, workspace, true); if (range.Start.Line == range.End.Line) { return(range with { Start = range.Start with { Line = line }, End = range.End with { Line = line } });
public static async Task <BlockStructureResponse> TranslateAsync(this BlockStructureResponse response, OmniSharpWorkspace workspace, SimpleFileRequest request) { if (response?.Spans == null) { return(response); } var spans = new List <CodeFoldingBlock>(); foreach (var span in response.Spans) { var range = await span.Range.TranslateAsync(workspace, request); if (range.Start.Line < 0) { continue; } spans.Add(new CodeFoldingBlock(range, span.Kind)); } response.Spans = spans; return(response); }