Ejemplo n.º 1
0
 private void AddDocument(CodeDocument codeDoc)
 {
     if (codeDoc != null && codeDoc.Features.Set(CodeEditorFeatures.Outline))
     {
         var tn = control.AddDocumentNode(codeDoc);
         var sci = (ScintillaControl)App.Editor(codeDoc.GetType()).Control;
         sci.TextChanged += (o,e) => DocumentChanged();
         codeDoc.FileChanged += (o,e) => ChangeNodeText(codeDoc, tn);
     }
 }
Ejemplo n.º 2
0
 public TreeNode AddDocumentNode(CodeDocument doc)
 {
     var tn = new TreeNode(doc.FileInfo != null ? doc.FileInfo.ShortName() : new FileInfo(doc.Title).ShortName());
     tn.ImageKey = "Module";
     tn.SelectedImageKey = "Module";
     tn.Tag = doc;
     AddDocumentNodes(tn);
     treeView.Nodes.Add(tn);
     return tn;
 }
Ejemplo n.º 3
0
        public void CollapseNode(CodeDocument doc)
        {
            var node = treeView.Nodes.OfType<TreeNode>().FirstOrDefault(tn => tn.Tag == doc);

            if (node != null)
            {
                if (node.IsExpanded)
                {
                    node.Nodes.Clear();
                    AddDocumentNodes(node);
                }
            }
        }
Ejemplo n.º 4
0
        public void ClearOutline(CodeDocument doc)
        {
            var ed = App.Editor();

            if (ed != null && doc.Messages != null)
            {
                var sci = ed.Control as ScintillaControl;

                if (sci != null)
                {
                    sci.ClearIndicator(sci.Indicators.Error);
                    sci.ClearIndicator(sci.Indicators.Warning);
                }
            }
        }
Ejemplo n.º 5
0
        public void Outline(CodeDocument doc)
        {
            var ed = App.Editor();

            if (ed != null && doc.Messages != null)
            {
                var sci = ed.Control as ScintillaControl;

                if (sci != null)
                {
                    if (!scis.ContainsKey(sci))
                    {
                        sci.Indicators.Error.Style = IndicatorStyle.Squiggle;
                        sci.Indicators.Error.ForeColor = Color.Red;
                        sci.Indicators.Warning.Style = IndicatorStyle.Squiggle;
                        sci.Indicators.Warning.ForeColor = Color.Blue;
                        sci.MouseDwell += MouseDwell;
                        scis.Add(sci, null);
                    }

                    sci.ClearIndicator(sci.Indicators.Error);
                    sci.ClearIndicator(sci.Indicators.Warning);

                    doc.Messages.ForEachIndex((m,i) =>
                        {
                            var ln = m.Line - 1;
                            var col = m.Column - 1;

                            var indic = m.Type == MessageItemType.Error ? sci.Indicators.Error : sci.Indicators.Warning;
                            var sp = sci.GetPositionByColumn(ln, col);
                            var word = sci.GetWordAt(sp);
                            var len = word == null ? 3 : word.Length;

                            if (len < 3 && col > 1)
                            {
                                sp -= m.Column;
                                len += m.Column;
                            }

                            sci.SetIndicator(indic, i + 1, sp, len);
                        });
                }
            }
        }
Ejemplo n.º 6
0
        private void AddDocument(CodeDocument codeDoc)
        {
            if (codeDoc != null && codeDoc.Features.Set(CodeEditorFeatures.Tasks))
            {
                var editor = app.Editor(codeDoc.GetType());
                var sci = editor.Control as ScintillaControl;

                if (sci != null)
                {
                    var node = new TreeNode();
                    codeDoc.FileChanged += (o,ev) => ChangeNodeText(node);
                    node.ImageKey = node.SelectedImageKey = "Folder";
                    node.Tag = codeDoc;
                    node.Nodes.Add(new TreeNode { Tag = stub });
                    ChangeNodeText(node);
                    nodeMap.Add(codeDoc, node);
                    treeView.Nodes.Add(node);

                    if (!sciMap.ContainsKey(sci))
                        sci.TextChanged += (o, ev) => ContentChanged();
                }
            }
        }
