Example #1
0
        public override async Task <Container <FoldingRange> > Handle(FoldingRangeRequestParam request,
                                                                      CancellationToken cancellationToken)
        {
            var progress = ProgressManager.For(request, cancellationToken);
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Message    = "Begin getting fold ranges",
                Percentage = 0
            });
            var module = TextDocumentHandler.GetAstModule(request.TextDocument.Uri);
            var l      = new List <FoldingRange>(FoldingVisitor.GenerateFoldsInternal(module));

            progress?.OnNext(new Container <FoldingRange>(l));

            if (!cancellationToken.IsCancellationRequested)
            {
                l.AddRange(GenerateMultilineCommentFolds(module));
            }
            l.AddRange(GenerateMultiSingleLineCommentFolds(cancellationToken, module));
            l.AddRange(GenerateRegionFolds(cancellationToken, module));

            progress?.OnNext(new Container <FoldingRange>(l));

            workDone.OnCompleted();
            progress?.OnCompleted();
            return(progress != null ? new Container <FoldingRange>() : new Container <FoldingRange>(l));
        }
Example #2
0
        public override Task <Container <SelectionRange> > Handle(SelectionRangeParam request,
                                                                  CancellationToken cancellationToken)
        {
            var workDone = ProgressManager.WorkDone(request,
                                                    new WorkDoneProgressBegin {
                Message = "Begin getting selection ranges", Percentage = 0.0
            });
            var progress   = ProgressManager.For(request, cancellationToken);
            var allResults = new List <SelectionRange>();

            int progressPosition = 0;

            foreach (var position in request.Positions)
            {
                var editorData = DResolverWrapper.CreateEditorData(new HoverParams
                {
                    Position     = position,
                    TextDocument = request.TextDocument
                }, cancellationToken);
                allResults.Add(FindIdealSelectionRange(editorData));
                progress?.OnNext(new Container <SelectionRange>(allResults));
                workDone.OnNext(new WorkDoneProgressReport
                {
                    Percentage = ((double)++progressPosition / request.Positions.Count()) * 100
                });
            }

            progress?.OnCompleted();
            workDone.OnCompleted();
            return(Task.FromResult(progress != null
                ? new Container <SelectionRange>()
                : new Container <SelectionRange>(allResults)));
        }
Example #3
0
        public override Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        {
            var progress = ProgressManager.For(request, cancellationToken);
            var work     = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title   = "Resolve symbol definition location",
                Message = "Begin resolving definition under caret"
            });

            var editorData = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var results    = DResolverWrapper.ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt resolutionAttempt, out ISyntaxRegion syntaxRegion);

            var result = new LocationOrLocationLinks(
                results.Select(ExpressionTypeEvaluation.GetResultMember)
                .Select(node => ToLocationOrLocationLink(node, Capability.LinkSupport, syntaxRegion)));

            progress?.OnNext(new Container <LocationOrLocationLink>(result));
            work.OnCompleted();

            return(Task.FromResult(progress != null ? new LocationOrLocationLinks() : result));
        }
