public static Task <ISymbol> FindSourceDefinitionAsync( ISymbol symbol, Solution solution, CancellationToken cancellationToken = default ) { if (symbol != null) { symbol = symbol.GetOriginalUnreducedDefinition(); switch (symbol.Kind) { case SymbolKind.Event: case SymbolKind.Field: case SymbolKind.Method: case SymbolKind.Local: case SymbolKind.NamedType: case SymbolKind.Parameter: case SymbolKind.Property: case SymbolKind.TypeParameter: case SymbolKind.Namespace: return(FindSourceDefinitionWorkerAsync(symbol, solution, cancellationToken)); } } return(SpecializedTasks.Null <ISymbol>()); }
public Task <SyntaxTree?> GetSyntaxTreeAsync(CancellationToken cancellationToken = default) { // If the language doesn't support getting syntax trees for a document, then bail out immediately. if (!this.SupportsSyntaxTree) { return(SpecializedTasks.Null <SyntaxTree>()); } // if we have a cached result task use it if (_syntaxTreeResultTask != null) { // _syntaxTreeResultTask is a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the // conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant. return(_syntaxTreeResultTask !); } // check to see if we already have the tree before actually going async if (TryGetSyntaxTree(out var tree)) { // stash a completed result task for this value for the next request (to reduce extraneous allocations of tasks) // don't use the actual async task because it depends on a specific cancellation token // its okay to cache the task and hold onto the SyntaxTree, because the DocumentState already keeps the SyntaxTree alive. Interlocked.CompareExchange(ref _syntaxTreeResultTask, Task.FromResult(tree), null); // _syntaxTreeResultTask is a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the // conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant. return(_syntaxTreeResultTask !); } // do it async for real. // GetSyntaxTreeAsync returns a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the // conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant. return(DocumentState.GetSyntaxTreeAsync(cancellationToken).AsTask() !); }
protected override Task <CodeActionOperation?> UpdateProjectAsync( Project project, bool isPreview, CancellationToken cancellationToken ) { if (!ShouldAddProjectReference()) { return(SpecializedTasks.Null <CodeActionOperation>()); } var projectWithAddedReference = project.AddProjectReference( new ProjectReference(FixData.ProjectReferenceToAdd) ); var applyOperation = new ApplyChangesOperation(projectWithAddedReference.Solution); if (isPreview) { return(Task.FromResult <CodeActionOperation?>(applyOperation)); } return(Task.FromResult <CodeActionOperation?>( new AddProjectReferenceCodeActionOperation( OriginalDocument.Project.Id, FixData.ProjectReferenceToAdd, applyOperation ) )); }
/// <summary> /// Gets the <see cref="QuickInfoItem"/> associated with position in the document. /// </summary> public virtual Task <QuickInfoItem?> GetQuickInfoAsync( Document document, int position, CancellationToken cancellationToken = default) { return(SpecializedTasks.Null <QuickInfoItem>()); }
private Task <object> CreateChangedDocumentViewAsync(ITextBuffer oldBuffer, ITextBuffer newBuffer, string description, List <LineSpan> originalSpans, List <LineSpan> changedSpans, PreviewWorkspace leftWorkspace, PreviewWorkspace rightWorkspace, double zoomLevel, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!(originalSpans.Any() && changedSpans.Any())) { // Both line spans must be non-empty. Otherwise, below projection buffer factory API call will throw. // So if either is empty (signaling that there are no changes to preview in the document), then we bail out. // This can happen in cases where the user has already applied the fix and light bulb has already been dismissed, // but platform hasn't cancelled the preview operation yet. Since the light bulb has already been dismissed at // this point, the preview that we return will never be displayed to the user. So returning null here is harmless. return(SpecializedTasks.Null <object>()); } var originalBuffer = _projectionBufferFactoryService.CreateProjectionBufferWithoutIndentation( _contentTypeRegistryService, _editorOptionsFactoryService.GlobalOptions, oldBuffer.CurrentSnapshot, "...", description, originalSpans.ToArray()); var changedBuffer = _projectionBufferFactoryService.CreateProjectionBufferWithoutIndentation( _contentTypeRegistryService, _editorOptionsFactoryService.GlobalOptions, newBuffer.CurrentSnapshot, "...", description, changedSpans.ToArray()); return(CreateNewDifferenceViewerAsync(leftWorkspace, rightWorkspace, originalBuffer, changedBuffer, zoomLevel, cancellationToken)); }
public EventHookupSession( EventHookupSessionManager eventHookupSessionManager, EventHookupCommandHandler commandHandler, ITextView textView, ITextBuffer subjectBuffer, IAsynchronousOperationListener asyncListener, Mutex testSessionHookupMutex) : base(eventHookupSessionManager.ThreadingContext) { AssertIsForeground(); _cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _cancellationTokenSource.Token; _textView = textView; _subjectBuffer = subjectBuffer; this.TESTSessionHookupMutex = testSessionHookupMutex; var document = textView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document != null && document.Project.Solution.Workspace.CanApplyChange(ApplyChangesKind.ChangeDocument)) { var position = textView.GetCaretPoint(subjectBuffer).Value.Position; _trackingPoint = textView.TextSnapshot.CreateTrackingPoint(position, PointTrackingMode.Negative); // If the caret is at the end of the document we just create an empty span var length = textView.TextSnapshot.Length > position + 1 ? 1 : 0; _trackingSpan = textView.TextSnapshot.CreateTrackingSpan(new Span(position, length), SpanTrackingMode.EdgeInclusive); var asyncToken = asyncListener.BeginAsyncOperation(GetType().Name + ".Start"); this.GetEventNameTask = Task.Factory.SafeStartNewFromAsync( () => DetermineIfEventHookupAndGetHandlerNameAsync(document, position, cancellationToken), cancellationToken, TaskScheduler.Default); var continuedTask = this.GetEventNameTask.SafeContinueWithFromAsync( async t => { await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken); if (t.Result != null) { commandHandler.EventHookupSessionManager.EventHookupFoundInSession(this); } }, cancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); continuedTask.CompletesAsyncOperation(asyncToken); } else { _trackingPoint = textView.TextSnapshot.CreateTrackingPoint(0, PointTrackingMode.Negative); _trackingSpan = textView.TextSnapshot.CreateTrackingSpan(new Span(), SpanTrackingMode.EdgeInclusive); this.GetEventNameTask = SpecializedTasks.Null <string>(); eventHookupSessionManager.CancelAndDismissExistingSessions(); } }
internal virtual Task <QuickInfoItem?> GetQuickInfoAsync( Document document, int position, SymbolDescriptionOptions options, CancellationToken cancellationToken) { return(SpecializedTasks.Null <QuickInfoItem>()); }
public Task <IEnumerable <RecommendedKeyword> > RecommendKeywordsAsync(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) { if (IsValidContext(context)) { return(Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("var")))); } return(SpecializedTasks.Null <IEnumerable <RecommendedKeyword> >()); }
public Task <IEnumerable <RecommendedKeyword> > RecommendKeywordsAsync(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) { if (context.SyntaxTree.IsTypeParameterConstraintContext(position, context.LeftToken)) { return(Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("notnull")))); } return(SpecializedTasks.Null <IEnumerable <RecommendedKeyword> >()); }
public Task <RemoteHostClient> TryGetRemoteHostClientAsync(CancellationToken cancellationToken) { if (_lazyInstance == null) { return(SpecializedTasks.Null <RemoteHostClient>()); } return(_lazyInstance.GetValueAsync(cancellationToken)); }
public static Task <RemoteHostClient?> TryGetClientAsync(Project project, CancellationToken cancellationToken) { if (!RemoteSupportedLanguages.IsSupported(project.Language)) { return(SpecializedTasks.Null <RemoteHostClient>()); } return(TryGetClientAsync(project.Solution.Workspace, cancellationToken)); }
protected override Task <SyntaxNode?> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray <Diagnostic> diagnostics) { if (diagnostics.IsEmpty) { return(SpecializedTasks.Null <SyntaxNode>()); } return(_codeFixProvider.GetTransformedSyntaxRootAsync(document, fixAllContext.CancellationToken).AsNullable()); }
public Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken) { if (workspace.Options.GetOption(RemoteHostOptions.RemoteHostTest)) { return(InProcRemoteHostClient.CreateAsync(workspace, runCacheCleanup: false)); } return(SpecializedTasks.Null <RemoteHostClient>()); }
internal override Task <Diagnostic?> GetLoadDiagnosticAsync(CancellationToken cancellationToken) { if (TextAndVersionSource is TreeTextSource) { return(SpecializedTasks.Null <Diagnostic>()); } return(base.GetLoadDiagnosticAsync(cancellationToken)); }
public virtual void Stop() { ThreadingContext.ThrowIfNotOnUIThread(); // cancel all outstanding tasks. _stopTokenSource.Cancel(); // reset task so that it doesn't hold onto things like WpfTextView _notifyControllerTask = _lastTask = SpecializedTasks.Null <TModel>(); }
public static Task<RemoteHostClient?> TryGetClientAsync(Workspace workspace, CancellationToken cancellationToken) { var service = workspace.Services.GetService<IRemoteHostClientService>(); if (service == null) { return SpecializedTasks.Null<RemoteHostClient>(); } return service.TryGetRemoteHostClientAsync(cancellationToken); }
public override Task <CompletionDescription> GetDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken) { if (!item.Properties.TryGetValue(DescriptionKey, out var description)) { return(SpecializedTasks.Null <CompletionDescription>()); } return(Task.FromResult(CompletionDescription.Create( ImmutableArray.Create(new TaggedText(TextTags.Text, description))))); }
public virtual void Stop() { AssertIsForeground(); // cancel all outstanding tasks. _stopTokenSource.Cancel(); // reset task so that it doesn't hold onto things like WpfTextView _notifyControllerTask = _lastTask = SpecializedTasks.Null <TModel>(); }
public static Task <SymbolTreeInfo> TryGetCachedInfoForMetadataReferenceIgnoreChecksumAsync(PortableExecutableReference reference, CancellationToken cancellationToken) { var metadataId = GetMetadataIdNoThrow(reference); if (metadataId != null && s_metadataIdToInfo.TryGetValue(metadataId, out var infoTask)) { return(infoTask.GetValueAsync(cancellationToken)); } return(SpecializedTasks.Null <SymbolTreeInfo>()); }
public Task <RemoteHostClient> CreateAsync(HostWorkspaceServices services, CancellationToken cancellationToken) { var optionService = services.GetRequiredService <IOptionService>(); if (optionService.GetOption(RemoteHostOptions.RemoteHostTest)) { return(InProcRemoteHostClient.CreateAsync(services, runCacheCleanup: false)); } return(SpecializedTasks.Null <RemoteHostClient>()); }
public Task <string?> TryGetServiceNameAsync(CancellationToken cancellationToken) { if (!RemoteHostOptions.IsUsingServiceHubOutOfProcess(_workspace.Services)) { return(SpecializedTasks.Null <string>()); } var isRemoteHost64Bit = RemoteHostOptions.IsServiceHubProcess64Bit(_workspace.Services); return(Task.FromResult <string?>(new RemoteServiceName(WellKnownServiceHubService.CodeAnalysis).ToString(isRemoteHost64Bit))); }
public static Task <RemoteHostClient?> TryGetClientAsync(HostWorkspaceServices services, CancellationToken cancellationToken) { var service = services.GetService <IRemoteHostClientProvider>(); if (service == null) { return(SpecializedTasks.Null <RemoteHostClient>()); } return(service.TryGetRemoteHostClientAsync(cancellationToken)); }
public Task <IBlockContext> GetBlockContextAsync( IBlockTag blockTag, ITextView view, CancellationToken token) { if (blockTag is RoslynBlockTag) { var result = new RoslynBlockContext(_provider, blockTag, view); return(Task.FromResult <IBlockContext>(result)); } return(SpecializedTasks.Null <IBlockContext>()); }
public ModelComputation(IThreadingContext threadingContext, IController <TModel> controller, TaskScheduler computationTaskScheduler) : base(threadingContext) { _controller = controller; __taskScheduler = computationTaskScheduler; _stopTokenSource = new CancellationTokenSource(); _stopCancellationToken = _stopTokenSource.Token; // Dummy up a new task so we don't need to check for null. _notifyControllerTask = _lastTask = SpecializedTasks.Null <TModel>(); }
public override Task <VSProjectContextList?> HandleRequestAsync(VSGetProjectContextsParams request, RequestContext context, CancellationToken cancellationToken) { Contract.ThrowIfNull(context.Solution); // We specifically don't use context.Document here because we want multiple var documents = context.Solution.GetDocuments(request.TextDocument.Uri, context.ClientName); if (!documents.Any()) { return(SpecializedTasks.Null <VSProjectContextList>()); } var contexts = new List <VSProjectContext>(); foreach (var document in documents) { var project = document.Project; var projectContext = new VSProjectContext { Id = ProtocolConversions.ProjectIdToProjectContextId(project.Id), Label = project.Name }; if (project.Language == LanguageNames.CSharp) { projectContext.Kind = VSProjectKind.CSharp; } else if (project.Language == LanguageNames.VisualBasic) { projectContext.Kind = VSProjectKind.VisualBasic; } contexts.Add(projectContext); } // If the document is open, it doesn't matter which DocumentId we pass to GetDocumentIdInCurrentContext since // all the documents are linked at that point, so we can just pass the first arbitrarily. If the document is closed // GetDocumentIdInCurrentContext will just return the same ID back, which means we're going to pick the first // ID in GetDocumentIdsWithFilePath, but there's really nothing we can do since we don't have contexts for // close documents anyways. var openDocument = documents.First(); var currentContextDocumentId = openDocument.Project.Solution.Workspace.GetDocumentIdInCurrentContext(openDocument.Id); return(Task.FromResult <VSProjectContextList?>(new VSProjectContextList { ProjectContexts = contexts.ToArray(), DefaultIndex = documents.IndexOf(d => d.Id == currentContextDocumentId) })); }
public InProcRemoteHostClientProvider(HostWorkspaceServices services) { _services = services; _lazyClient = new AsyncLazy <RemoteHostClient?>(cancellationToken => { var optionService = _services.GetRequiredService <IOptionService>(); if (optionService.GetOption(RemoteTestHostOptions.RemoteHostTest)) { return(InProcRemoteHostClient.CreateAsync(_services, runCacheCleanup: false).AsNullable()); } return(SpecializedTasks.Null <RemoteHostClient>()); }, cacheResult: true); }
public Task <RemoteHostClient> TryGetRemoteHostClientAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); Task <RemoteHostClient> remoteClientTask; lock (_gate) { remoteClientTask = _remoteClientTask; } if (remoteClientTask == null) { // service is in shutdown mode or not enabled return(SpecializedTasks.Null <RemoteHostClient>()); } return(remoteClientTask); }
public Task <RemoteHostClient?> TryGetRemoteHostClientAsync(CancellationToken cancellationToken) => SpecializedTasks.Null <RemoteHostClient>();
static Task <Compilation?> GetCompilationOrNullAsync(Project?project, CancellationToken cancellationToken) => project?.GetCompilationAsync(cancellationToken) ?? SpecializedTasks.Null <Compilation>();
public Task <INavigableLocation?> GetNavigableLocationAsync(ISymbol symbol, Project project, CancellationToken cancellationToken) => SpecializedTasks.Null <INavigableLocation>();