public override void Accept(JetBrains.TextControl.ITextControl textControl, JetBrains.Util.TextRange nameRange, LookupItemInsertType lookupItemInsertType, Suffix suffix, JetBrains.ProjectModel.ISolution solution, bool keepCaretStill) { Solution.GetPsiServices().Files.CommitAllDocuments(); IDisposable changeUnit = Shell.Instance.GetComponent <TextControlChangeUnitFactory>().CreateChangeUnit(textControl, "Expand live template"); try { var method = (IMethod)_instance.Element; var invocationExpression = ((IInvocationExpression)Context.NodeInFile.Parent); //target.GetMethod() string target = ((IReferenceExpression)invocationExpression.InvokedExpression).QualifierExpression.GetText(); if (!method.IsStatic) { target = string.Format("Expression.Default({0})", target); } textControl.Document.DeleteText(invocationExpression.GetDocumentRange().TextRange); string[] parameters; string[] arguments; BuildArguments(method, out parameters, out arguments); var template = new Template("GetMethodTemplate", string.Empty, string.Format("Expression.Call({0}, \"{1}\", new Type[] {{ {2} }}, {3}).Method", target, method.ShortName, string.Join(", ", parameters.Select(p => string.Format("typeof({0})", p))), string.Join(", ", arguments)), false, true, false, TemplateApplicability.Live); for (int i = 0; i < parameters.Length; i++) { template.Fields.Add(new TemplateField(parameters[i].Replace("$", string.Empty), parameters[i], 0)); } HotspotSession sessionFromTemplate = LiveTemplatesManager.Instance.CreateHotspotSessionFromTemplate( template, solution, textControl, (Action <IHotspotSession>)null); if (sessionFromTemplate == null) { return; } sessionFromTemplate.Execute(changeUnit); } catch { changeUnit.Dispose(); throw; } }
public void ExecuteTemplate() { IDeclaration newDeclaration = this.myDeclaration; newDeclaration.AssertIsValid(); ISolution solution = newDeclaration.GetPsiModule().GetSolution(); Debug.Assert(Shell.Instance.Invocator != null, "Shell.Instance.Invocator != null"); Shell.Instance.Invocator.Dispatcher.AssertAccess(); solution.GetComponent <SolutionDocumentTransactionManager>().AssertNotUnderTransaction(); IFile file = this.myAnchor.GetContainingFile(); Assertion.Assert(file != null, "fileFullName!= null"); var item = file.GetSourceFile().ToProjectFile(); var infos = GetFieldInfos(newDeclaration, this.myHolders); var textControl = EditorManager.GetInstance(solution).OpenProjectFile(item, true); if (textControl == null) { if (Shell.Instance.IsInInternalMode || Shell.Instance.IsTestShell) { Logger.Fail("textControl != null"); } return; } if (infos.Length > 0) { HotspotSession hotspotSession = LiveTemplatesManager.Instance.CreateHotspotSessionAtopExistingText( solution, TextRange.InvalidRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, infos); hotspotSession.Execute(); } Shell.Instance.GetComponent <NTriplesIntentionResultBehavior>().OnHotspotSessionExecutionStarted(this, textControl); }