Beispiel #1
0
        public static List <ICompletionData> GetCompletionData(TextDocument document, int caretOffset, int argumentIndex = -1)
        {
            List <ICompletionData> completionData = new List <ICompletionData>();

            string syntax = CommandHelper.GetCommandSyntax(document, caretOffset);

            if (string.IsNullOrEmpty(syntax))
            {
                return(null);
            }

            Regex regex = new Regex(@"\(.*?_\.*?\)");             // (CMD_...)

            if (!regex.IsMatch(syntax) && !syntax.ToUpper().Contains("ENABLED") && !syntax.ToUpper().Contains("DISABLED"))
            {
                return(null);
            }

            string[] arguments = syntax.Split(',');

            if (argumentIndex == -1)
            {
                argumentIndex = ArgumentHelper.GetArgumentIndexAtOffset(document, caretOffset);
            }

            if (arguments.Length <= argumentIndex || argumentIndex == -1)
            {
                return(null);
            }

            string currentArgument = arguments[argumentIndex];

            if (regex.IsMatch(currentArgument))
            {
                string mnemonicPrefix = currentArgument.Split('(')[1].Split(')')[0].Trim('.').Trim();

                foreach (string mnemonicConstant in ScriptKeywords.AllMnemonics)
                {
                    if (mnemonicConstant.StartsWith(mnemonicPrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        completionData.Add(new CompletionData(mnemonicConstant));
                    }
                }
            }
            else if (currentArgument.ToUpper().Contains("ENABLED") || currentArgument.ToUpper().Contains("DISABLED"))
            {
                completionData.Add(new CompletionData("ENABLED"));
                completionData.Add(new CompletionData("DISABLED"));
            }

            return(completionData);
        }
Beispiel #2
0
        private void HandleAutocompleteForNextFlag()
        {
            if (!_autocompleteWorker.IsBusy)
            {
                List <object> data = new List <object>
                {
                    Text,
                    CaretOffset,
                    ArgumentHelper.GetArgumentIndexAtOffset(Document, CaretOffset) - 1
                };

                _autocompleteWorker.RunWorkerAsync(data);
            }
        }
Beispiel #3
0
        private string GetFirstLetterOfCurrentArgument()
        {
            try             // TODO: Possibly get rid of this try / catch
            {
                int currentArgumentIndex = ArgumentHelper.GetArgumentIndexAtOffset(Document, CaretOffset);

                if (currentArgumentIndex == -1)
                {
                    return(null);
                }

                string syntax = CommandHelper.GetCommandSyntax(Document, CaretOffset);

                if (string.IsNullOrEmpty(syntax))
                {
                    return(null);
                }

                string[] syntaxArguments = syntax.Split(',');

                if (syntaxArguments.Length < currentArgumentIndex)
                {
                    return(null);
                }

                string currentSyntaxArgument = syntaxArguments[currentArgumentIndex];

                if (!currentSyntaxArgument.Contains("_"))
                {
                    return(null);
                }

                string flagPrefix = currentSyntaxArgument.Split('_')[0].Split('(')[1];

                return(flagPrefix[0].ToString());
            }
            catch
            {
                return(null);
            }
        }
Beispiel #4
0
        private string GetFirstLetterOfLastFlag()
        {
            int currentArgumentIndex = ArgumentHelper.GetArgumentIndexAtOffset(Document, CaretOffset);

            if (currentArgumentIndex == -1 || currentArgumentIndex == 0)
            {
                return(null);
            }

            string prevArgument = ArgumentHelper.GetArgumentFromIndex(Document, CaretOffset, currentArgumentIndex - 1).Trim();

            if (!prevArgument.Contains("_"))
            {
                return(null);
            }

            if (prevArgument.Contains("="))
            {
                prevArgument.Split('=').Last().Trim();
            }

            return(prevArgument[0].ToString());
        }