Exemple #1
0
 public async Task <bool> CanCreateDataPointAsync(
     CodeLensDescriptor descriptor,
     CodeLensDescriptorContext context,
     CancellationToken ct)
 => (descriptor.Kind is CodeElementKinds.Method || descriptor.Kind is CodeElementKinds.Property) &&
 await callbackService.Value
 .InvokeAsync <bool>(this, nameof(IInstructionsProvider.IsMicroscopeEnabled)).Caf();
Exemple #2
0
        public async Task <ReferenceCount?> GetReferenceCountAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, ReferenceCount?previousCount, CancellationToken cancellationToken)
        {
            var solution = _workspace.CurrentSolution;

            var(documentId, node) = await GetDocumentIdAndNodeAsync(
                solution, descriptor, descriptorContext, cancellationToken).ConfigureAwait(false);

            if (documentId == null)
            {
                return(null);
            }

            var service = _workspace.Services.GetRequiredService <ICodeLensReferencesService>();

            if (previousCount is not null)
            {
                // Avoid calculating results if we already have a result for the current project version
                var currentProjectVersion = await service.GetProjectCodeLensVersionAsync(solution, documentId.ProjectId, cancellationToken).ConfigureAwait(false);

                if (previousCount.Value.Version == currentProjectVersion.ToString())
                {
                    return(previousCount);
                }
            }

            var maxSearchResults = await GetMaxResultCapAsync(cancellationToken).ConfigureAwait(false);

            return(await service.GetReferenceCountAsync(solution, documentId, node, maxSearchResults, cancellationToken).ConfigureAwait(false));
        }
Exemple #3
0
        public async Task <bool> CanCreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext context, CancellationToken token)
        {
            var result = false;

            if (await IsEnabled())
            {
                if (descriptor.Kind == CodeElementKinds.Type)
                {
                    //it's a type
                    result = true;
                }
                //else if (descriptor.Kind == CodeElementKinds.Method)
                //{
                //    var parts = descriptor.ElementDescription.Split('.');
                //    if (parts.Length == 2)
                //    {
                //        if (parts[0] == parts[1])
                //        {
                //            //it's a constructor
                //            result = true;
                //        }
                //    }
                //}
            }

            return
                //Task.FromResult(
                (result
                 //)
                );
        }
Exemple #4
0
        public async Task <ImmutableArray <ReferenceMethodDescriptor>?> FindReferenceMethodsAsync(
            CodeLensDescriptor descriptor,
            CodeLensDescriptorContext descriptorContext,
            CancellationToken cancellationToken
            )
        {
            var solution = _workspace.CurrentSolution;

            var(documentId, node) = await GetDocumentIdAndNodeAsync(
                solution,
                descriptor,
                descriptorContext.ApplicableSpan,
                cancellationToken
                )
                                    .ConfigureAwait(false);

            if (documentId == null)
            {
                return(null);
            }

            var service = _workspace.Services.GetRequiredService <ICodeLensReferencesService>();

            return(await service
                   .FindReferenceMethodsAsync(solution, documentId, node, cancellationToken)
                   .ConfigureAwait(false));
        }
Exemple #5
0
 public CopyLinkCodeLensDataPoint(
     CodeLensDescriptor descriptor,
     IRepositoryService repositoryService)
 {
     Descriptor         = Requires.NotNull(descriptor, nameof(descriptor));
     _repositoryService = repositoryService;
 }
Exemple #6
0
        public Task <bool> CanCreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext context, CancellationToken token)
        {
            Debug.Assert(descriptor != null);
            var gitRepo = GitUtil.ProbeGitRepository(descriptor.FilePath, out string repoRoot);

            return(Task.FromResult <bool>(gitRepo != null));
        }
Exemple #7
0
        public async Task <(string projectVersion, ImmutableArray <ReferenceLocationDescriptor> references)?> FindReferenceLocationsAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
        {
            var solution = _workspace.CurrentSolution;

            var(documentId, node) = await GetDocumentIdAndNodeAsync(
                solution, descriptor, descriptorContext, cancellationToken).ConfigureAwait(false);

            if (documentId == null)
            {
                return(null);
            }

            var service    = _workspace.Services.GetRequiredService <ICodeLensReferencesService>();
            var references = await service.FindReferenceLocationsAsync(solution, documentId, node, cancellationToken).ConfigureAwait(false);

            if (!references.HasValue)
            {
                return(null);
            }

            var projectVersion = await service.GetProjectCodeLensVersionAsync(solution, documentId.ProjectId, cancellationToken).ConfigureAwait(false);

            return(projectVersion.ToString(), references.Value);
        }