Example #4
0
        public override Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            var ed       = CreateCompletionEditorData(request, cancellationToken, out char triggerChar);
            var workDone = ProgressManager.WorkDone(request,
                                                    new WorkDoneProgressBegin {
                Message = "Begin generating completion info", Percentage = 0
            });
            var progress = ProgressManager.For(request, cancellationToken);

            var allResults = new List <CompletionItem>();

            var completionDataGenerator = new CompletionDataGeneratorImpl(item =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                allResults.Add(item);
                if (allResults.Count % 15 == 0)
                {
                    progress?.OnNext(new CompletionList(allResults));
                }
            });

            CodeCompletion.GenerateCompletionData(ed, completionDataGenerator, triggerChar);

            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <CompletionList>(cancellationToken));
            }
            workDone.OnCompleted();
            progress?.OnNext(new CompletionList(allResults));
            progress?.OnCompleted();

            return(Task.FromResult(progress != null ? new CompletionList() : new CompletionList(allResults)));
        }
        public async override Task<Container<SymbolInformation>> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken)
        {
            using var reporter = ProgressManager.WorkDone(request, new WorkDoneProgressBegin()
            {
                Cancellable = true,
                Message = "This might take a while...",
                Title = "Some long task....",
                Percentage = 0
            });
            using var partialResults = ProgressManager.For(request, cancellationToken);
            if (partialResults != null)
            {
                await Task.Delay(2000, cancellationToken);

                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 20
                });
                await Task.Delay(500, cancellationToken);

                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 40
                });
                await Task.Delay(500, cancellationToken);

                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 50
                });
                await Task.Delay(500, cancellationToken);

                partialResults.OnNext(new[] {
                    new SymbolInformation() {
                        ContainerName = "Partial Container",
                        Deprecated = true,
                        Kind = SymbolKind.Constant,
                        Location = new Location() { Range = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(new Position(2, 1), new Position(2, 10)) {} },
                        Name = "Partial name"
                    }
                });

                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 70
                });
                await Task.Delay(500, cancellationToken);

                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 90
                });

                partialResults.OnCompleted();
                return new SymbolInformation[] { };
            }

            try
            {
                return new[] {
                    new SymbolInformation() {
                        ContainerName = "Container",
                        Deprecated = true,
                        Kind = SymbolKind.Constant,
                        Location = new Location() { Range = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(new Position(1, 1), new Position(1, 10)) {} },
                        Name = "name"
                    }
                };
            }
            finally
            {
                reporter.OnNext(new WorkDoneProgressReport()
                {
                    Cancellable = true,
                    Percentage = 100
                });
            }
        }
        public override Task <DocumentHighlightContainer> Handle(DocumentHighlightParams request,
                                                                 CancellationToken cancellationToken)
        {
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title      = "Begin finding highlights",
                Percentage = 0
            });

            var editorData       = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var nodeSymbolToFind = DResolverWrapper
                                   .ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt _,
                                                              out ISyntaxRegion _)
                                   .Select(GetResultMember)
                                   .FirstOrDefault();

            if (nodeSymbolToFind == null)
            {
                workDone.OnNext(new WorkDoneProgressReport()
                {
                    Message    = "No symbol found",
                    Percentage = 100
                });
                workDone.OnCompleted();
                return(Task.FromResult(new DocumentHighlightContainer()));
            }

            var progress = ProgressManager.For(request, cancellationToken);
            List <DocumentHighlight> allFoundReferences;
            var ctxt = ResolutionContext.Create(editorData, true);

            try
            {
                allFoundReferences = cancellationToken.IsCancellationRequested
                    ? new List <DocumentHighlight>()
                    : ReferencesFinder
                                     .SearchModuleForASTNodeReferences(editorData.SyntaxTree, nodeSymbolToFind, ctxt)
                                     .Where(region => region != null)
                                     .OrderBy(region => region.Location)
                                     .Select(ToDocumentHighlight)
                                     .ToList();
            }
            catch (Exception ex)
            {
                workDone.OnError(ex);
                if (progress != null)
                {
                    progress.OnError(ex);
                    return(Task.FromResult(new DocumentHighlightContainer()));
                }

                return(Task.FromException <DocumentHighlightContainer>(ex));
            }

            if (allFoundReferences.Count > 0)
            {
                progress?.OnNext(new DocumentHighlightContainer(allFoundReferences));
            }

            workDone.OnCompleted();
            progress?.OnCompleted();

            return(Task.FromResult(progress != null
                ? new DocumentHighlightContainer()
                : new DocumentHighlightContainer(allFoundReferences)));
        }
Example #7
0
        public override Task <LocationContainer> Handle(ReferenceParams request, CancellationToken cancellationToken)
        {
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title      = "Begin resolving references",
                Percentage = 0
            });

            var editorData       = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var nodeSymbolToFind = DResolverWrapper
                                   .ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt _, out ISyntaxRegion _)
                                   .Select(ExpressionTypeEvaluation.GetResultMember)
                                   .FirstOrDefault();

            if (nodeSymbolToFind == null)
            {
                workDone.OnNext(new WorkDoneProgressReport()
                {
                    Message    = "No symbol found",
                    Percentage = 100
                });
                workDone.OnCompleted();
                return(Task.FromResult(new LocationContainer()));
            }

            var modules = editorData.ParseCache.EnumRootPackagesSurroundingModule(editorData.SyntaxTree)
                          .SelectMany(package => (IEnumerable <DModule>)package)
                          .Where(module => module != null)
                          .OrderBy(module => module.FileName)
                          .ToList();

            var progress           = ProgressManager.For(request, cancellationToken);
            var allFoundReferences = new List <Location>();
            var ctxt          = ResolutionContext.Create(editorData, true);
            int progressIndex = 0;

            foreach (var module in modules)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    var references = ReferencesFinder.SearchModuleForASTNodeReferences(module, nodeSymbolToFind, ctxt, request.Context.IncludeDeclaration)
                                     .Where(region => region != null)
                                     .OrderBy(region => region.Location)
                                     .Select(region => ToLocation(region, module))
                                     .Where(location => location != default)
                                     .ToList();
                    progressIndex++;
                    if (references.Count > 0)
                    {
                        workDone.OnNext(new WorkDoneProgressReport
                        {
                            Message    = "Scanned " + module.FileName,
                            Percentage = ((double)progressIndex / modules.Count) * 100.0
                        });
                        allFoundReferences.AddRange(references);
                        progress?.OnNext(new Container <Location>(allFoundReferences));
                    }
                }
                catch (Exception ex)
                {
                    workDone.OnError(ex);
                    if (progress != null)
                    {
                        progress.OnError(ex);
                        return(Task.FromResult(new LocationContainer()));
                    }
                    return(Task.FromException <LocationContainer>(ex));
                }
            }

            workDone.OnCompleted();
            progress?.OnCompleted();

            // if $progress sent, result must be empty
            return(Task.FromResult(progress != null ? new LocationContainer()
                : new LocationContainer(allFoundReferences)));
        }