Skip to content

Commit 04063fb

Browse files
committed
Add a useful helper method
1 parent 04c3cca commit 04063fb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Diagnostics.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.Text;
7+
using Microsoft.VisualStudio.Text;
8+
9+
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor;
10+
11+
internal static class ITextBufferExtensions
12+
{
13+
public static bool TryGetTextDocument(this ITextBuffer textBuffer, [NotNullWhen(true)] out TextDocument? textDocument)
14+
{
15+
textDocument = textBuffer.CurrentSnapshot.AsText().GetOpenTextDocumentInCurrentContextWithChanges();
16+
return textDocument is not null;
17+
}
18+
}

0 commit comments

Comments
 (0)