public override bool Execute(AutoCompleteEventArgs e, AutoCompleteSettings settings) { var ignoreTab = e.Character == '\t' && !settings.CompleteBlockOnTab; var ignoreEnter = e.Character == '\r' && !settings.CompleteBlockOnEnter; if (IsInlineCharCompletion || e.IsDelete || ignoreTab || ignoreEnter) { return(false); } var module = e.CodeModule; using (var pane = module.CodePane) { var selection = pane.Selection; var originalCode = module.GetLines(selection); var code = originalCode.Trim().StripStringLiterals(); var hasComment = code.HasComment(out int commentStart); var isDeclareStatement = Regex.IsMatch(code, $"\\b{Tokens.Declare}\\b", RegexOptions.IgnoreCase); var isExitStatement = Regex.IsMatch(code, $"\\b{Tokens.Exit}\\b", RegexOptions.IgnoreCase); var isNamedArg = Regex.IsMatch(code, $"\\b{InputToken}\\:\\=", RegexOptions.IgnoreCase); if ((SkipPreCompilerDirective && code.StartsWith("#")) || isDeclareStatement || isExitStatement || isNamedArg) { return(false); } if (IsMatch(code) && !IsBlockCompleted(module, selection)) { var indent = originalCode.TakeWhile(c => char.IsWhiteSpace(c)).Count(); var newCode = OutputToken.PadLeft(OutputToken.Length + indent, ' '); var stdIndent = IndentBody ? IndenterSettings.Create().IndentSpaces : 0; module.InsertLines(selection.NextLine.StartLine, "\n" + newCode); module.ReplaceLine(selection.NextLine.StartLine, new string(' ', indent + stdIndent)); pane.Selection = new Selection(selection.NextLine.StartLine, indent + stdIndent + 1); e.Handled = true; return(true); } return(false); } }
protected bool IsBlockCompleted(ICodeModule module, Selection selection) { string content; var proc = module.GetProcOfLine(selection.StartLine); if (proc == null) { content = module.GetLines(1, module.CountOfDeclarationLines).StripStringLiterals(); } else { var procKind = module.GetProcKindOfLine(selection.StartLine); var startLine = module.GetProcStartLine(proc, procKind); var lineCount = module.GetProcCountLines(proc, procKind); content = module.GetLines(startLine, lineCount); } var options = RegexOptions.IgnoreCase; var inputPattern = $"(?<!{OutputToken.Replace(InputToken, string.Empty)})\\b{InputToken}\\b"; var inputMatches = Regex.Matches(content, inputPattern, options).Count; var outputMatches = Regex.Matches(content, $"\\b{OutputToken}\\b", options).Count; return(inputMatches > 0 && inputMatches == outputMatches); }
public OutputToken OutputWithDepth(string text, TokenType type, int depth) { var tok = new OutputToken(text, type, depth); Output(tok); return tok; }
public OutputToken Output(string text, TokenType type, object state) { var tok = new OutputToken(text, type) { State = state }; Output(tok); return tok; }
public OutputToken Output(string text, TokenType type) { var tok = new OutputToken(text, type); Output(tok); return tok; }
public OutputToken Output(string text) { var tok = new OutputToken(text); Output(tok); return tok; }
public virtual OutputToken Output(OutputToken tok) { this.output.Add(tok); return tok; }