Exemplo n.º 1
0
        public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context)
        {
            var completions = new List <ICompletionEntry>();
            var start       = DateTime.Now;

            _variablesProvider.Initialize();
            var names = GetFieldProvidingVariableNames(context);

            foreach (var variableName in names)
            {
                var members = _variablesProvider.GetMembers(variableName, 200);
                foreach (var v in members)
                {
                    Debug.Assert(v != null);
                    if (v.Name.Length > 0 && v.Name[0] != '[')
                    {
                        var glyph      = v.ItemType == NamedItemType.Variable ? _variableGlyph : _functionGlyph;
                        var completion = new EditorCompletionEntry(v.Name, v.Name.BacktickName(), v.Description, glyph);
                        completions.Add(completion);
                    }
                }
            }
            Debug.WriteLine("Variable members fetch: " + (DateTime.Now - start).TotalMilliseconds);
            return(completions);
        }
        public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context)
        {
            var completions = new List <ICompletionEntry>();
            var ast         = context.AstRoot;

            // First try simple scope like in 'for(x in 1:10) x|'
            IScope scope = ast.GetNodeOfTypeFromPosition <SimpleScope>(context.Position, includeEnd: true);

            // If not found, look for the regular scope
            scope = scope ?? ast.GetNodeOfTypeFromPosition <IScope>(context.Position);

            var variables = scope.GetApplicableVariables(context.Position);

            foreach (var v in variables)
            {
                var f          = v.Value as RFunction;
                var completion = new EditorCompletionEntry(v.Name.RemoveBackticks(), v.Name.BacktickName(), string.Empty, f != null ? _functionGlyph : _variableGlyph);
                completions.Add(completion);
            }

            return(completions);
        }