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 static async Task <NavigateResponse> TranslateAsync(this NavigateResponse response, OmniSharpWorkspace workspace, Request request)
        {
            var(line, _) = await LineIndexHelper.TranslateFromGenerated(request.FileName, response.Line, workspace, true);

            response.Line = line;

            return(response);
        }
Exemple #4
0
        public async Task TranslateFromGenerated_Should_Translate_Index_In_Single_File(int index, int expected)
        {
            var fileName  = SingleCakePath;
            var workspace = CreateSimpleWorkspace(fileName, GetGeneratedFileContent(fileName));

            var(actualIndex, actualFileName) = await LineIndexHelper.TranslateFromGenerated(fileName, index, workspace, true);

            Assert.Equal(expected, actualIndex);
            Assert.Equal(GetGeneratedFileContent(fileName).Split('\n')[index],
                         GetFileContent(actualFileName).Split('\n')[actualIndex]);
        }
Exemple #5
0
        public async Task TranslateFromGenerated_Should_Translate_To_Negative_If_Outside_Bounds()
        {
            const int index     = 8207;
            const int expected  = -1;
            var       fileName  = SingleCakePath;
            var       workspace = CreateSimpleWorkspace(fileName, GetGeneratedFileContent(fileName));

            var(actualIndex, _) = await LineIndexHelper.TranslateFromGenerated(fileName, index, workspace, true);

            Assert.Equal(expected, actualIndex);
        }
Exemple #6
0
        public async Task TranslateToGenerated_Should_Translate_Index_With_Multiple_Files(int index, int expected)
        {
            var fileName  = MultiCakePath;
            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]);
        }
        private static async Task <(string, LinePositionSpanTextChange)> TranslateAsync(this LinePositionSpanTextChange change, OmniSharpWorkspace workspace, string fileName)
        {
            var(line, newFileName) = await LineIndexHelper.TranslateFromGenerated(fileName, change.StartLine, workspace, false);

            change.StartLine = line;

            (line, _) = await LineIndexHelper.TranslateFromGenerated(fileName, change.EndLine, workspace, false);

            change.EndLine = line;

            return(newFileName, change);
        }
        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
                    }
                });
Exemple #9
0
        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));
        }
Exemple #10
0
        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
                    }
                });
        private static async Task <QuickFix> TranslateAsync(this QuickFix quickFix, OmniSharpWorkspace workspace, Request request)
        {
            var sameFile = string.IsNullOrEmpty(quickFix.FileName);
            var fileName = !sameFile ? quickFix.FileName : request.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                return(quickFix);
            }

            var(line, newFileName) = await LineIndexHelper.TranslateFromGenerated(fileName, quickFix.Line, workspace, sameFile);

            quickFix.Line     = line;
            quickFix.FileName = newFileName;

            (line, _) = await LineIndexHelper.TranslateFromGenerated(fileName, quickFix.EndLine, workspace, sameFile);

            quickFix.EndLine = line;

            return(quickFix);
        }
        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);
        }