Exemple #8
0
        public Task <bool> CanCreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext context, CancellationToken token)
        {
            Debug.Assert(descriptor != null);
            var Repo = HelixUtility.GetRepository(descriptor.FilePath, out string repoRoot,
                                                  out Changelist latest);

            return(Task.FromResult <bool>(Repo != null && latest != null));
        }
        public Task <IAsyncCodeLensDataPoint?> CreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken token)
        {
            if (_repositoryService == null)
            {
                return(Task.FromResult <IAsyncCodeLensDataPoint?>(null));
            }

            return(Task.FromResult <IAsyncCodeLensDataPoint?>(new CopyLinkCodeLensDataPoint(descriptor, _repositoryService)));
        }
Exemple #10
0
 private async Task <(DocumentId?, SyntaxNode?)> GetDocumentIdAndNodeAsync(
     Solution solution,
     CodeLensDescriptor descriptor,
     Span?span,
     CancellationToken cancellationToken
     )
 {
     if (span is null)
     {
         return(default);
Exemple #11
0
 public async Task <bool> CanCreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken token)
 {
     if (descriptor.Kind == CodeElementKinds.Method)
     {
         var projectId  = descriptor.ProjectGuid;
         var connection = Shared.Server.SentryConnection.GetCurrent(projectId);
         return(connection.IsEnabled);
     }
     return(false);
 }
            public DataPoint(
                ReferenceCodeLensProvider owner,
                ICodeLensCallbackService callbackService,
                CodeLensDescriptor descriptor)
            {
                _owner           = owner;
                _callbackService = callbackService;

                Descriptor = descriptor;
            }
Exemple #13
0
        public Task <bool> CanCreateDataPointAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
        {
            if (descriptorContext != null && descriptorContext.ApplicableSpan.HasValue)
            {
                // we allow all reference points.
                // engine will call this for all points our roslyn code lens (reference) tagger tagged.
                return(SpecializedTasks.True);
            }

            return(SpecializedTasks.False);
        }
Exemple #14
0
        public async Task <IAsyncCodeLensDataPoint> CreateDataPointAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
        {
            var dataPoint = new DataPoint(
                this,
                _lazyCodeLensCallbackService.Value,
                descriptor,
                await GetConnectionAsync(cancellationToken).ConfigureAwait(false));

            await dataPoint.TrackChangesAsync(cancellationToken).ConfigureAwait(false);

            return(dataPoint);
        }
Exemple #15
0
        public async Task <IAsyncCodeLensDataPoint> CreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken token)
        {
            var projectId  = descriptor.ProjectGuid;
            var connection = Shared.Server.SentryConnection.GetCurrent(projectId);

            //string pathBase;
            //if (!_pathBases.TryGetValue(descriptor.ProjectGuid, out pathBase))
            //{
            //    pathBase = FindPathBase(descriptor.FilePath);
            //    _pathBases[descriptor.ProjectGuid] = pathBase;
            //}

            return(new SentryDataPoint(connection, descriptor));
        }
Exemple #16
0
            public DataPoint(
                ReferenceCodeLensProvider owner,
                ICodeLensCallbackService callbackService,
                CodeLensDescriptor descriptor,
                Stream stream)
            {
                _owner           = owner;
                _callbackService = callbackService;

                Descriptor = descriptor;

                _endPoint = new RemoteEndPoint(stream, owner._client.Logger, new RoslynCallbackTarget(Invalidate));
                _endPoint.StartListening();
            }
Exemple #17
0
        public async Task <IEnumerable <ReferenceLocationDescriptor> > FindReferenceLocationsAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
        {
            var solution = _workspace.CurrentSolution;

            var(documentId, node) = await GetDocumentIdAndNodeAsync(
                solution, descriptor, descriptorContext.ApplicableSpan.Value, cancellationToken).ConfigureAwait(false);

            if (documentId == null)
            {
                return(null);
            }

            var service = _workspace.Services.GetService <ICodeLensReferencesService>();

            return(await service.FindReferenceLocationsAsync(solution, documentId, node, cancellationToken).ConfigureAwait(false));
        }
        public DpdtCodeLensDataPoint(
            ICodeLensCallbackService callbackService,
            CodeLensDescriptor descriptor
            )
        {
            if (callbackService is null)
            {
                throw new ArgumentNullException(nameof(callbackService));
            }

            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            _callbackService = callbackService;
            _descriptor      = descriptor;
        }
Exemple #19
0
            public DataPoint(
                ReferenceCodeLensProvider owner,
                ICodeLensCallbackService callbackService,
                CodeLensDescriptor descriptor,
                Stream stream)
            {
                _owner           = owner;
                _callbackService = callbackService;

                Descriptor = descriptor;

                _roslynRpc = stream.CreateStreamJsonRpc(
                    target: new RoslynCallbackTarget(Invalidate),
                    owner._client.Logger,
                    SpecializedCollections.SingletonEnumerable(AggregateJsonConverter.Instance));

                _roslynRpc.StartListening();
            }
