public HandlerProvider() { ImportHandler = new ImportHandler(); SearchHandler = new SearchHandler(); AutoCompleteHandler = new AutoCompleteHandler(); DeleteHandler = new DeleteHandler(); }
public IEnumerable <ICompletionData> GetCompletions(string editorText) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if (cursorOffset == -1) { throw new ArgumentException("Editor text should contain a $"); } TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(new BufferParser(_solution), new Logger()); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, }; return(provider.CreateProvider(request)); }
public IEnumerable <CompletionData> GetCompletions(string editorText, bool includeImportableTypes) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if (cursorOffset == -1) { throw new ArgumentException("Editor text should contain a $"); } TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(_solution, new BufferParser(_solution), new Logger(Verbosity.Quiet), new OmniSharpConfiguration()); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, WantDocumentationForEveryCompletionResult = false, WantImportableTypes = includeImportableTypes, WantMethodHeader = true, WantReturnType = true, WantSnippet = true }; return(provider.CreateProvider(request)); }
void CmdTabOrComplete() { bool complete = false; AutoCompleteEvent = AutoCompleteHelper.HandleAutoComplete; if (AutoCompleteEvent != null) { if (TabAtStartCompletes) { complete = true; } else { for (int i = 0; i < cursor; i++) { if (!Char.IsWhiteSpace(text[i])) { complete = true; break; } } } string prefix; if (complete) { if (text.ToString().Contains(' ')) { prefix = text.ToString().Split(' ').Last(); } else { prefix = text.ToString(); } Completion completion = AutoCompleteEvent(prefix.ToLower()); string[] completions = completion.Result; if (completions == null) { return; } int ncompletions = completions.Length; if (ncompletions == 0) { return; } if (completions.Length == 1) { InsertTextAtCursor(completions[0]); } else { int last = -1; for (int p = 0; p < completions[0].Length; p++) { char c = completions[0][p]; for (int i = 1; i < ncompletions; i++) { if (completions[i].Length < p) { goto mismatch; } if (completions[i][p] != c) { goto mismatch; } } last = p; } mismatch: if (last != -1) { InsertTextAtCursor(completions[0].Substring(0, last + 1)); } Console.WriteLine(); int countPerline = 3; int cntr = 0; foreach (string s in completions) { Console.Write(completion.Prefix); Console.Write(s); Console.Write(' '); cntr++; if (cntr == countPerline) { Console.WriteLine(); cntr = 0; } } Console.WriteLine(); Console.WriteLine(); Render(); ForceCursor(cursor); } } else { HandleChar('\t'); } } else { HandleChar('t'); } }
public void SetAutoCompleteCommandList(List <string> commands) { _commands = commands; AutoCompleteEvent = AutoCompleteMe; }
public static String GetLine(this IInteractivity interactivity, String prompt, AutoCompleteHandler handler) { interactivity.AutoComplete += handler; var line = interactivity.GetLine(prompt); interactivity.AutoComplete -= handler; return(line); }
private string[] get_command(string prompt = "> ") { var cmd = get_string(prompt); return(AutoCompleteHandler.Tokenize(cmd, AutoCompleteHandler.seps).ToArray()); }
internal bool DoInteractive() { ach = new AutoCompleteHandler(this); ReadLine.AutoCompletionHandler = ach; ReadLine.HistoryEnabled = true; while (true) { dump_state(); string[] cmd; while ((cmd = get_command()).Length == 0) { ; } // handle the command int idx = 0; if (cmd[idx] == "select.type") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); s.ts = instantiate_type(s.ts); } else if (cmd[idx] == "select.method") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); s.ms = ParseMethod(cmd, ref idx); } else if (cmd[idx] == "select.module") { idx++; s.m = ParseModule2(cmd, ref idx); } else if (cmd[idx] == "quit" || cmd[idx] == "q") { return(false); } else if (cmd[idx] == "continue" || cmd[idx] == "c") { return(true); } else if (cmd[idx] == "assemble.method") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); s.ms = ParseMethod(cmd, ref idx); t.InitIntcalls(); tst.r = new libtysila5.CachingRequestor(s.m.m); tst.st = new libtysila5.StringTable("Interactive", s.ms.ms.m.al, Program.t); StringBuilder sb = new StringBuilder(); libtysila5.libtysila.AssembleMethod(s.ms.ms, new binary_library.binary.FlatBinaryFile(), t, tst, sb); Console.WriteLine(sb.ToString()); } else if (cmd[idx] == "list.methods") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); foreach (var meth in s.ts.AllMethods.Keys) { Console.WriteLine(meth); } } else if (cmd[idx] == "list.fields") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); foreach (var fld in s.ts.AllFields.Keys) { Console.WriteLine(s.ts.AllFields[fld].ToString()); } Console.WriteLine(" Total size: " + s.ts.TypeSize.ToString("X")); } else if (cmd[idx] == "list.vmethods") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); var vmeths = libtysila5.layout.Layout.GetVirtualMethodDeclarations(s.ts); libtysila5.layout.Layout.ImplementVirtualMethods(s.ts, vmeths); foreach (var vmeth in vmeths) { var impl_ms = vmeth.impl_meth; string impl_target = (impl_ms == null) ? "__cxa_pure_virtual" : impl_ms.MethodReferenceAlias; var ims = new InteractiveMethodSpec(vmeth.unimpl_meth); Console.WriteLine(ims.Name + " -> " + impl_target); } } else if (cmd[idx] == "list.interfaces") { idx++; s.m = ParseModule(cmd, ref idx); s.ts = ParseType(cmd, ref idx); foreach (var ii in s.ts.ts.ImplementedInterfaces) { Console.WriteLine(((InteractiveTypeSpec)ii).Name); } } else if (cmd[idx] == "implement.interface") { idx++; InteractiveState istate = new InteractiveState(); istate.m = ParseModule(cmd, ref idx); istate.ts = ParseType(cmd, ref idx, istate); t.InitIntcalls(); tst.r = new libtysila5.CachingRequestor(s.m.m); var iis = libtysila5.layout.Layout.ImplementInterface(s.ts, istate.ts, t, tst); foreach (var ii in iis) { Console.WriteLine(((InteractiveMethodSpec)ii.InterfaceMethod).Name + " -> " + ii.TargetName); } } else { Console.WriteLine("Unknown command: " + cmd[idx]); } } throw new NotImplementedException(); return(false); }
void CmdTabOrComplete() { bool complete = false; AutoCompleteEvent = AutoCompleteHelper.HandleAutoComplete; if (AutoCompleteEvent != null) { if (TabAtStartCompletes) complete = true; else { for (int i = 0; i < cursor; i++) { if (!Char.IsWhiteSpace(text[i])) { complete = true; break; } } } string prefix; if (complete) { if (text.ToString().Contains(' ')) { prefix = text.ToString().Split(' ').Last(); } else { prefix = text.ToString(); } Completion completion = AutoCompleteEvent(prefix.ToLower()); string[] completions = completion.Result; if (completions == null) return; int ncompletions = completions.Length; if (ncompletions == 0) return; if (completions.Length == 1) { InsertTextAtCursor(completions[0]); } else { int last = -1; for (int p = 0; p < completions[0].Length; p++) { char c = completions[0][p]; for (int i = 1; i < ncompletions; i++) { if (completions[i].Length < p) goto mismatch; if (completions[i][p] != c) { goto mismatch; } } last = p; } mismatch: if (last != -1) { InsertTextAtCursor(completions[0].Substring(0, last + 1)); } Console.WriteLine(); int countPerline = 3; int cntr = 0; foreach (string s in completions) { Console.Write(completion.Prefix); Console.Write(s); Console.Write(' '); cntr++; if (cntr == countPerline) { Console.WriteLine(); cntr = 0; } } Console.WriteLine(); Console.WriteLine(); Render(); ForceCursor(cursor); } } else HandleChar('\t'); } else HandleChar('t'); }