Ejemplo n.º 1
0
        bool IsInComment(SharpDevelopTextAreaControl editor)
        {
            VBExpressionFinder ef = new VBExpressionFinder();
            int cursor            = editor.ActiveTextAreaControl.Caret.Offset - 1;

            return(ef.FilterComments(editor.Document.GetText(0, cursor + 1), ref cursor) == null);
        }
Ejemplo n.º 2
0
        private void OnToolTipRequest(object sender, ToolTipRequestEventArgs e)
        {
            if (e.InDocument && !e.ToolTipShown)
            {
                IExpressionFinder expressionFinder;
                if (MainForm.IsVisualBasic)
                {
                    expressionFinder = new VBExpressionFinder();
                }
                else
                {
                    expressionFinder = new CSharpExpressionFinder(mainForm.parseInformation);
                }
                ExpressionResult expression = expressionFinder.FindFullExpression(
                    editor.Text,
                    editor.Document.PositionToOffset(e.LogicalPosition));
                if (expression.Region.IsEmpty)
                {
                    expression.Region = new DomRegion(e.LogicalPosition.Line + 1, e.LogicalPosition.Column + 1);
                }

                TextArea           textArea = editor.ActiveTextAreaControl.TextArea;
                NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent.Language);
                ResolveResult      rr       = resolver.Resolve(expression,
                                                               mainForm.parseInformation,
                                                               textArea.MotherTextEditorControl.Text);
                string toolTipText = GetText(rr);
                if (toolTipText != null)
                {
                    e.ShowToolTip(toolTipText);
                }
            }
        }
Ejemplo n.º 3
0
        private bool IsInComment(CodeEditorControl editor)
        {
            VBExpressionFinder ef = new VBExpressionFinder();
            int cursor            = editor.ActiveViewControl.Caret.Offset - 1;

            return(ef.FilterComments(ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName).Substring(0, cursor + 1), ref cursor) == null);
        }
Ejemplo n.º 4
0
        protected ExpressionResult GetExpression(EditViewControl textArea)
        {
            SyntaxDocument    document         = textArea.Document;
            IExpressionFinder expressionFinder = null;

            if (Parser.ProjectParser.CurrentProjectContent.Language == LanguageProperties.CSharp)
            {
                expressionFinder = new CSharpExpressionFinder(this.fileName);
            }
            else
            {
                expressionFinder = new VBExpressionFinder();
            }
            if (expressionFinder == null)
            {
                return(new ExpressionResult(textArea.Caret.CurrentWord.Text));
            }
            else
            {
                TextRange        range = new TextRange(0, 0, textArea.Caret.Position.X, textArea.Caret.Position.Y);
                ExpressionResult res   = expressionFinder.FindExpression(document.GetRange(range), textArea.Caret.Offset - 1);
                if (overrideContext != null)
                {
                    res.Context = overrideContext;
                }
                return(res);
            }
        }
Ejemplo n.º 5
0
        public void Init()
        {
            HostCallback.GetCurrentProjectContent = delegate {
                return(ParserService.CurrentProjectContent);
            };

            ef = new VBExpressionFinder();
        }
Ejemplo n.º 6
0
        public void SetupDataProvider(string fileName)
        {
            IExpressionFinder expressionFinder;

            if (IntellisenseForm.SupportedLanguage == ESupportedLanguage.VisualBasic)
            {
                expressionFinder = new VBExpressionFinder();
            }
            else
            {
                expressionFinder = new CSharpExpressionFinder(iForm.ParseInformation);
            }

            //TextLocation position = m_textarea.Caret.Position;
            //ExpressionResult expression = expressionFinder.FindFullExpression(m_textarea.MotherTextEditorControl.Text, m_textarea.Document.PositionToOffset(position));
            //if (expression.Region.IsEmpty)
            //{
            //    expression.Region = new DomRegion(position.Line + 1, position.Column + 1);
            //}
            ExpressionResult expression = expressionFinder.FindFullExpression(
                m_textarea.MotherTextEditorControl.Text,
                m_textarea.MotherTextEditorControl.Document.PositionToOffset(m_textarea.Caret.Position) - 1);

            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(m_textarea.Caret.Position.Line + 1, m_textarea.Caret.Position.Column + 1);
            }



            NRefactoryResolver resolver = new NRefactoryResolver(iForm.ProjectContent.Language);
            ResolveResult      rr       = resolver.Resolve(expression, iForm.ParseInformation, m_textarea.MotherTextEditorControl.Text);

            List <string> lines = new List <string>();

            if (rr is MethodGroupResolveResult)
            {
                MethodGroupResolveResult mrr = rr as MethodGroupResolveResult;
                IAmbience ambience           = IntellisenseForm.SupportedLanguage == ESupportedLanguage.VisualBasic ? (IAmbience) new VBNetAmbience() : new CSharpAmbience();
                ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility;

                foreach (MethodGroup methodgroup in mrr.Methods)
                {
                    foreach (IMethod method in methodgroup)
                    {
                        lines.Add(ToolTipProvider.GetMemberText(ambience, method));
                    }
                }
            }

            m_insighttext         = (lines.Count > 0) ? lines.ToArray() : null;
            m_argumentstartoffset = m_textarea.Caret.Offset;
        }
