Ejemplo n.º 1
0
        public IEnumerable <Workspaces.Range> GetErrors(Workspaces.Range range, Document doc)
        {
            ParsingResults pd        = ParsingResultsFactory.Create(doc);
            var            workspace = doc.Workspace;

            if (pd.ParseTree == null)
            {
                Compile(workspace);
            }

            List <Range> result = new List <Workspaces.Range>();

            foreach (IParseTree p in pd.Errors)
            {
                ErrorNodeImpl q = p as Antlr4.Runtime.Tree.ErrorNodeImpl;
                if (q == null)
                {
                    continue;
                }

                if (q.Payload == null)
                {
                    continue;
                }

                int y = q.Payload.StartIndex;
                int z = q.Payload.StopIndex;
                if (y < 0)
                {
                    y = 0;
                }

                if (z < 0)
                {
                    z = 0;
                }

                int a = y;
                int b = z + 1;
                int start_token_start = a;
                int end_token_end     = b;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }

                if (end_token_end < range.Start.Value)
                {
                    continue;
                }

                Range r = new Workspaces.Range(new Workspaces.Index(a), new Workspaces.Index(b));
                result.Add(r);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static IEnumerable <Workspaces.Range> GetErrors(Workspaces.Range range, Document doc)
        {
            var pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                return(new List <Workspaces.Range>());
            }
            var result = new List <Workspaces.Range>();

            foreach (var p in pd.Errors)
            {
                var q = p as Antlr4.Runtime.Tree.ErrorNodeImpl;
                if (q == null)
                {
                    continue;
                }
                if (q.Payload == null)
                {
                    continue;
                }
                var y = q.Payload.StartIndex;
                var z = q.Payload.StopIndex;
                if (y < 0)
                {
                    y = 0;
                }
                if (z < 0)
                {
                    z = 0;
                }
                var a = y;
                var b = z + 1;
                int start_token_start = a;
                int end_token_end     = b;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }
                if (end_token_end < range.Start.Value)
                {
                    continue;
                }
                var r = new Workspaces.Range(new Workspaces.Index(a), new Workspaces.Index(b));
                result.Add(r);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static IEnumerable <DocumentSymbol> Get(Workspaces.Range range, Document doc)
        {
            ParserDetails pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                LanguageServer.Module.Compile();
            }

            List <DocumentSymbol> combined = new System.Collections.Generic.List <DocumentSymbol>();

            foreach (KeyValuePair <TerminalNodeImpl, int> p in pd.Tags)
            {
                if (p.Key.Symbol == null)
                {
                    continue;
                }

                int start_token_start = p.Key.Symbol.StartIndex;
                int end_token_end     = p.Key.Symbol.StopIndex + 1;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }

                if (end_token_end < range.Start.Value)
                {
                    continue;
                }

                combined.Add(
                    new DocumentSymbol()
                {
                    name  = p.Key.Symbol.Text,
                    range = new Workspaces.Range(p.Key.Symbol.StartIndex, p.Key.Symbol.StopIndex),
                    kind  = p.Value
                });
            }
            foreach (KeyValuePair <Antlr4.Runtime.IToken, int> p in pd.Comments)
            {
                int start_token_start = p.Key.StartIndex;
                int end_token_end     = p.Key.StopIndex + 1;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }

                if (end_token_end < range.Start.Value)
                {
                    continue;
                }

                combined.Add(
                    new DocumentSymbol()
                {
                    name  = p.Key.Text,
                    range = new Workspaces.Range(p.Key.StartIndex, p.Key.StopIndex),
                    kind  = p.Value
                });
            }

            // Sort the list.
            IEnumerable <DocumentSymbol>        result;
            IOrderedEnumerable <DocumentSymbol> sorted_combined_tokens = combined.OrderBy(t => t.range.Start.Value).ThenBy(t => t.range.End.Value);

            result = sorted_combined_tokens;
            return(result);
        }
