예제 #1
0
            private IList <IPostfixLookupItem> TryReparseWith([NotNull] ISolution solution, [NotNull] ITextControl textControl,
                                                              [NotNull] string templateName, [NotNull] string reparseString)
            {
                var offset   = textControl.Caret.Offset();
                var document = textControl.Document;

                try
                {
                    document.InsertText(offset, reparseString);
                    solution.GetPsiServices().CommitAllDocuments();

                    var itemsOwner       = myItemsOwnerFactory.CreateLookupItemsOwner(textControl);
                    var executionContext = new PostfixExecutionContext(
                        myLifetime, solution, textControl, itemsOwner, reparseString, false);

                    foreach (var position in TextControlToPsi.GetElements <ITokenNode>(solution, document, offset))
                    {
                        var postfixContext = myTemplatesManager.IsAvailable(position, executionContext);
                        if (postfixContext == null)
                        {
                            continue;
                        }

                        return(myTemplatesManager.CollectItems(postfixContext, templateName: templateName));
                    }

                    return(null);
                }
                finally
                {
                    var reparseRange = TextRange.FromLength(offset, reparseString.Length);
                    document.DeleteText(reparseRange);
                }
            }
예제 #2
0
 protected PostfixTemplateContext([NotNull] ITreeNode reference,
                                  [NotNull] ICSharpExpression expression,
                                  [NotNull] PostfixExecutionContext executionContext)
 {
     myInnerExpression = expression;
     Reference         = reference;
     PsiModule         = reference.GetPsiModule();
     ExecutionContext  = executionContext;
 }
 public ReferenceNamePostfixTemplateContext([NotNull] IReferenceName reference,
                                            [NotNull] ICSharpExpression expression,
                                            [NotNull] PostfixExecutionContext executionContext)
     : base(reference, expression, executionContext)
 {
 }
예제 #4
0
        public PostfixTemplateContext IsAvailable([CanBeNull] ITreeNode position, [NotNull] PostfixExecutionContext context)
        {
            if (!(position is ICSharpIdentifier))
            {
                return(null);
            }

            // expr.__
            var referenceExpression = position.Parent as IReferenceExpression;

            if (referenceExpression != null && referenceExpression.Delimiter != null)
            {
                var expression = referenceExpression.QualifierExpression;
                if (expression != null)
                {
                    // protect from 'o.M(.var)'
                    var invocation = expression as IInvocationExpression;
                    if (invocation != null && invocation.LPar != null && invocation.RPar == null)
                    {
                        var argument = invocation.Arguments.LastOrDefault();
                        if (argument != null && argument.Expression == null)
                        {
                            return(null);
                        }
                    }

                    // protect from 'smth.var\n(someCode).InBraces()'
                    invocation = referenceExpression.Parent as IInvocationExpression;
                    if (invocation != null)
                    {
                        for (ITokenNode lpar = invocation.LPar,
                             token = invocation.InvokedExpression.NextSibling as ITokenNode;
                             token != null && token != lpar && token.IsFiltered();
                             token = token.NextSibling as ITokenNode)
                        {
                            if (token.GetTokenType() == CSharpTokenType.NEW_LINE)
                            {
                                return(null);
                            }
                        }
                    }

                    // protect from 'doubleDot..var'
                    var qualifierReference = expression as IReferenceExpression;
                    if (qualifierReference != null && qualifierReference.NameIdentifier == null)
                    {
                        return(null);
                    }

                    return(new ReferenceExpressionPostfixTemplateContext(referenceExpression, expression, context));
                }
            }

            // String.__
            var referenceName = position.Parent as IReferenceName;

            if (referenceName != null && referenceName.Qualifier != null && referenceName.Delimiter != null)
            {
                var typeUsage = referenceName.Parent as ITypeUsage;
                if (typeUsage != null)
                {
                    var expression = typeUsage.Parent as ICSharpExpression;
                    if (expression != null)
                    {
                        return(new ReferenceNamePostfixTemplateContext(referenceName, expression, context));
                    }
                }
            }

            // string.__
            var brokenStatement = FindBrokenStatement(position);

            if (brokenStatement != null)
            {
                var expressionStatement = brokenStatement.PrevSibling as IExpressionStatement;
                if (expressionStatement != null)
                {
                    var expression = FindExpressionBrokenByKeyword(expressionStatement);
                    if (expression != null)
                    {
                        return(new BrokenStatementPostfixTemplateContext(brokenStatement, expression, context));
                    }
                }
            }

            return(null);
        }
 public BrokenStatementPostfixTemplateContext([NotNull] ITreeNode reference,
                                              [NotNull] ICSharpExpression expression,
                                              [NotNull] PostfixExecutionContext executionContext)
     : base(reference, expression, executionContext)
 {
 }
            private IList<ILookupItem> TryReparseWith([NotNull] ISolution solution,
                                                [NotNull] ITextControl textControl,
                                                [NotNull] string templateName,
                                                [NotNull] string reparseString)
            {
                var offset = textControl.Caret.Offset();
                var document = textControl.Document;

                try
                {
                  document.InsertText(offset, reparseString);
                  solution.GetPsiServices().CommitAllDocuments();

                  var itemsOwner = myItemsOwnerFactory.CreateLookupItemsOwner(textControl);
                  var executionContext = new PostfixExecutionContext(
                myLifetime, solution, textControl, itemsOwner, reparseString, false);

                  foreach (var position in TextControlToPsi.GetElements<ITokenNode>(solution, document, offset))
                  {
                var postfixContext = myTemplatesManager.IsAvailable(position, executionContext);
                if (postfixContext == null) continue;

                return myTemplatesManager.CollectItems(postfixContext, templateName: templateName);
                  }

                  return null;
                }
                finally
                {
                  var reparseRange = TextRange.FromLength(offset, reparseString.Length);
                  document.DeleteText(reparseRange);
                }
            }