protected void Parse(StringReader rdr, DepthScanner scanner, Globals globals)
        {
            int currentLine = 0;
            ParseNamespace(rdr, globals, scanner, ref currentLine, false);

            // Resolve incomplete names
            foreach (string key in globals.GetPropertyNames())
            {
                TypeInfo t = globals.GetProperty(key, true) as TypeInfo;
                if (t != null)
                {
                    if (!t.IsComplete)
                        globals.AddProperty(key, globals.GetTypeInfo(t.Name), -1, "");
                    if (t is TemplateInst)
                    {
                        TemplateInst ti = t as TemplateInst;
                        if (!ti.WrappedType.IsComplete)
                            ti.WrappedType = globals.GetTypeInfo(ti.WrappedType.Name);
                    }
                }
            }

            foreach (FunctionInfo f in globals.GetFunctions(null, true))
            {
                f.ResolveIncompletion(globals);
            }

            foreach (TypeInfo type in globals.TypeInfo)
            {
                type.ResolveIncompletion(globals);
            }
        }
Example #2
0
 void editor_TextChanged(object sender, EventArgs e)
 {
     MainWindow.inst().Dispatcher.BeginInvoke((System.Windows.Forms.MethodInvoker) delegate() {
         changeChecker.Recheck();
         DepthScanner newScan = new DepthScanner();
         newScan.Process(editor.Text);
         scanner = newScan;
     });
 }
Example #3
0
        void editor_TextChanged(object sender, EventArgs e)
        {
            string text = editor.Text;

            new Thread(delegate()
            {
                DepthScanner newScan = new DepthScanner();
                newScan.Process(text);
                MainWindow.inst().Dispatcher.BeginInvoke((System.Windows.Forms.MethodInvoker) delegate()
                {
                    changeChecker.Recheck();
                    scanner = newScan;
                });
            }).Start();
            UpdateFoldings();
        }
        public override Globals Parse(string path, string fileCode, string[] includePaths)
        {
            Globals ret = new Globals(false);

            // Merge global app registered types into it
            ret.Parent = hlslGlobs;

            List<string> existingPaths = new List<string>();
            // Inline #includes
            fileCode = ProcessIncludes(path, fileCode, includePaths, existingPaths);
            // Strip comments
            fileCode = StripComments(fileCode);
            DepthScanner scanner = new DepthScanner();
            scanner.Process(fileCode);
            Parse(new StringReader(fileCode), scanner, ret);
            return ret;
        }
        public override Globals Parse(string path, string fileCode, string[] includePaths)
        {
            Globals ret = new Globals(false);

            // Merge global app registered types into it
            ret.Parent = hlslGlobs;

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

            // Inline #includes
            fileCode = ProcessIncludes(path, fileCode, includePaths, existingPaths);
            // Strip comments
            fileCode = StripComments(fileCode);
            DepthScanner scanner = new DepthScanner();

            scanner.Process(fileCode);
            Parse(new StringReader(fileCode), scanner, ret);
            return(ret);
        }
        protected void Parse(StringReader rdr, DepthScanner scanner, Globals globals)
        {
            int currentLine = 0;

            ParseNamespace(rdr, globals, scanner, ref currentLine, false);

            // Resolve incomplete names
            foreach (string key in globals.GetPropertyNames())
            {
                TypeInfo t = globals.GetProperty(key, true) as TypeInfo;
                if (t != null)
                {
                    if (!t.IsComplete)
                    {
                        globals.AddProperty(key, globals.GetTypeInfo(t.Name), -1, "");
                    }
                    if (t is TemplateInst)
                    {
                        TemplateInst ti = t as TemplateInst;
                        if (!ti.WrappedType.IsComplete)
                        {
                            ti.WrappedType = globals.GetTypeInfo(ti.WrappedType.Name);
                        }
                    }
                }
            }

            foreach (FunctionInfo f in globals.GetFunctions(null, true))
            {
                f.ResolveIncompletion(globals);
            }

            foreach (TypeInfo type in globals.TypeInfo)
            {
                type.ResolveIncompletion(globals);
            }
        }
