Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
Expand Down Expand Up @@ -44,36 +43,50 @@ internal sealed partial class BraceCompletionSessionProvider(
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService = editorOperationsFactoryService;
private readonly EditorOptionsService _editorOptionsService = editorOptionsService;

public bool TryCreateSession(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionSession session)
public bool TryCreateSession(
ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace,
[NotNullWhen(true)] out IBraceCompletionSession? session)
{
_threadingContext.ThrowIfNotOnUIThread();

var responsiveCompletion = textView.Options.GetOptionValue(DefaultOptions.ResponsiveCompletionOptionId);
var cancellationToken = GetCancellationToken(responsiveCompletion);
try
{
return TryCreateSessionWorker(out session);
}
catch (OperationCanceledException)
{
session = null;
return false;
}

var textSnapshot = openingPoint.Snapshot;
var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
bool TryCreateSessionWorker([NotNullWhen(true)] out IBraceCompletionSession? session)
{
var editorSessionFactory = document.GetLanguageService<IBraceCompletionServiceFactory>();
if (editorSessionFactory != null)
var textSnapshot = openingPoint.Snapshot;
var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var parsedDocument = ParsedDocument.CreateSynchronously(document, cancellationToken);
var editorSession = editorSessionFactory.TryGetService(parsedDocument, openingPoint, openingBrace, cancellationToken);
if (editorSession != null)
var editorSessionFactory = document.GetLanguageService<IBraceCompletionServiceFactory>();
if (editorSessionFactory != null)
{
var undoHistory = _undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory;
session = new BraceCompletionSession(
this, textView, openingPoint.Snapshot.TextBuffer,
openingPoint, openingBrace, closingBrace,
undoHistory, editorSession, responsiveCompletion);
return true;
var parsedDocument = ParsedDocument.CreateSynchronously(document, cancellationToken);
var editorSession = editorSessionFactory.TryGetService(parsedDocument, openingPoint, openingBrace, cancellationToken);
if (editorSession != null)
{
var undoHistory = _undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory;
session = new BraceCompletionSession(
this, textView, openingPoint.Snapshot.TextBuffer,
openingPoint, openingBrace, closingBrace,
undoHistory, editorSession, responsiveCompletion);
return true;
}
}
}
}

session = null;
return false;
session = null;
return false;
}
}

private static CancellationToken GetCancellationToken(bool responsiveCompletion)
Expand Down
Loading