protected override void AfterComplete(ITextControl textControl, IUsingStatement statement) { var variableNames = SuggestResourceVariableNames(statement); var newStatement = PutStatementCaret(textControl, statement); if (newStatement == null) { return; } var resourceDeclaration = newStatement.Declaration; if (resourceDeclaration == null) { return; } var declaration = (ILocalVariableDeclaration)resourceDeclaration.Declarators[0]; var typeExpression = new MacroCallExpressionNew(new SuggestVariableTypeMacroDef()); var nameExpression = new NameSuggestionsExpression(variableNames); var typeSpot = new HotspotInfo( new TemplateField("type", typeExpression, 0), declaration.TypeUsage.GetDocumentRange()); var nameSpot = new HotspotInfo( new TemplateField("name", nameExpression, 0), declaration.NameIdentifier.GetDocumentRange()); var endSelectionRange = new TextRange(textControl.Caret.Offset()); var liveTemplatesManager = Info.ExecutionContext.LiveTemplatesManager; var session = liveTemplatesManager.CreateHotspotSessionAtopExistingText( newStatement.GetSolution(), endSelectionRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, typeSpot, nameSpot); session.Execute(); }
private Action <ITextControl> MarkInsertedDescription(ISolution solution, ExceptionDocCommentModel insertedExceptionModel) { var exceptionCommentRange = insertedExceptionModel.GetMarkerRange(); if (exceptionCommentRange == DocumentRange.InvalidRange) { return(null); } var copyExceptionDescription = string.IsNullOrEmpty(insertedExceptionModel.ExceptionDescription) || insertedExceptionModel.ExceptionDescription.Contains("[MARKER]"); var exceptionDescription = copyExceptionDescription ? "Condition" : insertedExceptionModel.ExceptionDescription; var nameSuggestionsExpression = new NameSuggestionsExpression(new[] { exceptionDescription }); var field = new TemplateField("name", nameSuggestionsExpression, 0); var fieldInfo = new HotspotInfo(field, exceptionCommentRange); return(textControl => { var hotspotSession = Shell.Instance.GetComponent <LiveTemplatesManager>() .CreateHotspotSessionAtopExistingText( solution, TextRange.InvalidRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, new[] { fieldInfo }); hotspotSession.Execute(); }); }
private Action<ITextControl> MarkInsertedDescription(ISolution solution, ExceptionDocCommentModel insertedExceptionModel) { var exceptionCommentRange = insertedExceptionModel.GetMarkerRange(); if (exceptionCommentRange == DocumentRange.InvalidRange) return null; var copyExceptionDescription = string.IsNullOrEmpty(insertedExceptionModel.ExceptionDescription) || insertedExceptionModel.ExceptionDescription.Contains("[MARKER]"); var exceptionDescription = copyExceptionDescription ? "Condition" : insertedExceptionModel.ExceptionDescription; var nameSuggestionsExpression = new NameSuggestionsExpression(new[] {exceptionDescription}); var field = new TemplateField("name", nameSuggestionsExpression, 0); var fieldInfo = new HotspotInfo(field, exceptionCommentRange); return textControl => { var hotspotSession = Shell.Instance.GetComponent<LiveTemplatesManager>() .CreateHotspotSessionAtopExistingText( solution, TextRange.InvalidRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, new[] {fieldInfo}); hotspotSession.Execute(); }; }