Example #7
0
 public void EditorKeyUp(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner depthScanner, System.Windows.Input.KeyEventArgs e)
 {
     // Do nothing
 }
        public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, MouseEventArgs e)
        {
            TextViewPosition?pos = editor.GetPositionFromPoint(e.GetPosition(editor));

            if (pos != null)
            {
                try
                {
                    int     line   = pos.Value.Line;
                    int     offset = editor.Document.GetOffset(pos.Value.Location);
                    Globals globs  = GetGlobals();
                    if (globs != null)
                    {
                        bool     isFunc = false;
                        string[] words  = IntellisenseHelper.ExtractPath(editor.Document, offset, pos.Value.Location.Line, out isFunc);
                        if (words != null && words.Length > 0)
                        {
                            BaseTypeInfo info = null;
                            FunctionInfo func = null;
                            NameResolver reso = new NameResolver(globs, scanner);
                            if (words.Length > 1)
                            {
                                for (int i = 0; i < words.Length; ++i)
                                {
                                    if (i == words.Length - 1 && info != null && isFunc)
                                    {
                                        if (info is TypeInfo)
                                        {
                                            func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                                        }
                                    }
                                    else
                                    {
                                        if (info == null)
                                        {
                                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                                        }
                                        else if (info != null && info is TypeInfo)
                                        {
                                            if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                            {
                                                info = ((TypeInfo)info).Properties[words[i]];
                                            }
                                        }
                                    }
                                }
                            }
                            else if (isFunc && words.Length == 1)
                            {
                                func = globs.GetFunction(words[0]);
                            }
                            else if (!isFunc && words.Length == 1)
                            {
                                info = reso.GetClassType(editor.Document, line, words[0]);
                                if (info == null)
                                {
                                    TypeInfo ty = globs.GetTypeInfo(words[0]);
                                    if (ty != null)
                                    {
                                        info = ty;
                                    }
                                }
                            }

                            string msg = "";
                            // Ask documentation for the information
                            if (info != null && func != null && info is TypeInfo)
                            { //member function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name + "::" + func.Name + func.Inner);
                                if (m != null)
                                {
                                    msg += "\r\n" + m;
                                }
                            }
                            else if (func != null)
                            { //global function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(func.Name + func.Inner);
                                if (m != null)
                                {
                                    msg += "\r\n" + m;
                                }
                            }
                            else if (info != null && info is TypeInfo)
                            { //global or member type
                                msg = ((TypeInfo)info).Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name);
                                if (m != null)
                                {
                                    msg += "\r\n" + m;
                                }
                            }

                            if (msg.Length > 0)
                            {
                                InsightWindow window = new InsightWindow(editor.TextArea);
                                window.Content = msg;
                                window.Show();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //deliberately swallow any exceptions here
                }
            }
        }
Example #9
0
        public IDEEditor(FileBaseItem aItem)
        {
            InitializeComponent();
            item          = aItem;
            changeChecker = new DataChanged {
                editor = editor
            };
            SetCode(aItem);
            editor.ShowLineNumbers = true;
            if (aItem.Name.EndsWith(".as"))
            {
                editor.SyntaxHighlighting = LoadHighlightingDefinition("Debugger.Resources.Angelscript.xshd");
            }
            else if (aItem.Name.EndsWith(".xml"))
            {
                editor.SyntaxHighlighting = LoadHighlightingDefinition("Debugger.Resources.XML.xshd");
            }
            else
            {
                editor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(item.Path.Substring(item.Path.LastIndexOf('.')));
            }

            editor.FontFamily = new FontFamily("Consolas");
            editor.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDCDCCC"));
            editor.TextArea.TextView.BackgroundRenderers.Add(new LineHighlighter());
            editor.TextArea.TextView.BackgroundRenderers.Add(new ErrorLineHighlighter(aItem));
            Debugger.Editor.SearchPanel.Install(editor);
            editor.TextChanged += editor_TextChanged;
            scanner             = new DepthScanner();
            scanner.Process(editor.Text);
            editor.MouseHover += editor_MouseHover;
            editor.KeyUp      += editor_KeyUp;

            editor.ContextMenu = new ContextMenu();
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Compile",
                Command = new RelayCommand(p =>
                {
                    IDEView.Compile();
                })
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "New ScriptObject",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset, SOScript);
                    editor.Document.EndUpdate();
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Insert #include",
                Command = new RelayCommand(p => {
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                    dlg.DefaultExt = "*";
                    dlg.Filter     = "All files (*.*)|*.*";
                    if (dlg.ShowDialog() == true)
                    {
                        editor.Document.BeginUpdate();
                        editor.Document.Insert(editor.CaretOffset, string.Format("#include \"{0}\"", dlg.FileName));
                        editor.Document.EndUpdate();
                    }
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Doxygen Comment",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset,
                                           @"/////////////////////////////////////////////////
/// DOCUMENT_HERE
/////////////////////////////////////////////////", AnchorMovementType.AfterInsertion);
                    editor.Document.EndUpdate();
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Property Comment",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset, "///< DOCUMENT", AnchorMovementType.AfterInsertion);
                    editor.Document.EndUpdate();
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Snippet",
                Command = new RelayCommand(p =>
                {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string ext = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(ext))
                        {
                            snips.Add(snip);
                        }
                    }
                    if (snips.Count > 0)
                    {
                        Snippets.SnippetDlg dlg = new Snippets.SnippetDlg(editor, snips);
                        dlg.ShowDialog();
                    }
                }, sp => {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string exte = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(exte))
                        {
                            return(true);
                        }
                    }
                    return(false);
                })
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Cut",
                Command = ApplicationCommands.Cut
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Copy",
                Command = ApplicationCommands.Copy
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Paste",
                Command = ApplicationCommands.Paste
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Undo",
                Command = ApplicationCommands.Undo
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Redo",
                Command = ApplicationCommands.Redo
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save",
                Command = ApplicationCommands.Save
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save As",
                Command = ApplicationCommands.SaveAs
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Open",
                Command = ApplicationCommands.Open
            });
        }
        public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, MouseEventArgs e)
        {
            TextViewPosition? pos = editor.GetPositionFromPoint(e.GetPosition(editor));
            if (pos != null)
            {
                try
                {
                    int line = pos.Value.Line;
                    int offset = editor.Document.GetOffset(pos.Value.Location);
                    Globals globs = GetGlobals();
                    if (globs != null)
                    {
                        bool isFunc = false;
                        string[] words = IntellisenseHelper.ExtractPath(editor.Document, offset, pos.Value.Location.Line, out isFunc);
                        if (words != null && words.Length > 0)
                        {
                            BaseTypeInfo info = null;
                            FunctionInfo func = null;
                            NameResolver reso = new NameResolver(globs, scanner);
                            if (words.Length > 1)
                            {
                                for (int i = 0; i < words.Length; ++i)
                                {
                                    if (i == words.Length - 1 && info != null && isFunc)
                                    {
                                        if (info is TypeInfo)
                                            func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                                    }
                                    else
                                    {
                                        if (info == null)
                                        {
                                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                                        }
                                        else if (info != null && info is TypeInfo)
                                        {
                                            if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                                info = ((TypeInfo)info).Properties[words[i]];
                                        }
                                    }
                                }
                            }
                            else if (isFunc && words.Length == 1)
                            {
                                func = globs.GetFunction(words[0]);
                            }
                            else if (!isFunc && words.Length == 1)
                            {
                                info = reso.GetClassType(editor.Document, line, words[0]);
                                if (info == null)
                                {
                                    TypeInfo ty = globs.GetTypeInfo(words[0]);
                                    if (ty != null)
                                        info = ty;
                                }
                            }

                            string msg = "";
                            // Ask documentation for the information
                            if (info != null && func != null && info is TypeInfo)
                            { //member function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name + "::" + func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (func != null)
                            { //global function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (info != null && info is TypeInfo)
                            { //global or member type
                                msg = ((TypeInfo)info).Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }

                            if (msg.Length > 0)
                            {
                                InsightWindow window = new InsightWindow(editor.TextArea);
                                window.Content = msg;
                                window.Show();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //deliberately swallow any exceptions here
                }
            }
        }
        public void EditorKeyUp(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, System.Windows.Input.KeyEventArgs e)
        {
            Globals g = GetGlobals();
            if (g == null)
                return;
            // These keys halt and terminate intellisense
            switch (e.Key)
            {
                case Key.Home:
                case Key.End:
                case Key.Left:
                case Key.Right:
                case Key.Escape:
                case Key.LWin:
                case Key.RWin:
                case Key.Space:
                    if (currentComp != null)
                        currentComp.Close();
                    return;
            }
            // These keys halt further checks
            switch (e.Key)
            {
                case Key.Up:
                case Key.Down:
                case Key.PageDown:
                case Key.PageUp:
                case Key.LeftShift:
                case Key.RightShift:
                case Key.LeftAlt:
                case Key.RightAlt:
                case Key.LeftCtrl:
                case Key.RightCtrl:
                case Key.Scroll:
                case Key.Capital:
                case Key.CrSel:
                case Key.Clear:
                case Key.Insert:
                case Key.PrintScreen:
                case Key.Print:
                    return;
            }

            char KEY = KeyHelpers.GetCharFromKey(e.Key);
            if (KEY == ')' || KEY == ';')
            {
                if (currentComp != null)
                    currentComp.Close();
                return;
            }
            int curOfs = editor.TextArea.Caret.Offset;
            int line = editor.TextArea.Caret.Line;

            // Do not attempt intellisense inside of comments
            string txt = editor.Document.GetText(editor.Document.Lines[editor.TextArea.Caret.Line - 1]);
            if (txt.Trim().StartsWith("//"))
                return;

            // Check for anything to display in response to a potential namespace, scope, or dot
            if (e.Key == Key.OemPeriod || KEY == ':')
            {
                //IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs-1, line-1)) {
                int ofs = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                ofs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                string word = "";
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                        word += editor.Document.Text[ofs];
                }

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info = null;
                string[] words = IntellisenseHelper.DotPath(editor.Document, curOfs - 1, line - 1);
                if (words.Length > 0)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (info == null)
                        {
                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            if (info == null && GetGlobals().ContainsProperty(words[i]))
                                info = GetGlobals().GetProperty(words[i], true);
                        }
                        else if (info != null)
                        {
                            info = info.ResolvePropertyPath(GetGlobals(), words[i]);
                        }
                    }
                }

                bool functionsOnly = false;
                //attempt to resolve it locally
                if (info == null)
                    info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, word);
                //attempt to resolve it from globals
                if (info == null && GetGlobals() != null && GetGlobals().ContainsProperty(word))
                    info = GetGlobals().GetProperty(word, true);
                if (info == null && word.Contains("::"))
                {
                    if (GetGlobals() == null)
                        return;
                    if (word.Length > 2)
                    {
                        string ns = word.Replace("::", "");
                        if (GetGlobals().ContainsTypeInfo(ns))
                        {
                            EnumInfo ti = GetGlobals().GetTypeInfo(word.Replace("::", "")) as EnumInfo;
                            if (ti != null)
                            {
                                currentComp = new CompletionWindow(editor.TextArea);
                                IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                                foreach (string str in ti.Values)
                                    data.Add(new BaseCompletionData(null, str));
                                currentComp.Show();
                                currentComp.Closed += comp_Closed;
                                return;
                            }
                            else
                            {
                                TypeInfo ty = GetGlobals().GetTypeInfo(word.Replace("::", ""));
                                if (ty != null)
                                {
                                    info = ty;
                                    functionsOnly = true;
                                }
                            }
                        }
                        else
                        { //list global functions because we've received "::" only
                            Globals globs = GetGlobals();
                            bool asNS = false;
                            if (globs.ContainsNamespace(ns))
                            {
                                asNS = true;
                                globs = globs.GetNamespace(ns);
                            }
                            currentComp = new CompletionWindow(editor.TextArea);
                            IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                            foreach (string str in globs.GetPropertyNames())
                            {
                                TypeInfo ti = globs.GetProperty(str, !asNS) as TypeInfo;
                                if (ti != null)
                                    data.Add(new PropertyCompletionData(ti, str));
                            }
                            foreach (FunctionInfo fi in globs.GetFunctions(null, false))
                                data.Add(new FunctionCompletionData(fi));
                            if (asNS) //Include classes
                            {
                                foreach (TypeInfo ti in globs.TypeInfo)
                                    data.Add(new ClassCompletionData(ti));
                            }
                            currentComp.Show();
                            currentComp.Closed += comp_Closed;
                            return;
                        }
                    }
                }

                //build the list
                if (info != null && info is TypeInfo)
                {
                    TypeInfo ti = info as TypeInfo;
                    currentComp = new CompletionWindow(editor.TextArea);
                    IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                    if (!functionsOnly)
                    {
                        foreach (string str in ti.Properties.Keys)
                        {
                            data.Add(new PropertyCompletionData(ti.Properties[str], str,
                                ti.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                (ti.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                        }
                        foreach (TypeInfo t in ti.BaseTypes)
                        {
                            foreach (string str in t.Properties.Keys)
                            {
                                if (!t.PrivateProperties.Contains(str))
                                {
                                    data.Add(new PropertyCompletionData(t.Properties[str], str,
                                        t.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                        (t.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                                }
                            }
                        }
                    }
                    foreach (FunctionInfo fi in ti.Functions)
                        data.Add(new FunctionCompletionData(fi));
                    foreach (TypeInfo t in ti.BaseTypes)
                    {
                        foreach (FunctionInfo fi in t.Functions)
                        {
                            if (!fi.IsPrivate)
                                data.Add(new FunctionCompletionData(fi));
                        }
                    }
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
            }
            else if (KEY == '(' && IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs - 2, line - 1))
            {

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info = null;
                FunctionInfo func = null;
                string[] words = IntellisenseHelper.DotPath(editor.Document, curOfs - 2, line - 1);
                if (words.Length > 1)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (i == words.Length - 1 && info != null)
                        {
                            if (info is TypeInfo)
                                func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                        }
                        else
                        {
                            if (info == null)
                            {
                                info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            }
                            else if (info != null && info is TypeInfo)
                            {
                                if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                    info = ((TypeInfo)info).Properties[words[i]];
                            }
                        }
                    }
                }
                if (func != null && info != null)
                {
                    List<FunctionInfo> data = new List<FunctionInfo>();
                    if (info is TypeInfo)
                    {
                        TypeInfo ti = (TypeInfo)info;
                        foreach (FunctionInfo fi in ti.Functions.Where(f => { return f.Name.Equals(func.Name); }))
                            data.Add(fi);
                        if (data.Count > 0)
                        {
                            OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                            window.Provider = new OverloadProvider(ti, data.ToArray());
                            window.Show();
                            //compWindow.Closed += comp_Closed;
                        }
                    }
                }
                else if (func == null && info == null) // Found nothing
                {
                    List<FunctionInfo> data = new List<FunctionInfo>();
                    foreach (FunctionInfo fi in GetGlobals().GetFunctions(words[0], true))
                        data.Add(fi);
                    if (data.Count > 0)
                    {
                        OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                        window.Provider = new OverloadProvider(null, data.ToArray());
                        window.Show();
                        //compWindow.Closed += comp_Closed;
                    }
                }
            }
            else if (Char.IsLetter(KEY))
            {
                if (currentComp != null || editor.TextArea.Caret.Line == 1)
                    return;

                int ofs = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                int nextOfs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                if (nextOfs > 0)
                {
                    if (editor.Document.Text[nextOfs] == '.')
                        return;
                }
                string word = "";
                if (ofs < 0)
                    return;
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                        word += editor.Document.Text[ofs];
                }
                if (word.Contains("."))
                {
                    if (currentComp != null)
                        currentComp.Close();
                    //editor_KeyUp(sender, e);
                    return;
                }

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                List<string> suggestions = new List<string>();
                reso.GetNameMatch(editor.Document, editor.TextArea.Caret.Line - 2, word, ref suggestions);

                CompletionWindow compWindow = new CompletionWindow(editor.TextArea);
                compWindow.StartOffset = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                IList<ICompletionData> data = compWindow.CompletionList.CompletionData;
                //attempt local name resolution first
                if (suggestions.Count > 0)
                {
                    foreach (string str in suggestions) //text suggestions are of lower priority
                        data.Add(new BaseCompletionData(null, str) { Priority = 0.5 });
                }
                //Scan globals
                if (GetGlobals() != null)
                {
                    foreach (string str in GetGlobals().GetTypeInfoNames())
                    {
                        if (str.StartsWith(word))
                            data.Add(new ClassCompletionData(GetGlobals().GetTypeInfo(str)));
                    }
                    foreach (FunctionInfo fun in GetGlobals().GetFunctions(null, true))
                    {
                        if (fun.Name.StartsWith(word))
                            data.Add(new FunctionCompletionData(fun));
                    }
                }
                if (data.Count > 0)
                {
                    currentComp = compWindow;
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
                else if (currentComp != null)
                {
                    currentComp.Close();
                }
            }
        }
        protected void ParseNamespace(StringReader rdr, Globals globals, DepthScanner scanner, ref int currentLine, bool asNamespace)
        {
            string l = "";
            int depth = scanner.GetBraceDepth(currentLine);
            bool hitDeeper = false;
            while ((l = rdr.ReadLine()) != null)
            {
                string defName = "";
                int lineNumber = 0;
                ExtractLineInfo(ref l, out defName, out lineNumber);

                ++currentLine;
                if (l.Trim().StartsWith("//"))
                    continue;
                if (l.Trim().StartsWith("#"))
                    continue;
                int curDepth = scanner.GetBraceDepth(currentLine-1);
                if (!asNamespace)
                {
                    if (curDepth < depth) // Left our namespace depth
                        return;
                    else if (curDepth > depth) // Outside of the desired scanning depth (namespace level)
                        continue;
                }
                else
                {
                    if (curDepth > depth)
                        hitDeeper = true;
                    if (curDepth == depth && hitDeeper)
                        return;
                    else if (curDepth > depth + 1) //We do not go deeper than the namespace
                        continue;
                }

                string line = l.Trim();
                if (line.Length == 0)
                    continue;
                string[] tokens = line.Split(BREAKCHARS);

                // Class / Interface/ Template type
                if (ResemblesClass(line))
                {
                    int abstractIdx = Array.IndexOf(tokens, "abstract");
                    int sharedIdx = Array.IndexOf(tokens, "shared");
                    int templateIdx = Array.IndexOf(tokens, "template");
                    int mixinIdx = Array.IndexOf(tokens, "mixin");
                    int finalIdx = Array.IndexOf(tokens, "final");

                    int classTermIdx = Math.Max(abstractIdx, Math.Max(sharedIdx, Math.Max(templateIdx, Math.Max(mixinIdx, finalIdx)))) + 1;

                    bool isInterface = tokens[classTermIdx].Equals("interface");
                    if (templateIdx != -1)
                    {
                        //Resolve template type?
                    }

                    string className = tokens[classTermIdx + 1];
                    TypeInfo ti = new TypeInfo { Name = className,
                        IsTemplate = templateIdx != -1, IsShared = sharedIdx != -1,
                        IsAbstract = abstractIdx != -1, IsMixin = mixinIdx != -1,
                        IsInterface = isInterface,
                        SourceLine = lineNumber, SourceFile = defName };

                    // Get any baseclasses, baseclass must appear first
                    for (int i = classTermIdx + 2; i < tokens.Length; ++i)
                    {
                        string baseName = tokens[i];
                        if (globals.ContainsTypeInfo(baseName.Replace(",","")))
                            ti.BaseTypes.Add(globals.GetTypeInfo(baseName.Replace(",","")));
                    }
                    ParseClass(rdr, globals, scanner, ti, ref currentLine);
                    globals.AddTypeInfo(className, ti);
                }
                else if (tokens[0].ToLower().Equals("namespace")) // Namespace
                {
                    string nsName = tokens[1];
                    Globals namespaceGlobals = null;
                    if (globals.ContainsNamespace(nsName)) // Check if the namespace has been encountered before
                        namespaceGlobals = globals.GetNamespace(nsName);
                    else
                        namespaceGlobals = new Globals(false);
                    namespaceGlobals.Parent = globals;
                    ParseNamespace(rdr, namespaceGlobals, scanner, ref currentLine, true);
                    namespaceGlobals.Name = nsName;
                    globals.AddNamespace(nsName, namespaceGlobals);
                }
                else if (tokens[0].ToLower().Equals("enum")) // Enumeration
                {
                    ParseEnum(line, rdr, globals, ref currentLine);
                }
                else
                {
                    if (ResemblesFunction(line)) // Global/namespace function
                    {
                        try
                        {
                            FunctionInfo fi = _parseFunction(rdr, line, globals, lineNumber, defName);
                            if (fi != null)
                                globals.AddFunction(fi);
                        }
                        catch (Exception ex) { }
                    }
                    else if (ResemblesProperty(line, globals)) // Global/namespace property
                    {
                        string[] parts = l.Replace(";", "").Split(BREAKCHARS);

                        // Globals can't be private/protected
                        int constIdx = Array.IndexOf(parts, "const");
                        int uniformIdx = Array.IndexOf(parts, "uniform");
                        int termIdx = Math.Max(constIdx, uniformIdx) + 1;

                        if (parts[termIdx].Contains('<'))
                        {
                            string templateType = parts[termIdx].Substring(0, parts[termIdx].IndexOf('<'));
                            string containedType = parts[termIdx].Extract('<', '>');
                            TypeInfo wrapped = globals.GetTypeInfo(containedType);
                            TemplateInst ti = new TemplateInst() { Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = containedType, IsComplete = false, SourceLine = lineNumber, SourceFile = defName } };
                            globals.AddProperty(parts[termIdx + 1], ti, lineNumber, defName);
                            //if (constIdx != -1)
                            //    globals.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                        else
                        {
                            string pname = parts[termIdx].EndsWith("@") ? parts[termIdx].Substring(0, parts[termIdx].Length - 1) : parts[termIdx]; //handle
                            if (pname.Length == 0)
                                continue;
                            TypeInfo pType = null;
                            if (globals.ContainsTypeInfo(pname))
                                pType = globals.GetTypeInfo(pname);
                            if (pType == null)
                            { //create temp type to resolve later
                                pType = new TypeInfo() { Name = pname, IsComplete = false, SourceLine = lineNumber, SourceFile = defName };
                            }
                            globals.AddProperty(parts[termIdx + 1], pType, lineNumber, defName);
                            //if (constIdx != -1)
                            //    globals.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                    }
                }
            }
        }
        protected void ParseClass(StringReader rdr, Globals targetGlobals, DepthScanner scanner, TypeInfo targetType, ref int currentLine)
        {
            int depth = scanner.GetBraceDepth(currentLine);
            string l = "";
            bool hitDeeper = false;
            while ((l = rdr.ReadLine()) != null)
            {
                string defName = "";
                int lineNumber = 0;
                ExtractLineInfo(ref l, out defName, out lineNumber);
                l = l.Trim();

                ++currentLine;
                int curDepth = scanner.GetBraceDepth(currentLine-1);
                if (curDepth > depth)
                    hitDeeper = true;
                if (curDepth == depth && hitDeeper)
                    return;
                else if (curDepth > depth + 1) //We do not go deeper than class
                    continue;
                if (ResemblesFunction(l))
                {
                    FunctionInfo fi = _parseFunction(rdr, l, targetGlobals, lineNumber, defName);
                    if (fi != null)
                        targetType.Functions.Add(fi);
                }
                else if (ResemblesProperty(l, targetGlobals))
                {
                    string[] tokens = l.Replace(";","").Split(BREAKCHARS);

                    int constIdx = Array.IndexOf(tokens, "const");
                    int privateIdx = Array.IndexOf(tokens, "private");
                    int protectedIdx = Array.IndexOf(tokens, "protected");

                    int termIdx = Math.Max(constIdx, Math.Max(privateIdx, protectedIdx)) + 1;

                    if (tokens[termIdx].Contains('<'))
                    {
                        string templateType = tokens[termIdx].Substring(0, tokens[termIdx].IndexOf('<'));
                        string containedType = tokens[termIdx].Extract('<', '>');
                        TypeInfo wrapped = targetGlobals.GetTypeInfo(containedType);
                        TemplateInst ti = new TemplateInst() { Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo { Name = containedType, IsComplete = false, SourceLine = lineNumber, SourceFile = defName } };
                        targetType.Properties[tokens[termIdx+1]] = ti;
                        targetType.PropertyLines[tokens[termIdx + 1]] = lineNumber;
                        if (constIdx != -1)
                            targetType.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        if (protectedIdx != -1)
                            targetType.ProtectedProperties.Add(tokens[termIdx + 1]);
                        else if (privateIdx != -1)
                            targetType.PrivateProperties.Add(tokens[termIdx + 1]);
                    }
                    else
                    {
                        string pname = tokens[termIdx].EndsWith("@") ? tokens[termIdx].Substring(0, tokens[termIdx].Length - 1) : tokens[termIdx]; //handle
                        TypeInfo pType = null;
                        if (targetGlobals.ContainsTypeInfo(pname))
                            pType = targetGlobals.GetTypeInfo(pname);
                        if (pType == null)
                        { //create temp type to resolve later
                            pType = new TypeInfo() { Name = pname, IsComplete = false, SourceLine = lineNumber, SourceFile = defName };
                        }
                        targetType.Properties[tokens[termIdx + 1]] = pType;
                        targetType.PropertyLines[tokens[termIdx + 1]] = lineNumber;
                        if (constIdx != -1)
                            targetType.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        if (protectedIdx != -1)
                            targetType.ProtectedProperties.Add(tokens[termIdx + 1]);
                        else if (privateIdx != -1)
                            targetType.PrivateProperties.Add(tokens[termIdx + 1]);
                    }
                }
            }
        }
        protected void ParseNamespace(StringReader rdr, Globals globals, DepthScanner scanner, ref int currentLine, bool asNamespace)
        {
            string l         = "";
            int    depth     = scanner.GetBraceDepth(currentLine);
            bool   hitDeeper = false;

            while ((l = rdr.ReadLine()) != null)
            {
                string defName    = "";
                int    lineNumber = 0;
                ExtractLineInfo(ref l, out defName, out lineNumber);

                ++currentLine;
                if (l.Trim().StartsWith("//"))
                {
                    continue;
                }
                if (l.Trim().StartsWith("#"))
                {
                    continue;
                }
                int curDepth = scanner.GetBraceDepth(currentLine - 1);
                if (!asNamespace)
                {
                    if (curDepth < depth) // Left our namespace depth
                    {
                        return;
                    }
                    else if (curDepth > depth) // Outside of the desired scanning depth (namespace level)
                    {
                        continue;
                    }
                }
                else
                {
                    if (curDepth > depth)
                    {
                        hitDeeper = true;
                    }
                    if (curDepth == depth && hitDeeper)
                    {
                        return;
                    }
                    else if (curDepth > depth + 1) //We do not go deeper than the namespace
                    {
                        continue;
                    }
                }

                string line = l.Trim();
                if (line.Length == 0)
                {
                    continue;
                }
                string[] tokens = line.Split(BREAKCHARS);

                // Class / Interface/ Template type
                if (ResemblesClass(line))
                {
                    int abstractIdx = Array.IndexOf(tokens, "abstract");
                    int sharedIdx   = Array.IndexOf(tokens, "shared");
                    int templateIdx = Array.IndexOf(tokens, "template");
                    int mixinIdx    = Array.IndexOf(tokens, "mixin");
                    int finalIdx    = Array.IndexOf(tokens, "final");

                    int classTermIdx = Math.Max(abstractIdx, Math.Max(sharedIdx, Math.Max(templateIdx, Math.Max(mixinIdx, finalIdx)))) + 1;

                    bool isInterface = tokens[classTermIdx].Equals("interface");
                    if (templateIdx != -1)
                    {
                        //Resolve template type?
                    }

                    string   className = tokens[classTermIdx + 1];
                    TypeInfo ti        = new TypeInfo {
                        Name        = className,
                        IsTemplate  = templateIdx != -1, IsShared = sharedIdx != -1,
                        IsAbstract  = abstractIdx != -1, IsMixin = mixinIdx != -1,
                        IsInterface = isInterface,
                        SourceLine  = lineNumber, SourceFile = defName
                    };

                    // Get any baseclasses, baseclass must appear first
                    for (int i = classTermIdx + 2; i < tokens.Length; ++i)
                    {
                        string baseName = tokens[i];
                        if (globals.ContainsTypeInfo(baseName.Replace(",", "")))
                        {
                            ti.BaseTypes.Add(globals.GetTypeInfo(baseName.Replace(",", "")));
                        }
                    }
                    ParseClass(rdr, globals, scanner, ti, ref currentLine);
                    globals.AddTypeInfo(className, ti);
                }
                else if (tokens[0].ToLower().Equals("namespace")) // Namespace
                {
                    string  nsName           = tokens[1];
                    Globals namespaceGlobals = null;
                    if (globals.ContainsNamespace(nsName)) // Check if the namespace has been encountered before
                    {
                        namespaceGlobals = globals.GetNamespace(nsName);
                    }
                    else
                    {
                        namespaceGlobals = new Globals(false);
                    }
                    namespaceGlobals.Parent = globals;
                    ParseNamespace(rdr, namespaceGlobals, scanner, ref currentLine, true);
                    namespaceGlobals.Name = nsName;
                    globals.AddNamespace(nsName, namespaceGlobals);
                }
                else if (tokens[0].ToLower().Equals("enum")) // Enumeration
                {
                    ParseEnum(line, rdr, globals, ref currentLine);
                }
                else
                {
                    if (ResemblesFunction(line)) // Global/namespace function
                    {
                        try
                        {
                            FunctionInfo fi = _parseFunction(rdr, line, globals, lineNumber, defName);
                            if (fi != null)
                            {
                                globals.AddFunction(fi);
                            }
                        }
                        catch (Exception ex) { }
                    }
                    else if (ResemblesProperty(line, globals)) // Global/namespace property
                    {
                        string[] parts = l.Replace(";", "").Split(BREAKCHARS);

                        // Globals can't be private/protected
                        int constIdx   = Array.IndexOf(parts, "const");
                        int uniformIdx = Array.IndexOf(parts, "uniform");
                        int termIdx    = Math.Max(constIdx, uniformIdx) + 1;

                        if (parts[termIdx].Contains('<'))
                        {
                            string       templateType  = parts[termIdx].Substring(0, parts[termIdx].IndexOf('<'));
                            string       containedType = parts[termIdx].Extract('<', '>');
                            TypeInfo     wrapped       = globals.GetTypeInfo(containedType);
                            TemplateInst ti            = new TemplateInst()
                            {
                                Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo {
                                    Name = containedType, IsComplete = false, SourceLine = lineNumber, SourceFile = defName
                                }
                            };
                            globals.AddProperty(parts[termIdx + 1], ti, lineNumber, defName);
                            //if (constIdx != -1)
                            //    globals.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                        else
                        {
                            string pname = parts[termIdx].EndsWith("@") ? parts[termIdx].Substring(0, parts[termIdx].Length - 1) : parts[termIdx]; //handle
                            if (pname.Length == 0)
                            {
                                continue;
                            }
                            TypeInfo pType = null;
                            if (globals.ContainsTypeInfo(pname))
                            {
                                pType = globals.GetTypeInfo(pname);
                            }
                            if (pType == null)
                            { //create temp type to resolve later
                                pType = new TypeInfo()
                                {
                                    Name = pname, IsComplete = false, SourceLine = lineNumber, SourceFile = defName
                                };
                            }
                            globals.AddProperty(parts[termIdx + 1], pType, lineNumber, defName);
                            //if (constIdx != -1)
                            //    globals.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                    }
                }
            }
        }
Example #15
0
 public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner depthScanner, System.Windows.Input.MouseEventArgs e)
 {
     // Do nothing
 }
 public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner depthScanner, System.Windows.Input.MouseEventArgs e)
 {
     throw new NotImplementedException();
 }
 public void EditorKeyUp(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner depthScanner, System.Windows.Input.KeyEventArgs e)
 {
 }
 public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner depthScanner, System.Windows.Input.MouseEventArgs e)
 {
 }
        public void EditorKeyUp(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, System.Windows.Input.KeyEventArgs e)
        {
            Globals g = GetGlobals();

            if (g == null)
            {
                return;
            }
            // These keys halt and terminate intellisense
            switch (e.Key)
            {
            case Key.Home:
            case Key.End:
            case Key.Left:
            case Key.Right:
            case Key.Escape:
            case Key.LWin:
            case Key.RWin:
            case Key.Space:
                if (currentComp != null)
                {
                    currentComp.Close();
                }
                return;
            }
            // These keys halt further checks
            switch (e.Key)
            {
            case Key.Up:
            case Key.Down:
            case Key.PageDown:
            case Key.PageUp:
            case Key.LeftShift:
            case Key.RightShift:
            case Key.LeftAlt:
            case Key.RightAlt:
            case Key.LeftCtrl:
            case Key.RightCtrl:
            case Key.Scroll:
            case Key.Capital:
            case Key.CrSel:
            case Key.Clear:
            case Key.Insert:
            case Key.PrintScreen:
            case Key.Print:
                return;
            }

            char KEY = KeyHelpers.GetCharFromKey(e.Key);

            if (KEY == ')' || KEY == ';')
            {
                if (currentComp != null)
                {
                    currentComp.Close();
                }
                return;
            }
            int curOfs = editor.TextArea.Caret.Offset;
            int line   = editor.TextArea.Caret.Line;

            // Do not attempt intellisense inside of comments
            string txt = editor.Document.GetText(editor.Document.Lines[editor.TextArea.Caret.Line - 1]);

            if (txt.Trim().StartsWith("//"))
            {
                return;
            }

            if (e.Key == Key.OemPeriod || KEY == ':')
            {
                //IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs-1, line-1)) {
                int ofs = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                ofs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                string word = "";
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                    {
                        word += editor.Document.Text[ofs];
                    }
                }

                NameResolver reso  = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info  = null;
                string[]     words = IntellisenseHelper.DotPath(editor.Document, curOfs - 1, line - 1);
                if (words.Length > 0)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (info == null)
                        {
                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            if (info == null && GetGlobals().ContainsProperty(words[i]))
                            {
                                info = GetGlobals().GetProperty(words[i], true);
                            }
                        }
                        else if (info != null)
                        {
                            info = info.ResolvePropertyPath(GetGlobals(), words[i]);
                        }
                    }
                }

                bool functionsOnly = false;
                //attempt to resolve it locally
                if (info == null)
                {
                    info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, word);
                }
                //attempt to resolve it from globals
                if (info == null && GetGlobals() != null && GetGlobals().ContainsProperty(word))
                {
                    info = GetGlobals().GetProperty(word, true);
                }
                if (info == null && word.Contains("::"))
                {
                    if (GetGlobals() == null)
                    {
                        return;
                    }
                    if (word.Length > 2)
                    {
                        string ns = word.Replace("::", "");
                        if (GetGlobals().ContainsTypeInfo(ns))
                        {
                            EnumInfo ti = GetGlobals().GetTypeInfo(word.Replace("::", "")) as EnumInfo;
                            if (ti != null)
                            {
                                currentComp = new CompletionWindow(editor.TextArea);
                                IList <ICompletionData> data = currentComp.CompletionList.CompletionData;
                                foreach (string str in ti.Values)
                                {
                                    data.Add(new BaseCompletionData(null, str));
                                }
                                currentComp.Show();
                                currentComp.Closed += comp_Closed;
                                return;
                            }
                            else
                            {
                                TypeInfo ty = GetGlobals().GetTypeInfo(word.Replace("::", ""));
                                if (ty != null)
                                {
                                    info          = ty;
                                    functionsOnly = true;
                                }
                            }
                        }
                        else
                        { //list global functions
                            Globals globs = GetGlobals();
                            bool    asNS  = false;
                            if (globs.ContainsNamespace(ns))
                            {
                                asNS  = true;
                                globs = globs.GetNamespace(ns);
                            }
                            currentComp = new CompletionWindow(editor.TextArea);
                            IList <ICompletionData> data = currentComp.CompletionList.CompletionData;
                            foreach (string str in globs.GetPropertyNames())
                            {
                                TypeInfo ti = globs.GetProperty(str, !asNS) as TypeInfo;
                                if (ti != null)
                                {
                                    data.Add(new PropertyCompletionData(ti, str));
                                }
                            }
                            foreach (FunctionInfo fi in globs.GetFunctions(null, false))
                            {
                                data.Add(new FunctionCompletionData(fi));
                            }
                            if (asNS) //Include classes
                            {
                                foreach (TypeInfo ti in globs.TypeInfo)
                                {
                                    data.Add(new ClassCompletionData(ti));
                                }
                            }
                            currentComp.Show();
                            currentComp.Closed += comp_Closed;
                            return;
                        }
                    }
                }

                //build the list
                if (info != null && info is TypeInfo)
                {
                    TypeInfo ti = info as TypeInfo;
                    currentComp = new CompletionWindow(editor.TextArea);
                    IList <ICompletionData> data = currentComp.CompletionList.CompletionData;
                    if (!functionsOnly)
                    {
                        foreach (string str in ti.Properties.Keys)
                        {
                            data.Add(new PropertyCompletionData(ti.Properties[str], str,
                                                                ti.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                                                (ti.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                        }
                        foreach (TypeInfo t in ti.BaseTypes)
                        {
                            foreach (string str in t.Properties.Keys)
                            {
                                if (!t.PrivateProperties.Contains(str))
                                {
                                    data.Add(new PropertyCompletionData(t.Properties[str], str,
                                                                        t.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                                                        (t.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                                }
                            }
                        }
                    }
                    foreach (FunctionInfo fi in ti.Functions)
                    {
                        data.Add(new FunctionCompletionData(fi));
                    }
                    foreach (TypeInfo t in ti.BaseTypes)
                    {
                        foreach (FunctionInfo fi in t.Functions)
                        {
                            if (!fi.IsPrivate)
                            {
                                data.Add(new FunctionCompletionData(fi));
                            }
                        }
                    }
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
            }
            else if (KEY == '(' && IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs - 2, line - 1))
            {
                NameResolver reso  = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info  = null;
                FunctionInfo func  = null;
                string[]     words = IntellisenseHelper.DotPath(editor.Document, curOfs - 2, line - 1);
                if (words.Length > 1)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (i == words.Length - 1 && info != null)
                        {
                            if (info is TypeInfo)
                            {
                                func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                            }
                        }
                        else
                        {
                            if (info == null)
                            {
                                info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            }
                            else if (info != null && info is TypeInfo)
                            {
                                if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                {
                                    info = ((TypeInfo)info).Properties[words[i]];
                                }
                            }
                        }
                    }
                }
                if (func != null && info != null)
                {
                    List <FunctionInfo> data = new List <FunctionInfo>();
                    if (info is TypeInfo)
                    {
                        TypeInfo ti = (TypeInfo)info;
                        foreach (FunctionInfo fi in ti.Functions.Where(f => { return(f.Name.Equals(func.Name)); }))
                        {
                            data.Add(fi);
                        }
                        if (data.Count > 0)
                        {
                            OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                            window.Provider = new OverloadProvider(ti, data.ToArray());
                            window.Show();
                            //compWindow.Closed += comp_Closed;
                        }
                    }
                }
                else if (func == null && info == null) // Found nothing
                {
                    List <FunctionInfo> data = new List <FunctionInfo>();
                    foreach (FunctionInfo fi in GetGlobals().GetFunctions(words[0], true))
                    {
                        data.Add(fi);
                    }
                    if (data.Count > 0)
                    {
                        OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                        window.Provider = new OverloadProvider(null, data.ToArray());
                        window.Show();
                        //compWindow.Closed += comp_Closed;
                    }
                }
            }
            else if (Char.IsLetter(KEY))
            {
                if (currentComp != null || editor.TextArea.Caret.Line == 1)
                {
                    return;
                }

                int ofs     = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                int nextOfs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                if (nextOfs > 0)
                {
                    if (editor.Document.Text[nextOfs] == '.')
                    {
                        return;
                    }
                }
                string word = "";
                if (ofs < 0)
                {
                    return;
                }
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                    {
                        word += editor.Document.Text[ofs];
                    }
                }
                if (word.Contains("."))
                {
                    if (currentComp != null)
                    {
                        currentComp.Close();
                    }
                    //editor_KeyUp(sender, e);
                    return;
                }

                NameResolver  reso        = new NameResolver(GetGlobals(), scanner);
                List <string> suggestions = new List <string>();
                reso.GetNameMatch(editor.Document, editor.TextArea.Caret.Line - 2, word, ref suggestions);

                CompletionWindow compWindow = new CompletionWindow(editor.TextArea);
                compWindow.StartOffset = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                IList <ICompletionData> data = compWindow.CompletionList.CompletionData;
                //attempt local name resolution first
                if (suggestions.Count > 0)
                {
                    foreach (string str in suggestions) //text suggestions are of lower priority
                    {
                        data.Add(new BaseCompletionData(null, str)
                        {
                            Priority = 0.5
                        });
                    }
                }
                //Scan globals
                if (GetGlobals() != null)
                {
                    foreach (string str in GetGlobals().GetTypeInfoNames())
                    {
                        if (str.StartsWith(word))
                        {
                            data.Add(new ClassCompletionData(GetGlobals().GetTypeInfo(str)));
                        }
                    }
                    foreach (FunctionInfo fun in GetGlobals().GetFunctions(null, true))
                    {
                        if (fun.Name.StartsWith(word))
                        {
                            data.Add(new FunctionCompletionData(fun));
                        }
                    }
                }
                if (data.Count > 0)
                {
                    currentComp = compWindow;
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
                else if (currentComp != null)
                {
                    currentComp.Close();
                }
            }
        }
Example #20
0
        public IDEEditor(FileBaseItem aItem)
        {
            InitializeComponent();
            item          = aItem;
            changeChecker = new DataChanged {
                editor = editor
            };
            SetCode(aItem);
            editor.ShowLineNumbers = true;

            editor.Options.ConvertTabsToSpaces = true;
            editor.Options.IndentationSize     = 4;

            editor.FontFamily = new FontFamily("Consolas");
            editor.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDCDCCC"));
            editor.TextArea.TextView.BackgroundRenderers.Add(new LineHighlighter());
            editor.TextArea.TextView.BackgroundRenderers.Add(new ErrorLineHighlighter(aItem));
            // Buggy
            //editor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();
            Debugger.Editor.SearchPanel.Install(editor);
            editor.TextChanged += editor_TextChanged;
            scanner             = new DepthScanner();
            scanner.Process(editor.Text);
            editor.MouseHover          += editor_MouseHover;
            editor.TextArea.MouseWheel += editor_MouseWheel;
            editor.KeyUp   += editor_KeyUp;
            editor.MouseUp += editor_MouseUp;
            codeFolding     = new BraceFoldingStrategy();

            if (FOLDED_EXTENSIONS.Contains(System.IO.Path.GetExtension(aItem.Path)))
            {
                foldingManager = FoldingManager.Install(editor.TextArea);
                UpdateFoldings();
            }

            intelSource        = Intellisense.Sources.SourceBuilder.GetSourceForExtension(System.IO.Path.GetExtension(item.Path));
            editor.ContextMenu = new ContextMenu();

            // Hook the source, so we can get context menu commands from it
            if (intelSource != null)
            {
                intelSource.HookEditor(editor, item);
            }

            editor.ContextMenu.Items.Add(new MenuItem
            {
                Header  = "Snippet",
                Command = new RelayCommand(p =>
                {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string ext = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(ext))
                        {
                            snips.Add(snip);
                        }
                    }
                    if (snips.Count > 0)
                    {
                        Snippets.SnippetDlg dlg = new Snippets.SnippetDlg(editor, snips);
                        dlg.ShowDialog();
                    }
                }, sp =>
                {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string exte = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(exte))
                        {
                            return(true);
                        }
                    }
                    return(false);
                })
            });

            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Cut",
                Command = ApplicationCommands.Cut
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Copy",
                Command = ApplicationCommands.Copy
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Paste",
                Command = ApplicationCommands.Paste
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Undo",
                Command = ApplicationCommands.Undo
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Redo",
                Command = ApplicationCommands.Redo
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save",
                Command = ApplicationCommands.Save
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save As",
                Command = ApplicationCommands.SaveAs
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Open",
                Command = ApplicationCommands.Open
            });
        }
        protected void ParseClass(StringReader rdr, Globals targetGlobals, DepthScanner scanner, TypeInfo targetType, ref int currentLine)
        {
            int    depth     = scanner.GetBraceDepth(currentLine);
            string l         = "";
            bool   hitDeeper = false;

            while ((l = rdr.ReadLine()) != null)
            {
                string defName    = "";
                int    lineNumber = 0;
                ExtractLineInfo(ref l, out defName, out lineNumber);
                l = l.Trim();

                ++currentLine;
                int curDepth = scanner.GetBraceDepth(currentLine - 1);
                if (curDepth > depth)
                {
                    hitDeeper = true;
                }
                if (curDepth == depth && hitDeeper)
                {
                    return;
                }
                else if (curDepth > depth + 1) //We do not go deeper than class
                {
                    continue;
                }
                if (ResemblesFunction(l))
                {
                    FunctionInfo fi = _parseFunction(rdr, l, targetGlobals, lineNumber, defName);
                    if (fi != null)
                    {
                        targetType.Functions.Add(fi);
                    }
                }
                else if (ResemblesProperty(l, targetGlobals))
                {
                    string[] tokens = l.Replace(";", "").Split(BREAKCHARS);

                    int constIdx     = Array.IndexOf(tokens, "const");
                    int privateIdx   = Array.IndexOf(tokens, "private");
                    int protectedIdx = Array.IndexOf(tokens, "protected");

                    int termIdx = Math.Max(constIdx, Math.Max(privateIdx, protectedIdx)) + 1;

                    if (tokens[termIdx].Contains('<'))
                    {
                        string       templateType  = tokens[termIdx].Substring(0, tokens[termIdx].IndexOf('<'));
                        string       containedType = tokens[termIdx].Extract('<', '>');
                        TypeInfo     wrapped       = targetGlobals.GetTypeInfo(containedType);
                        TemplateInst ti            = new TemplateInst()
                        {
                            Name = templateType, IsTemplate = true, WrappedType = wrapped != null ? wrapped : new TypeInfo {
                                Name = containedType, IsComplete = false, SourceLine = lineNumber, SourceFile = defName
                            }
                        };
                        targetType.Properties[tokens[termIdx + 1]]    = ti;
                        targetType.PropertyLines[tokens[termIdx + 1]] = lineNumber;
                        if (constIdx != -1)
                        {
                            targetType.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                        if (protectedIdx != -1)
                        {
                            targetType.ProtectedProperties.Add(tokens[termIdx + 1]);
                        }
                        else if (privateIdx != -1)
                        {
                            targetType.PrivateProperties.Add(tokens[termIdx + 1]);
                        }
                    }
                    else
                    {
                        string   pname = tokens[termIdx].EndsWith("@") ? tokens[termIdx].Substring(0, tokens[termIdx].Length - 1) : tokens[termIdx]; //handle
                        TypeInfo pType = null;
                        if (targetGlobals.ContainsTypeInfo(pname))
                        {
                            pType = targetGlobals.GetTypeInfo(pname);
                        }
                        if (pType == null)
                        { //create temp type to resolve later
                            pType = new TypeInfo()
                            {
                                Name = pname, IsComplete = false, SourceLine = lineNumber, SourceFile = defName
                            };
                        }
                        targetType.Properties[tokens[termIdx + 1]]    = pType;
                        targetType.PropertyLines[tokens[termIdx + 1]] = lineNumber;
                        if (constIdx != -1)
                        {
                            targetType.ReadonlyProperties.Add(tokens[termIdx + 1]);
                        }
                        if (protectedIdx != -1)
                        {
                            targetType.ProtectedProperties.Add(tokens[termIdx + 1]);
                        }
                        else if (privateIdx != -1)
                        {
                            targetType.PrivateProperties.Add(tokens[termIdx + 1]);
                        }
                    }
                }
            }
        }