Ejemplo n.º 7
0
        public void SetupDataProvider(string fileName, EditViewControl textArea)
        {
            if (setupOnlyOnce && this.textArea != null)
            {
                return;
            }
            SyntaxDocument document = textArea.Document;

            this.fileName = fileName;
            this.document = document;
            this.textArea = textArea;
            int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;

            initialOffset = useOffset;


            IExpressionFinder expressionFinder = null;

            if (Parser.ProjectParser.CurrentProjectContent.Language == LanguageProperties.CSharp)
            {
                expressionFinder = new CSharpExpressionFinder(fileName);
            }
            else
            {
                expressionFinder = new VBExpressionFinder();
            }

            ExpressionResult expressionResult;

            if (expressionFinder == null)
            {
                expressionResult = new ExpressionResult(textArea.Caret.CurrentWord.Text);                //TextUtilities.GetExpressionBeforeOffset(textArea, useOffset));
            }
            else
            {
                expressionResult = expressionFinder.FindExpression(Parser.ProjectParser.GetFileContents(fileName), useOffset - 1);
            }
            if (expressionResult.Expression == null)             // expression is null when cursor is in string/comment
            {
                return;
            }
            expressionResult.Expression = expressionResult.Expression.Trim();

            // the parser works with 1 based coordinates
            TextPoint tp = document.IntPosToPoint(useOffset + 1);
            int       caretLineNumber = tp.Y;
            int       caretColumn     = tp.X;

            SetupDataProvider(fileName, document, expressionResult, caretLineNumber, caretColumn);
        }
Ejemplo n.º 8
0
        public void SetupDataProvider(string fileName)
        {
            IExpressionFinder expressionFinder;

            if (IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic)
            {
                expressionFinder = new VBExpressionFinder();
            }
            else
            {
                expressionFinder = new CSharpExpressionFinder(_iForm.ParseInformation);
            }

            //TextLocation position = _textArea.Caret.Position;
            //ExpressionResult expression = expressionFinder.FindFullExpression(_textArea.MotherTextEditorControl.Text, _textArea.Document.PositionToOffset(position));
            //if (expression.Region.IsEmpty)
            //{
            //    expression.Region = new DomRegion(position.Line + 1, position.Column + 1);
            //}
            var expression = expressionFinder.FindFullExpression(
                _textArea.MotherTextEditorControl.Text,
                _textArea.MotherTextEditorControl.Document.PositionToOffset(_textArea.Caret.Position) - 1);

            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(_textArea.Caret.Position.Line + 1, _textArea.Caret.Position.Column + 1);
            }


            var resolver = new NRefactoryResolver(_iForm.ProjectContent.Language);
            var rr       = resolver.Resolve(expression, _iForm.ParseInformation, _textArea.MotherTextEditorControl.Text);

            var lines = new List <string>();

            if (rr is MethodGroupResolveResult)
            {
                var mrr      = rr as MethodGroupResolveResult;
                var ambience = IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic
                                        ? (IAmbience) new VBNetAmbience()
                                        : new CSharpAmbience();
                ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility;

                lines.AddRange(mrr.Methods.SelectMany(methodgroup => methodgroup,
                                                      (methodgroup, method) => ToolTipProvider.GetMemberText(ambience, method)));
            }

            _insighText         = lines.Count > 0 ? lines.ToArray() : null;
            ArgumentStartOffset = _textArea.Caret.Offset;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Find the expression the cursor is at.
        /// Also determines the context (using statement, "new"-expression etc.) the
        /// cursor is at.
        /// </summary>
        private ExpressionResult FindExpression(TextArea textArea)
        {
            IExpressionFinder finder;

            if (MainForm.IsVisualBasic)
            {
                finder = new VBExpressionFinder();
            }
            else
            {
                finder = new CSharpExpressionFinder(mainForm.parseInformation);
            }
            ExpressionResult expression = finder.FindExpression(textArea.Document.TextContent, textArea.Caret.Offset);

            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(textArea.Caret.Line + 1, textArea.Caret.Column + 1);
            }
            return(expression);
        }
