Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IDocumentExtensions.cs « Util « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00e100ee8eb7e08c32a004f81efc11d9ee1ce26b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis;

namespace ICSharpCode.NRefactory6.CSharp
{
	static class IDocumentExtensions
	{
		public static async Task<CompilationUnitSyntax> GetCSharpSyntaxRootAsync(this Document document, CancellationToken cancellationToken = default(CancellationToken))
		{
			var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
			return (CompilationUnitSyntax)root;
		}

		public static Task<SyntaxTree> GetCSharpSyntaxTreeAsync(this Document document, CancellationToken cancellationToken = default(CancellationToken))
		{
			return document.GetSyntaxTreeAsync(cancellationToken);
		}

		public static Task<SemanticModel> GetCSharpSemanticModelAsync(this Document document, CancellationToken cancellationToken = default(CancellationToken))
		{
			return document.GetSemanticModelAsync(cancellationToken);
		}

		public static Task<SemanticModel> GetCSharpSemanticModelForNodeAsync(this Document document, SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
		{
			return document.GetSemanticModelForNodeAsync(node, cancellationToken);
		}

		public static Task<SemanticModel> GetCSharpSemanticModelForSpanAsync(this Document document, TextSpan span, CancellationToken cancellationToken = default(CancellationToken))
		{
			return document.GetSemanticModelForSpanAsync(span, cancellationToken);
		}

		public static Task<Compilation> GetCSharpCompilationAsync(this Document document, CancellationToken cancellationToken = default(CancellationToken))
		{
			return document.Project.GetCompilationAsync(cancellationToken);
		}
	}
}