internal override async void AutoComplete(AutoCompleteParameters autoCompleteParameters)
        {
            _autoCompleteAppend = string.Empty;

            string?text = autoCompleteParameters.LineText.Trim();


            MatchingAutoCompletes.Clear();

            ILookup <string, UMLDataType>?types = DataTypes.SelectMany(p => p.DataTypes).Where(p => p is UMLClass || p is UMLInterface).ToLookup(p => p.Name);

            if (text.StartsWith("participant", StringComparison.InvariantCulture) ||
                text.StartsWith("actor", StringComparison.InvariantCulture))
            {
                if (PlantUML.UMLSequenceDiagramParser.TryParseLifeline(text, types, autoCompleteParameters.LineNumber, out UMLSequenceLifeline? lifeline) && lifeline.DataTypeId != null)
                {
                    return;
                }
                else
                {
                    foreach (IGrouping <string, UMLDataType>?item in types)
                    {
                        if (string.IsNullOrEmpty(autoCompleteParameters.TypedWord) || item.Key.Contains(autoCompleteParameters.TypedWord, StringComparison.InvariantCultureIgnoreCase))
                        {
                            MatchingAutoCompletes.Add(item.Key);
                        }
                    }

                    if (MatchingAutoCompletes.Count > 0)
                    {
                        ShowAutoComplete();
                    }

                    return;
                }
            }

            string?str = TextEditor?.TextRead();

            if (str is not null)
            {
                UMLSequenceDiagram?diagram = await PlantUML.UMLSequenceDiagramParser.ReadString(str, DataTypes, true);

                if (diagram != null)
                {
                    if (PlantUML.UMLSequenceDiagramParser.TryParseAllConnections(text, diagram, types, null, 0,
                                                                                 out UMLSequenceConnection? connection))
                    {
                        if (text.Length - 2 > autoCompleteParameters.PositionInLine &&
                            autoCompleteParameters.PositionInLine < text.IndexOf(":", StringComparison.InvariantCulture))
                        {
                            return;
                        }

                        if (connection.To != null && connection.To.DataTypeId != null)
                        {
                            foreach (UMLDataType?t in types[connection.To.DataTypeId])
                            {
                                AddAll(t, MatchingAutoCompletes, autoCompleteParameters.TypedWord);
                            }
                            if (MatchingAutoCompletes.Count > 0)
                            {
                                ShowAutoComplete();
                            }

                            return;
                        }
                    }

                    if (text.EndsWith("return", StringComparison.InvariantCulture))
                    {
                        foreach (string?item in diagram.LifeLines.Where(p => string.IsNullOrEmpty(autoCompleteParameters.TypedWord) || p.Text.StartsWith(autoCompleteParameters.TypedWord, StringComparison.InvariantCultureIgnoreCase)).Select(p => p.Text))
                        {
                            MatchingAutoCompletes.Add(item);
                        }

                        if (MatchingAutoCompletes.Count > 0)
                        {
                            ShowAutoComplete();
                        }

                        return;
                    }

                    foreach (string?item in diagram.LifeLines.Where(p => string.IsNullOrEmpty(autoCompleteParameters.TypedWord) || p.Alias.StartsWith(autoCompleteParameters.TypedWord, StringComparison.InvariantCultureIgnoreCase)).Select(p => p.Alias))
                    {
                        MatchingAutoCompletes.Add(item);
                    }
                }
            }
            if (!MatchingAutoCompletes.Any())
            {
                foreach (string?item in DEFAULTAUTOCOMPLETES.Where(p => string.IsNullOrEmpty(autoCompleteParameters.TypedWord) || p.StartsWith(autoCompleteParameters.TypedWord, StringComparison.InvariantCultureIgnoreCase)))
                {
                    MatchingAutoCompletes.Add(item);
                }
            }



            if (MatchingAutoCompletes.Count > 0)
            {
                ShowAutoComplete();
            }
        }
Exemplo n.º 2
0
 internal override void AutoComplete(AutoCompleteParameters autoCompleteParameters)
 {
 }