Exemple #20
0
        public async Task <ReferenceCount?> GetReferenceCountAsync(
            CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
        {
            var solution = _workspace.CurrentSolution;

            var(documentId, node) = await GetDocumentIdAndNodeAsync(
                solution, descriptor, descriptorContext.ApplicableSpan, cancellationToken).ConfigureAwait(false);

            if (documentId == null)
            {
                return(null);
            }

            var maxSearchResults = await GetMaxResultCapAsync(cancellationToken).ConfigureAwait(false);

            var service = _workspace.Services.GetRequiredService <ICodeLensReferencesService>();

            return(await service.GetReferenceCountAsync(solution, documentId, node, maxSearchResults, cancellationToken).ConfigureAwait(false));
        }
Exemple #21
0
        public async Task <IAsyncCodeLensDataPoint> CreateDataPointAsync(
            CodeLensDescriptor descriptor,
            CodeLensDescriptorContext context,
            CancellationToken ct)
        {
            try {
                var dp = new CodeLensDataPoint(callbackService.Value, descriptor);

                var vspid = await callbackService.Value
                            .InvokeAsync <int>(this, nameof(IInstructionsProvider.GetVisualStudioPid)).Caf();

                await dp.ConnectToVisualStudio(vspid).Caf();

                return(dp);
            } catch (Exception ex) {
                LogCL(ex);
                throw;
            }
        }
        public async Task <bool> CanCreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken token)
        {
            // Initialize MEF to import our own interfaces.
            MefHostCompositionService.Instance.SatisfyImportsOnce(this);

            if (_repositoryService == null)
            {
                _repositoryService = MefHostCompositionService.Instance.Container.GetExportedValue <IRepositoryService>();
            }

            // Because we're out of proc here, the content of this instance of IRepositoryService is different
            // from the one from devenv.exe.
            // Therefore, we have to make sure we discover the repository here because the service in this
            // process may have not discovered it yet.
            // Additionally, since this method returns a boolean to determine whether the CodeLens provider should render
            // or not in the UI, we call DiscoverRepositoryAsync and wait that we finished to discover the repository.
            // This means we're blocking the thread and will do an IO access the very first time this method is call
            // (and potentially in the future too).
            await _repositoryService.DiscoverRepositoryAsync(descriptor.FilePath, token).ConfigureAwait(false);

            return(_repositoryService.IsFilePartOfKnownRepository(descriptor.FilePath));
        }
Exemple #23
0
        public async Task <IAsyncCodeLensDataPoint> CreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext context, CancellationToken token)
        {
            try
            {
                var dp = new DpdtCodeLensDataPoint(
                    _callbackService.Value,
                    descriptor
                    );

                var vspid = await _callbackService.Value
                            .InvokeAsync <int>(this, nameof(IDpdtCodeLensListener.GetVisualStudioPid))
                            .ConfigureAwait(false)
                ;

                await dp.ConnectToVisualStudioAsync(vspid).ConfigureAwait(false);

                return(dp);
            }
            catch (Exception ex)
            {
                LogCL(ex);
                throw;
            }
        }
Exemple #24
0
 public CodeLensDataPoint(ICodeLensCallbackService callbackService, CodeLensDescriptor descriptor)
 {
     this.callbackService = callbackService;
     Descriptor           = descriptor;
 }
Exemple #25
0
 public Task <IAsyncCodeLensDataPoint> CreateDataPointAsync(CodeLensDescriptor descriptor, CodeLensDescriptorContext context, CancellationToken token)
 {
     return(Task.FromResult <IAsyncCodeLensDataPoint>(new GitCommitDataPoint(descriptor)));
 }
Exemple #26
0
 public GitCommitDataPoint(CodeLensDescriptor descriptor)
 {
     this.descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
     this.gitRepo    = GitUtil.ProbeGitRepository(descriptor.FilePath, out this.gitRepoRootPath);
 }
Exemple #27
0
 public SentryDataPoint(SentryConnection sentryConnection, CodeLensDescriptor descriptor)
 {
     _sentryConnection = sentryConnection;
     _descriptor       = descriptor;
     _sentryConnection.OptionsChanged += InvalidatedAsync;
 }
Exemple #28
0
 public HelixSubmittedChangelistDataPoint(CodeLensDescriptor descriptor)
 {
     this.descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
     this.rep        = HelixUtility.GetRepository(descriptor.FilePath, out this.ws_root,
                                                  out Changelist latest);
 }
Exemple #29
0
 private async Task <(DocumentId, SyntaxNode)> GetDocumentIdAndNodeAsync(
     Solution solution, CodeLensDescriptor descriptor, Text.Span span, CancellationToken cancellationToken)
 {
     if (!TryGetDocument(solution, descriptor.ProjectGuid, descriptor.FilePath, out var document))
     {
         return(default);
Exemple #30
0
 private async Task <(DocumentId?, SyntaxNode?)> GetDocumentIdAndNodeAsync(
     Solution solution, CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
 {
     if (descriptorContext.ApplicableSpan is null)
     {
         return(default);