Ejemplo n.º 7
0
        public Tuple<ICompiledUnit, IEnumerable<MessageItem>> Compile(CodeDocument doc, string source)
        {
            var par = new ElaParser();
            var parRes = par.Parse(source);
            var msg = new List<MessageItem>();
            var unit = doc.Unit;
            Func<ElaMessage,MessageItem> project = m => new MessageItem(
                m.Type == MessageType.Error ? MessageItemType.Error : MessageItemType.Warning, m.Message, doc, m.Line, m.Column);

            if (parRes.Success)
            {
                var copt = new CompilerOptions();

                copt.ShowHints = false;
                copt.GenerateDebugInfo = true;
                copt.IgnoreUndefined = true;

                //TODO: hack, should be taken from options
                copt.Prelude = "prelude";
                var comp = new ElaCompiler();

                try
                {
                    var compRes = comp.Compile(parRes.Program, copt, new ExportVars());
                    msg.AddRange(compRes.Messages.Where(m => m.Type != MessageType.Hint).Select(project));

                    if (compRes.CodeFrame != null)
                        unit = new CompiledUnit(doc, compRes.CodeFrame);
                }
                catch { }
            }
            else
                msg.AddRange(parRes.Messages.Select(project));

            return Tuple.Create(unit, (IEnumerable<MessageItem>)msg);
        }
Ejemplo n.º 8
0
 private void ChangeNodeText(CodeDocument doc, TreeNode node)
 {
     var title = new FileInfo(doc.Title).ShortName();
     node.Text = title;
 }
Ejemplo n.º 9
0
        public void RemoveDocumentNode(CodeDocument doc)
        {
            var node = treeView.Nodes.OfType<TreeNode>().FirstOrDefault(tn => tn.Tag == doc);

            if (node != null)
            {
                node.Tag = null;
                treeView.Nodes.Remove(node);
            }
        }
Ejemplo n.º 10
0
 public IEnumerable<TaskItem> GetTasks(CodeDocument doc)
 {
     var tp = new ElaTaskParser();
     return tp.Parse(doc.GetContent());
 }
Ejemplo n.º 11
0
 public SymbolLocation(CodeDocument doc, int line, int column)
 {
     Document = doc;
     Line     = line - 1;
     Column   = column - 1;
 }
Ejemplo n.º 12
0
        public void DoComplete(int pos, CodeDocument doc)
        {
            if (doc == null)
                return;

            if (TestIfComments(pos, true) || TestIfComments(pos - 1, false))
                return;

            if (sci.CurrentPosition > 0 && sci.CharAt(sci.CurrentPosition - 1) == '.')
            {
                ListModuleMembers(doc, pos - 2);
                return;
            }

            var names = default(List<AutocompleteSymbol>);

            if (doc.Unit != null)
            {
                var frame = ((CompiledUnit)doc.Unit).CodeFrame;
                var dr = new DebugReader(frame.Symbols);
                var col = sci.GetColumnFromPosition(sci.CurrentPosition);
                var ln = dr.FindClosestLineSym(sci.CurrentLine + 1, col + 1);

                var scope = col == 0 || col == 1 ? dr.GetScopeSymByIndex(0) :
                    dr.FindScopeSym(sci.CurrentLine + 1, col + 1);

                if (scope == null)
                    scope = dr.GetScopeSymByIndex(0);

                if (scope != null)
                {
                    var vars = LookVars(dr, ln != null ? ln.Offset : scope.EndOffset, scope.Index);
                    names = vars
                        .Where(v => v.Name[0] != '$')
                        .Select(v =>
                            {
                                var f = (ElaVariableFlags)v.Flags;
                                return new AutocompleteSymbol(v.Name,
                                    f.Set(ElaVariableFlags.Module) ? AutocompleteSymbolType.Module :
                                    f.Set(ElaVariableFlags.TypeFun) ? AutocompleteSymbolType.Type :
                                    f.Set(ElaVariableFlags.ClassFun) ? AutocompleteSymbolType.Member :
                                        AutocompleteSymbolType.Variable);
                            })
                        .ToList();
                }
            }

            var line = sci.GetLine(sci.CurrentLine).Text.Trim('\r', '\n', '\0');
            var tl = line.Trim();
            var keywords = new List<AutocompleteSymbol>();

            keywords.Add(Snippet("if"));

            if (tl.Length == 0)
            {
                keywords.Add(Snippet("open"));
                keywords.Add(Snippet("let"));

                if (line.Length > 0)
                {
                    keywords.Add(Snippet("et"));
                    keywords.Add(Snippet("where"));
                }
            }
            else if (tl.EndsWith("="))
                keywords.Add(Snippet("let"));
            else if (tl.EndsWith("let"))
            {
                keywords.Add(Snippet("private"));
                keywords.Add(Snippet("inline"));
            }

            if (names != null)
                keywords.AddRange(names);

            app.GetService<IAutocompleteService>().ShowAutocomplete(keywords);
        }