Ejemplo n.º 10
0
        private void OnToolTipRequest(object sender, TextEditor.ToolTipRequestEventArgs e)
        {
            if (!e.InDocument || e.ToolTipShown)
            {
                return;
            }

            IExpressionFinder expressionFinder;

            if (IntellisenseForm.SupportedLanguage == SupportedLanguage.VisualBasic)
            {
                expressionFinder = new VBExpressionFinder();
            }
            else
            {
                expressionFinder = new CSharpExpressionFinder(_iForm.ParseInformation);
            }

            var expression = expressionFinder.FindFullExpression(
                _editor.Text,
                _editor.Document.PositionToOffset(e.LogicalPosition));

            if (expression.Region.IsEmpty)
            {
                expression.Region = new DomRegion(e.LogicalPosition.Line + 1, e.LogicalPosition.Column + 1);
            }

            var textArea = _editor.ActiveTextAreaControl.TextArea;
            var resolver = new NRefactoryResolver(_iForm.ProjectContent.Language);
            var rr       = resolver.Resolve(expression,
                                            _iForm.ParseInformation,
                                            textArea.MotherTextEditorControl.Text);

            var toolTipText = GetText(rr);

            if (toolTipText != null)
            {
                e.ShowToolTip(toolTipText);
            }
        }
Ejemplo n.º 11
0
        public override bool HandleKeyPress(CodeEditorControl editor, char ch)
        {
            VBExpressionFinder ef     = new VBExpressionFinder();
            int cursor                = editor.ActiveViewControl.Caret.Offset;
            ExpressionContext context = null;

            if (ch == '(')
            {
                if (CodeCompletionOptions.KeywordCompletionEnabled)
                {
                    switch (editor.ActiveViewControl.Caret.CurrentWord.Text.Trim())
                    {
                    case "For":
                    case "Lock":
                        context = ExpressionContext.Default;
                        break;

                    case "using":
                        context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.IDisposable"), false);
                        break;

                    case "Catch":
                        context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.Exception"), false);
                        break;

                    case "For Each":
                    case "typeof":
                    case "default":
                        context = ExpressionContext.Type;
                        break;
                    }
                }
                if (context != null)
                {
                    if (IsInComment(editor))
                    {
                        return(false);
                    }
                    editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ch);
                    return(true);
                }
                else if (EnableMethodInsight)
                {
                    editor.ActiveViewControl.ShowInsightWindow(new MethodInsightDataProvider());
                    return(true);
                }
                return(false);
            }
            else if (ch == '<')
            {
                Word curWord = editor.ActiveViewControl.Caret.CurrentWord;
                //Word preWord =  curWord.Row.FormattedWords[curWord.Index-1];
                //int lineOffset = editor.ActiveViewControl.Document.Text.Substring(0, editor.ActiveViewControl.Caret.Offset - editor.ActiveViewControl.Caret.Position.X).Length;
                //TextPoint tp = editor.ActiveViewControl.Document.IntPosToPoint(lineOffset);

                if (curWord == null || curWord.Text.Length == 0)
                {
                    // [ is first character on the line
                    // -> Attribute completion
                    editor.ActiveViewControl.ShowCompletionWindow(new AttributesDataProvider(ScriptControl.Parser.ProjectParser.CurrentProjectContent), ch);
                    return(true);
                }
            }
            else if (ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled)
            {
                if (InsightRefreshOnComma(editor, ch))
                {
                    return(true);
                }
            }
            else if (ch == '=')
            {
                string curLine      = editor.ActiveViewControl.Caret.CurrentRow.Text;
                string documentText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName);
                int    position     = editor.ActiveViewControl.Caret.Offset - 2;

                if (position > 0 && (documentText[position + 1] == '+'))
                {
                    ExpressionResult result = ef.FindFullExpression(documentText, position);

                    if (result.Expression != null)
                    {
                        ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText);
                        if (resolveResult != null && resolveResult.ResolvedType != null)
                        {
                            IClass underlyingClass = resolveResult.ResolvedType.GetUnderlyingClass();
                            if (underlyingClass == null && resolveResult.ResolvedType.FullyQualifiedName.Length > 0)
                            {
                                underlyingClass = ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass(resolveResult.ResolvedType.FullyQualifiedName);
                            }
                            if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.MulticastDelegate")))
                            {
                                //EventHandlerCompletitionDataProvider eventHandlerProvider = new EventHandlerCompletitionDataProvider(result.Expression, resolveResult);
                                //eventHandlerProvider.InsertSpace = true;
                                //editor.ActiveViewControl.ShowCompletionWindow(eventHandlerProvider, ch);
                            }
                        }
                    }
                }
                else if (position > 0)
                {
                    ExpressionResult result = ef.FindFullExpression(documentText, position);
                    if (result.Expression != null)
                    {
                        ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText);
                        if (resolveResult != null && resolveResult.ResolvedType != null)
                        {
                            if (ProvideContextCompletion(editor, resolveResult.ResolvedType, ch))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else if (ch == '\n')
            {
                string curLine = editor.ActiveViewControl.Caret.CurrentRow.Text;
                // don't return true when inference succeeds, otherwise the ';' won't be added to the document.
                TryDeclarationTypeInference(editor, curLine);
            }

            return(base.HandleKeyPress(editor, ch));
        }