Esempio n. 1
0
        public async Task <IEnumerable <Suggestion> > GetSuggestionsAsync(string userText, int cursorPos)
        {
            if (cursorPos < 0 || cursorPos > userText.Length)
            {
                return(new List <Suggestion>());
            }

            var sanitizedText = userText.Substring(0, cursorPos);

            // first, remove anything that might be part of another command
            // look backward for the follow characters and forget everything before them
            // && ;
            sanitizedText = RemoveTextBeforeAndIncluding(sanitizedText, new string[] { "&&", ";" }).Replace("~", shell.HomeDirectory).Trim();

            // c<TAB> -> cd [command]
            // ech<TAB> -> echo [command]
            // cat b<TAB> -> cat bob [file]
            // cat bob; ec[TAB] -> cat bob; echo [file]

            if (sanitizedText.StartsWith("cd"))
            {
                return(CdCompletion.GetCompletions(sanitizedText, shell, cursorPos));
            }
            else if (sanitizedText.StartsWith("." + Path.DirectorySeparatorChar))
            {
                return(ExecutableCompletions.GetCompletions(sanitizedText, shell, cursorPos));
            }
            else
            {
#pragma warning disable VSTHRD003 // Avoid awaiting foreign Tasks
                return(await FileAndDirectoryCompletion.GetCompletionsAsync(sanitizedText, shell, cursorPos, commandsInPath));

#pragma warning restore VSTHRD003 // Avoid awaiting foreign Tasks
            }

            // user defined?
        }
Esempio n. 2
0
        public void InternalFileResolution_ConvertToAbsolute()
        {
            using (var ms = new MemoryStream())
            {
                var fakeShell = new Shell
                {
                    HomeDirectory    = basePath,
                    WorkingDirectory = basePath
                };

                Assert.AreEqual(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), FileAndDirectoryCompletion.ConvertToAbsolute(basePath + "/..", fakeShell));
                Assert.AreEqual(fakeShell.HomeDirectory + Path.DirectorySeparatorChar, FileAndDirectoryCompletion.ConvertToAbsolute("~/", fakeShell));
                Assert.AreEqual(fakeShell.WorkingDirectory + Path.DirectorySeparatorChar, FileAndDirectoryCompletion.ConvertToAbsolute("./", fakeShell));
                Assert.AreEqual(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "bob"), FileAndDirectoryCompletion.ConvertToAbsolute("~/../bob", fakeShell));
            }
        }