< Summary

Class:GDX.Developer.ConsoleAutoCompleteProvider
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleAutoCompleteProvider.cs
Covered lines:0
Uncovered lines:61
Coverable lines:61
Total lines:108
Line coverage:0% (0 of 61)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetCurrentSuggestion()0%2100%
UpdateSuggestion(...)0%3421800%
Reset()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleAutoCompleteProvider.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6
 7namespace GDX.Developer
 8{
 9#if UNITY_2022_2_OR_NEWER
 10    public static class ConsoleAutoCompleteProvider
 11    {
 12        static int s_AutoCompleteOffset;
 13        static string[] s_AutoCompleteSuggestions;
 14        static string s_CurrentSuggestion;
 15
 16        public static string GetCurrentSuggestion()
 017        {
 018            return s_CurrentSuggestion;
 019        }
 20
 21        public static bool UpdateSuggestion(string inputString)
 022        {
 023            string[] split = inputString.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
 24
 025            if (split == null || split.Length == 0)
 026            {
 027                Reset();
 028                return false;
 29            }
 30
 31            // Check if we have a command
 032            ConsoleCommandBase command = Console.GetCommand(split[0]);
 033            if (command != null)
 034            {
 035                s_AutoCompleteSuggestions =
 36                    command.GetArgumentAutoCompleteSuggestions(split.Length == 2 ? split[1] : null,
 37                        s_AutoCompleteSuggestions);
 38
 039                if (s_AutoCompleteSuggestions == null || s_AutoCompleteSuggestions.Length == 0)
 040                {
 041                    Reset();
 042                }
 43                else
 044                {
 045                    s_CurrentSuggestion = $" {s_AutoCompleteSuggestions[s_AutoCompleteOffset]}";
 046                    s_AutoCompleteOffset++;
 047                    if (s_AutoCompleteOffset >= s_AutoCompleteSuggestions.Length)
 048                    {
 049                        s_AutoCompleteOffset = 0;
 050                    }
 051                }
 52
 053                return true;
 54            }
 55
 56            // Variable Search
 057            ConsoleVariableBase variable = Console.GetVariable(split[0]);
 058            if (variable != null)
 059            {
 060                s_AutoCompleteSuggestions =
 61                    variable.GetArgumentAutoCompleteSuggestions(split.Length == 2 ? split[1] : null,
 62                        s_AutoCompleteSuggestions);
 63
 064                if (s_AutoCompleteSuggestions == null || s_AutoCompleteSuggestions.Length == 0)
 065                {
 066                    Reset();
 067                }
 68                else
 069                {
 070                    s_CurrentSuggestion = $" {s_AutoCompleteSuggestions[s_AutoCompleteOffset]}";
 071                    s_AutoCompleteOffset++;
 072                    if (s_AutoCompleteOffset >= s_AutoCompleteSuggestions.Length)
 073                    {
 074                        s_AutoCompleteOffset = 0;
 075                    }
 076                }
 77
 078                return true;
 79            }
 80
 81            // Wide Search
 082            s_AutoCompleteSuggestions = Console.GetCommandAutoCompleteSuggestions(split[0], s_AutoCompleteSuggestions);
 083            if (s_AutoCompleteSuggestions == null || s_AutoCompleteSuggestions.Length == 0)
 084            {
 085                s_CurrentSuggestion = string.Empty;
 086                s_AutoCompleteOffset = 0;
 087                return false;
 88            }
 89
 90            // TODO : if you have a bad command and a space and a var it will get here and implode on auto
 091            s_CurrentSuggestion = s_AutoCompleteSuggestions[s_AutoCompleteOffset].Substring(inputString.Length);
 092            s_AutoCompleteOffset++;
 093            if (s_AutoCompleteOffset >= s_AutoCompleteSuggestions.Length)
 094            {
 095                s_AutoCompleteOffset = 0;
 096            }
 97
 098            return true;
 099        }
 100
 101        public static void Reset()
 0102        {
 0103            s_AutoCompleteOffset = 0;
 0104            s_AutoCompleteSuggestions = null;
 0105        }
 106    }
 107#endif // UNITY_2022_2_OR_NEWER
 108}