コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: CodeWriterBase.cs プロジェクト: JamesDunne/Asynq
 public OutputToken OutputWithDepth(string text, TokenType type, int depth)
 {
     var tok = new OutputToken(text, type, depth);
     Output(tok);
     return tok;
 }
コード例 #4
0
ファイル: CodeWriterBase.cs プロジェクト: JamesDunne/Asynq
 public OutputToken Output(string text, TokenType type, object state)
 {
     var tok = new OutputToken(text, type) { State = state };
     Output(tok);
     return tok;
 }
コード例 #5
0
ファイル: CodeWriterBase.cs プロジェクト: JamesDunne/Asynq
 public OutputToken Output(string text, TokenType type)
 {
     var tok = new OutputToken(text, type);
     Output(tok);
     return tok;
 }
コード例 #6
0
ファイル: CodeWriterBase.cs プロジェクト: JamesDunne/Asynq
 public OutputToken Output(string text)
 {
     var tok = new OutputToken(text);
     Output(tok);
     return tok;
 }
コード例 #7
0
ファイル: CodeWriterBase.cs プロジェクト: JamesDunne/Asynq
 public virtual OutputToken Output(OutputToken tok)
 {
     this.output.Add(tok);
     return tok;
 }