Ejemplo n.º 4
0
        public static QuickInfo GetQuickInfo(int index, Document doc)
        {
            ParserDetails pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                LanguageServer.Module.Compile();
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            IGrammarDescription            gd = GrammarDescriptionFactory.Create(doc.FullPath);

            if (pt == null)
            {
                return(null);
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            pd.Attributes.TryGetValue(p, out IList <CombinedScopeSymbol> list_value);
            if (list_value == null)
            {
                return(null);
            }

            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            Range            range = new Workspaces.Range(new Workspaces.Index(q.Symbol.StartIndex), new Workspaces.Index(q.Symbol.StopIndex + 1));
            bool             found = pd.Tags.TryGetValue(q, out int tag_type);

            if (!found)
            {
                return(null);
            }

            if (list_value == null || list_value.Count == 0)
            {
                return(new QuickInfo()
                {
                    Display = gd.Map[tag_type], Range = range
                });
            }
            if (list_value.Count == 1)
            {
                CombinedScopeSymbol value = list_value.First();
                ISymbol             name  = value as Symtab.ISymbol;
                string show = name?.Name;
                if (value is Symtab.Literal)
                {
                    show = ((Symtab.Literal)value).Cleaned;
                }
                if (gd.PopUpDefinition[tag_type] != null)
                {
                    Func <ParserDetails, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                    string mess = fun(pd, p);
                    if (mess != null)
                    {
                        return(new QuickInfo()
                        {
                            Display = mess, Range = range
                        });
                    }
                }
                string display = gd.Map[tag_type]
                                 + "\n"
                                 + show;
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
            {
                string display = "Ambiguous -- ";
                foreach (CombinedScopeSymbol value in list_value)
                {
                    ISymbol name = value as Symtab.ISymbol;
                    string  show = name?.Name;
                    if (value is Symtab.Literal)
                    {
                        show = ((Symtab.Literal)value).Cleaned;
                    }
                    if (gd.PopUpDefinition[tag_type] != null)
                    {
                        Func <ParserDetails, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                        string mess = fun(pd, p);
                        if (mess != null)
                        {
                            display = display + mess;
                        }
                    }
                    else
                    {
                        display = display + gd.Map[tag_type]
                                  + "\n"
                                  + show;
                    }
                }
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
        }
Ejemplo n.º 5
0
        public static IEnumerable <DocumentSymbol> Get(Workspaces.Range range, Document doc)
        {
            var pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                return(new List <DocumentSymbol>());
            }
            var combined = new System.Collections.Generic.List <DocumentSymbol>();

            foreach (var p in pd.Tags)
            {
                if (p.Key.Symbol == null)
                {
                    continue;
                }
                int start_token_start = p.Key.Symbol.StartIndex;
                int end_token_end     = p.Key.Symbol.StopIndex + 1;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }
                if (end_token_end < range.Start.Value)
                {
                    continue;
                }
                combined.Add(
                    new DocumentSymbol()
                {
                    name  = p.Key.Symbol.Text,
                    range = new Workspaces.Range(p.Key.Symbol.StartIndex, p.Key.Symbol.StopIndex),
                    kind  = p.Value
                });
            }
            foreach (var p in pd.Comments)
            {
                int start_token_start = p.Key.StartIndex;
                int end_token_end     = p.Key.StopIndex + 1;
                if (start_token_start > range.End.Value)
                {
                    continue;
                }
                if (end_token_end < range.Start.Value)
                {
                    continue;
                }
                combined.Add(
                    new DocumentSymbol()
                {
                    name  = p.Key.Text,
                    range = new Workspaces.Range(p.Key.StartIndex, p.Key.StopIndex),
                    kind  = p.Value
                });
            }

            // Sort the list.
            IEnumerable <DocumentSymbol> result;
            var sorted_combined_tokens = combined.OrderBy(t => t.range.Start.Value).ThenBy(t => t.range.End.Value);

            result = sorted_combined_tokens;
            return(result);
        }
Ejemplo n.º 6
0
 public TextChange(Range range, string replacement)
 {
     _range       = range;
     _replacement = replacement;
 }