public IEnumerable <IQuerySuggestion> Compute(SuggestionState state)
        {
            var expected = state.Expected.Find(item =>
                                               item.RuleIndices[0] == QueryParser.RULE_factor && (
                                                   item.Tokens.Contains(QueryLexer.STRING) ||
                                                   item.Tokens.Contains(QueryLexer.INT) ||
                                                   item.Tokens.Contains(QueryLexer.REAL)
                                                   ));

            // only suggest attribute values in an expression factor
            if (expected == null)
            {
                return(Enumerable.Empty <IQuerySuggestion>());
            }

            var parts = state.Caret.SplitParent();

            if (parts.Suffix.Length > 0 && (
                    parts.Suffix[parts.Suffix.Length - 1] == '\n' ||
                    parts.Suffix[parts.Suffix.Length - 1] == '\r'))
            {
                parts.Suffix = parts.Suffix.Substring(0, parts.Suffix.Length - 1);
            }

            return(_listener.AttributeNames
                   .SelectMany(name => _attributeCache.GetValues(name))
                   .Where(item => ContainsPrefixSuffix(item, parts.Prefix, parts.Suffix))
                   .Select(item => new ValueSuggestion(state.Caret, item)));
        }
Пример #2
0
        private async void View_BeginValueEdit(object sender, NameEventArgs e)
        {
            // reset suggestions
            View.Suggestions = new List <Suggestion>();

            var suggestions = await Task.Run(() =>
            {
                var items = new List <Suggestion>();
                foreach (var value in _attributeCache.GetValues(e.Value))
                {
                    items.Add(new Suggestion(value.ToString(), value.Type.ToString(), value));
                }

                return(items);
            });

            if (_isDisposed)
            {
                return;
            }

            View.Suggestions = suggestions;
        }