Ejemplo n.º 13
0
        private void ListModuleMembers(CodeDocument doc, int pos)
        {
            var sym = GetNameInfo(pos, doc);
            var unit = doc != null ? doc.Unit : null;
            var frame = unit != null ? ((CompiledUnit)unit).CodeFrame : null;

            if (sym != null && ((ElaVariableFlags)sym.Flags).Set(ElaVariableFlags.Module)
                && frame != null && frame.References.ContainsKey(sym.Name))
            {
                var mod = frame.References[sym.Name];
                var rr = new ElaReferenceResolver { App = app };
                var refUnit = rr.Resolve(new Reference(new CompiledUnit(doc, frame), mod));

                if (refUnit != null)
                {
                    var sb = new StringBuilder();
                    var list = new List<AutocompleteSymbol>();

                    foreach (var cn in ((CompiledUnit)refUnit).CodeFrame.GlobalScope.EnumerateVars()
                        .Where(v => !v.Value.VariableFlags.Set(ElaVariableFlags.Module)
                            && !v.Value.VariableFlags.Set(ElaVariableFlags.Private)
                            && v.Key[0] != '$'))
                    {
                        list.Add(new AutocompleteSymbol(cn.Key,
                            cn.Value.VariableFlags.Set(ElaVariableFlags.Module) ? AutocompleteSymbolType.Module :
                            cn.Value.VariableFlags.Set(ElaVariableFlags.TypeFun) ? AutocompleteSymbolType.Type :
                            cn.Value.VariableFlags.Set(ElaVariableFlags.ClassFun) ? AutocompleteSymbolType.Member :
                                AutocompleteSymbolType.Variable));
                    }

                    list = list.OrderBy(c => c.Name).ToList();
                    app.GetService<IAutocompleteService>().ShowAutocomplete(list);
                }
            }
        }
Ejemplo n.º 14
0
        private VarSym GetNameInfo(int position, CodeDocument doc)
        {
            var word = sci.GetWordAt(position) ?? GetOperator(position, 0);
            var frame = doc != null ? doc.Unit : null;

            if (word != null && frame != null)
            {
                var dr = new DebugReader(((CompiledUnit)frame).CodeFrame.Symbols);
                var lineNum = sci.GetLineFromPosition(position);
                var colNum = sci.GetColumnFromPosition(position);

                var ln = dr.FindClosestLineSym(lineNum + 1, colNum + 1);
                var scope = default(ScopeSym);

                if (ln != null && (scope = (dr.FindScopeSym(lineNum + 1, colNum + 1) ?? dr.GetScopeSymByIndex(0))) != null)
                    return LookVar(dr, ln.Offset, scope.Index, word);
            }

            return null;
        }
Ejemplo n.º 15
0
        public FileInfo FindModule(int pos, CodeDocument doc)
        {
            var sym = GetNameInfo(pos, doc);
            var unit = doc != null ? doc.Unit : null;
            var frame = unit != null ? ((CompiledUnit)unit).CodeFrame : null;

            if (sym != null && ((ElaVariableFlags)sym.Flags).Set(ElaVariableFlags.Module)
                && frame != null && frame.References.ContainsKey(sym.Name))
            {
                var mod = frame.References[sym.Name];
                var rr = new ElaReferenceResolver { App = app };
                var refUnit = rr.Resolve(new Reference(new CompiledUnit(doc, frame), mod), ElaReferenceResolver.NoBuild);

                if (refUnit != null)
                    return ((CompiledUnit)refUnit).Document.FileInfo;
            }

            return null;
        }
Ejemplo n.º 16
0
 public new ITaskProvider GetTaskProvider(CodeDocument doc)
 {
     return base.GetTaskProvider(doc);
 }
