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

IntroduceVariableCodeRefactoringProvider.cs « IntroduceVariable « MonoDevelop.CSharp.CodeRefactorings « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7cf7247aae823cb1846c404b143f3d37bfc1aa6 (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
// 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.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis;
using ICSharpCode.NRefactory6.CSharp.Features.IntroduceVariable;
using ICSharpCode.NRefactory6.CSharp;

namespace MonoDevelop.CSharp.CodeRefactorings.IntroduceVariable
{
	[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = PredefinedCodeRefactoringProviderNames.IntroduceVariable), Shared]
	class IntroduceVariableCodeRefactoringProvider : CodeRefactoringProvider
	{
		static readonly CSharpIntroduceVariableService service = new CSharpIntroduceVariableService ();

		public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
		{
			var document = context.Document;
			var textSpan = context.Span;
			var cancellationToken = context.CancellationToken;
			if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
			{
				return;
			}
			var model = await document.GetSemanticModelAsync (cancellationToken).ConfigureAwait (false);
			if (model.IsFromGeneratedCode (cancellationToken))
				return;
			var result = await service.IntroduceVariableAsync(document, textSpan, cancellationToken).ConfigureAwait(false);

			if (!result.ContainsChanges)
			{
				return;
			}

			var actions = result.GetCodeRefactoring(cancellationToken).Actions;
			context.RegisterRefactorings(actions);
		}
	}
}