Exemplo n.º 1
0
        public static bool CheckAndAddSuggestion(IntellisenseSuggestion suggestion, IntellisenseSuggestionList suggestionList)
        {
            if (suggestionList.ContainsSuggestion(suggestion.DisplayText.Text))
            {
                return(false);
            }

            suggestionList.Add(suggestion);
            return(true);
        }
Exemplo n.º 2
0
        public static UIString DisambiguateGlobals(IntellisenseSuggestionList curList, UIString curSuggestion, SuggestionKind suggestionKind, DType type)
        {
            Contracts.AssertValue(curList);
            Contracts.AssertValue(curSuggestion);
            Contracts.AssertValid(type);

            UIString retVal = curSuggestion;
            string   sug    = curSuggestion.Text;
            bool     suggestionKindIsGlobalOrScope = (suggestionKind == SuggestionKind.Global || suggestionKind == SuggestionKind.ScopeVariable);

            foreach (var s in curList.SuggestionsForText(sug))
            {
                // Retrive global/appVariable suggestions which
                //   -- Don't have the same type as current suggestion (because, if it's of same type, it will be filtered out anyway)
                //   -- Match the current suggestion text (filtered in the loop definition above for efficiency)
                if ((!suggestionKindIsGlobalOrScope &&
                     s.Kind != SuggestionKind.Global &&
                     s.Kind != SuggestionKind.ScopeVariable) ||
                    s.Type == type)
                {
                    continue;
                }

                // The retrived list represents collisions. Update the suggestion text with global disambiguation.

                int punctuatorLen = TexlLexer.PunctuatorAt.Length + TexlLexer.PunctuatorAt.Length;
                // The suggestion already in the list is global. Update it.
                if (s.Kind == SuggestionKind.Global || s.Kind == SuggestionKind.ScopeVariable)
                {
                    int index = curList.IndexOf(s);
                    Contracts.Assert(index >= 0);

                    UIString dispText = curList[index].DisplayText;

                    // If we are already using the global syntax, we should not add it again.
                    if (dispText.Text.StartsWith(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt))
                    {
                        continue;
                    }

                    curList.UpdateDisplayText(index, new UIString(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt + dispText.Text + TexlLexer.PunctuatorBracketClose,
                                                                  dispText.HighlightStart + punctuatorLen,
                                                                  dispText.HighlightEnd + punctuatorLen));
                }
                // Current suggestion is global. Update it.
                else
                {
                    retVal = new UIString(TexlLexer.PunctuatorBracketOpen + TexlLexer.PunctuatorAt + sug + TexlLexer.PunctuatorBracketClose,
                                          curSuggestion.HighlightStart + punctuatorLen,
                                          curSuggestion.HighlightEnd + punctuatorLen);
                }
            }
            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is a Private method used only by the SuggestFunctions() method to add overload suggestions to the existing suggestions.
        /// </summary>
        public static void AddFunctionOverloads(string qualifiedName, IntellisenseSuggestionList suggestions, IntellisenseSuggestion funcSuggestion)
        {
            Contracts.AssertNonEmpty(qualifiedName);
            Contracts.AssertValue(suggestions);
            Contracts.AssertValue(funcSuggestion);

            int overloadMatch = suggestions.FindIndex(x => (x.Kind == SuggestionKind.Function && x.FunctionName == qualifiedName));

            if (overloadMatch > -1)
            {
                suggestions[overloadMatch].AddOverloads(funcSuggestion.Overloads);
            }
            else
            {
                CheckAndAddSuggestion(funcSuggestion, suggestions);
            }
        }
Exemplo n.º 4
0
 protected virtual UIString ConstructUIString(SuggestionKind suggestionKind, DType type, IntellisenseSuggestionList suggestions, string valueToSuggest, int highlightStart, int highlightEnd)
 {
     return(IntellisenseHelper.DisambiguateGlobals(suggestions,
                                                   new UIString(valueToSuggest, highlightStart, highlightEnd),
                                                   suggestionKind,
                                                   type));
 }
Exemplo n.º 5
0
 protected virtual bool CheckAndAddSuggestion(IntellisenseSuggestionList suggestions, IntellisenseSuggestion candidate)
 {
     return(IntellisenseHelper.CheckAndAddSuggestion(candidate, suggestions));
 }
Exemplo n.º 6
0
        public bool AddSuggestion(IntellisenseData.IntellisenseData intellisenseData, string suggestion, SuggestionKind suggestionKind, SuggestionIconKind iconKind, DType type, bool requiresSuggestionEscaping, uint sortPriority = 0)
        {
            Contracts.AssertValue(intellisenseData);
            Contracts.AssertValue(suggestion);

            if (!intellisenseData.DetermineSuggestibility(suggestion, type))
            {
                return(false);
            }

            IntellisenseSuggestionList suggestions          = intellisenseData.Suggestions;
            IntellisenseSuggestionList substringSuggestions = intellisenseData.SubstringSuggestions;
            int    matchingLength = intellisenseData.MatchingLength;
            string matchingStr    = intellisenseData.MatchingStr;
            string boundTo        = intellisenseData.BoundTo;

            var valueToSuggest = requiresSuggestionEscaping ? TexlLexer.EscapeName(suggestion) : suggestion;
            int highlightStart = suggestion.IndexOf(matchingStr, StringComparison.OrdinalIgnoreCase);

            // If the suggestion has special characters we need to find the highlightStart index by escaping the matching string as well.
            // Because, the suggestion could be something like 'Ident with Space' and the user might have typed Ident. In this case,
            // we want to highlight only Ident while displaying 'Ident with Space'.
            if (requiresSuggestionEscaping && !string.IsNullOrEmpty(matchingStr) && valueToSuggest != suggestion && highlightStart == 0)
            {
                highlightStart++;
            }
            else
            {
                matchingLength--;
            }

            int highlightEnd = highlightStart + matchingStr.Length;

            if (IntellisenseHelper.IsMatch(suggestion, matchingStr))
            {
                // In special circumstance where the user escapes an identifier where they don't have to, the matching length will
                // include the starting delimiter that user provided, where as the suggestion would not include any delimiters.
                // Hence we have to count for that fact.
                if (matchingLength > 0 & matchingLength > matchingStr.Length)
                {
                    highlightEnd = matchingLength > valueToSuggest.Length ? valueToSuggest.Length : matchingLength;
                }
                UIString UIsuggestion            = ConstructUIString(suggestionKind, type, suggestions, valueToSuggest, highlightStart, highlightEnd);
                IntellisenseSuggestion candidate = new IntellisenseSuggestion(UIsuggestion,
                                                                              suggestionKind,
                                                                              iconKind,
                                                                              type,
                                                                              boundTo,
                                                                              -1,
                                                                              string.Empty,
                                                                              null,
                                                                              sortPriority);
                return(CheckAndAddSuggestion(suggestions, candidate));
            }
            if (highlightStart > -1)
            {
                UIString UIsuggestion            = ConstructUIString(suggestionKind, type, substringSuggestions, valueToSuggest, highlightStart, highlightEnd);
                IntellisenseSuggestion candidate = new IntellisenseSuggestion(UIsuggestion,
                                                                              suggestionKind,
                                                                              iconKind,
                                                                              type,
                                                                              boundTo,
                                                                              -1,
                                                                              string.Empty,
                                                                              null,
                                                                              sortPriority);

                return(CheckAndAddSuggestion(substringSuggestions, candidate));
            }

            return(false);
        }
 protected override bool CheckAndAddSuggestion(IntellisenseSuggestionList suggestions, IntellisenseSuggestion candidate)
 {
     return(!suggestions.ContainsSuggestion(candidate.DisplayText.Text));
 }
 protected override UIString ConstructUIString(SuggestionKind suggestionKind, DType type, IntellisenseSuggestionList suggestions, string valueToSuggest, int highlightStart, int highlightEnd)
 {
     return(new UIString(valueToSuggest, highlightStart, highlightEnd));
 }