Ejemplo n.º 17
0
        private IEnumerable<SymbolLocation> ProcessFile(string name, CodeDocument doc)
        {
            var editor = app.Editor(doc.GetType());
            var list = new List<SymbolLocation>();

            if (editor is ElaEditor)
            {
                var src = ((ITextEditor)editor).GetContent(doc);
                var p = new ElaParser();
                var res = p.Parse(src);

                if (res.Success)
                {
                    res.Program.Includes.ForEach(i => FindName(name, doc, i, list));
                    FindName(name, doc, res.Program.Instances, list);
                    FindName(name, doc, res.Program.Classes, list);
                    FindName(name, doc, res.Program.Types, list);
                    FindName(name, doc, res.Program.TopLevel, list);
                }
            }

            return list;
        }
Ejemplo n.º 18
0
        private void FindName(string name, CodeDocument doc, ElaExpression expr, List<SymbolLocation> syms)
        {
            if (expr == null)
                return;

            switch (expr.Type)
            {
                case ElaNodeType.As:
                    {
                        var a = (ElaAs)expr;

                        if (a.Name == name)
                            syms.Add(new SymbolLocation(doc, a.Line, a.Column));

                        if (a.Expression != null)
                            FindName(name, doc, a.Expression, syms);
                    }
                    break;
                case ElaNodeType.EquationSet:
                    {
                        var b = (ElaEquationSet)expr;

                        foreach (var e in b.Equations)
                            FindName(name, doc, e, syms);
                    }
                    break;
                case ElaNodeType.Builtin:
                    break;
                case ElaNodeType.Newtype:
                    {
                        var b = (ElaNewtype)expr;

                        foreach (var e in b.Constructors)
                            FindName(name, doc, e, syms);
                    }
                    break;
                case ElaNodeType.TypeClass:
                    {
                        var b = (ElaTypeClass)expr;

                        if (b.Members != null)
                            foreach (var m in b.Members)
                                FindName(name, doc, m, syms);

                        if (b.And != null)
                            FindName(name, doc, b.And, syms);
                    }
                    break;
                case ElaNodeType.ClassMember:
                    {
                        var b = (ElaClassMember)expr;

                        if (b.Name == name)
                            syms.Add(new SymbolLocation(doc, b.Line, b.Column));
                    }
                    break;
                case ElaNodeType.ClassInstance:
                    {
                        var b = (ElaClassInstance)expr;

                        if (b.Where != null)
                            FindName(name, doc, b.Where, syms);

                        if (b.And != null)
                            FindName(name, doc, b.And, syms);
                    }
                    break;
                case ElaNodeType.Equation:
                    {
                        var b = (ElaEquation)expr;

                        if (b.Left != null)
                            FindName(name, doc, b.Left, syms);

                        if (b.Right != null)
                            FindName(name, doc, b.Right, syms);

                        if (b.Next != null)
                            FindName(name, doc, b.Next, syms);
                    }
                    break;
                case ElaNodeType.LetBinding:
                    {
                        var b = (ElaLetBinding)expr;

                        if (b.Equations != null)
                            FindName(name, doc, b.Equations, syms);

                        if (b.Expression != null)
                            FindName(name, doc, b.Expression, syms);
                    }
                    break;
                case ElaNodeType.Comprehension:
                    {
                        var c = (ElaComprehension)expr;

                        if (c.Generator != null)
                            FindName(name, doc, c.Generator, syms);
                    }
                    break;
                case ElaNodeType.Condition:
                    {
                        var c = (ElaCondition)expr;

                        if (c.Condition != null)
                            FindName(name, doc, c.Condition, syms);

                        if (c.True != null)
                            FindName(name, doc, c.True, syms);

                        if (c.False != null)
                            FindName(name, doc, c.False, syms);
                    }
                    break;
                case ElaNodeType.Placeholder:
                    break;
                case ElaNodeType.FieldDeclaration:
                    {
                        var f = (ElaFieldDeclaration)expr;

                        if (f.FieldValue != null)
                            FindName(name, doc, f.FieldValue, syms);
                    }
                    break;
                case ElaNodeType.FieldReference:
                    {
                        var r = (ElaFieldReference)expr;

                        if (r.TargetObject != null)
                            FindName(name, doc, r.TargetObject, syms);
                    }
                    break;
                case ElaNodeType.Juxtaposition:
                    {
                        var c = (ElaJuxtaposition)expr;
                        FindName(name, doc, c.Target, syms);

                        foreach (var p in c.Parameters)
                            FindName(name, doc, p, syms);
                    }
                    break;
                case ElaNodeType.Lambda:
                    {
                        var f = (ElaLambda)expr;

                        if (f.Left != null)
                            FindName(name, doc, f.Left, syms);

                        if (f.Right != null)
                            FindName(name, doc, f.Right, syms);
                    }
                    break;
                case ElaNodeType.Generator:
                    {
                        var g = (ElaGenerator)expr;

                        if (g.Target != null)
                            FindName(name, doc, g.Target, syms);

                        if (g.Pattern != null)
                            FindName(name, doc, g.Pattern, syms);

                        if (g.Guard != null)
                            FindName(name, doc, g.Guard, syms);

                        if (g.Body != null)
                            FindName(name, doc, g.Body, syms);
                    }
                    break;
                case ElaNodeType.ImportedVariable:
                    {
                        var v = (ElaImportedVariable)expr;

                        if (v.LocalName == name || v.Name == name)
                            syms.Add(new SymbolLocation(doc, v.Line, v.Column));
                    }
                    break;
                case ElaNodeType.TypeCheck:
                    {
                        var i = (ElaTypeCheck)expr;

                        if (i.Expression != null)
                            FindName(name, doc, i.Expression, syms);
                    }
                    break;
                case ElaNodeType.LazyLiteral:
                    {
                        var l = (ElaLazyLiteral)expr;

                        if (l.Expression != null)
                            FindName(name, doc, l.Expression, syms);
                    }
                    break;
                case ElaNodeType.ListLiteral:
                    {
                        var l = (ElaListLiteral)expr;

                        if (l.Values != null)
                            foreach (var v in l.Values)
                                FindName(name, doc, v, syms);
                    }
                    break;
                case ElaNodeType.Match:
                    {
                        var m = (ElaMatch)expr;

                        if (m.Expression != null)
                            FindName(name, doc, m.Expression, syms);

                        if (m.Entries != null)
                            FindName(name, doc, m.Entries, syms);
                    }
                    break;
                case ElaNodeType.ModuleInclude:
                    {
                        var m = (ElaModuleInclude)expr;

                        if (m.Alias == name)
                            syms.Add(new SymbolLocation(doc, m.Line, m.Column));

                        if (m.HasImportList)
                            foreach (var i in m.ImportList)
                                FindName(name, doc, i, syms);
                    }
                    break;
                case ElaNodeType.Primitive:
                    break;
                case ElaNodeType.Raise:
                    {
                        var r = (ElaRaise)expr;

                        if (r.Expression != null)
                            FindName(name, doc, r.Expression, syms);
                    }
                    break;
                case ElaNodeType.Range:
                    {
                        var r = (ElaRange)expr;

                        if (r.First != null)
                            FindName(name, doc, r.First, syms);

                        if (r.Second != null)
                            FindName(name, doc, r.Second, syms);

                        if (r.Last != null)
                            FindName(name, doc, r.Last, syms);
                    }
                    break;
                case ElaNodeType.RecordLiteral:
                    {
                        var r = (ElaRecordLiteral)expr;

                        if (r.Fields != null)
                            foreach (var f in r.Fields)
                                FindName(name, doc, f, syms);
                    }
                    break;
                case ElaNodeType.Try:
                    {
                        var t = (ElaTry)expr;

                        if (t.Expression != null)
                            FindName(name, doc, t.Expression, syms);

                        if (t.Entries != null)
                            FindName(name, doc, t.Entries, syms);
                    }
                    break;
                case ElaNodeType.TupleLiteral:
                    {
                        var t = (ElaTupleLiteral)expr;

                        if (t.Parameters != null)
                            foreach (var p in t.Parameters)
                                FindName(name, doc, p, syms);
                    }
                    break;
                case ElaNodeType.NameReference:
                    {
                        var r = (ElaNameReference)expr;

                        if (r.Name == name)
                            syms.Add(new SymbolLocation(doc, r.Line, r.Column));
                    }
                    break;
            }
        }
Ejemplo n.º 19
0
 public SymbolLocation(CodeDocument doc, int line, int column)
 {
     Document = doc;
     Line = line - 1;
     Column = column - 1;
 }