diff --git a/aql2/src/prompt/ReadlinePromptCompletion.cpp b/aql2/src/prompt/ReadlinePromptCompletion.cpp index e1d2bd5c1b67bf05b7cea97ecb3ee0535b514727..d52c1dfedf8ca4f885ed6e5ff86cb7b2b3ef1f82 100644 --- a/aql2/src/prompt/ReadlinePromptCompletion.cpp +++ b/aql2/src/prompt/ReadlinePromptCompletion.cpp @@ -53,35 +53,39 @@ std::set < std::string > ReadlinePromptCompletion::filter_completions ( const st /* ========================================================================= */ +bool ReadlinePromptCompletion::masterCommandCompletionTest ( const ext::string & line, const int start, const std::string & expectation ) { + return line.starts_with ( expectation ) && ( unsigned ) start == expectation.length ( ) + 1; +} + ReadlinePromptCompletion::CompletionContext ReadlinePromptCompletion::context ( const char *text, const int start, const int end ) { ext::string line ( rl_line_buffer ); if ( start == 0 ) return CompletionContext::COMMAND; - if ( line.starts_with ( "introspect" ) && start == 11 ) + if ( masterCommandCompletionTest ( line, start, "introspect" ) ) return CompletionContext::COMMAND_INTROSPECT; - else if ( line.starts_with ( "set" ) && start == 4 ) + else if ( masterCommandCompletionTest ( line, start, "set" ) ) return CompletionContext::SET; - else if ( line.starts_with ( "introspect overloads" ) && start == 21 ) + else if ( masterCommandCompletionTest ( line, start, "introspect overloads" ) ) return CompletionContext::ALGORITHM; - else if ( line.starts_with ( "introspect variables" ) && start == 21 ) + else if ( masterCommandCompletionTest ( line, start, "introspect variables" ) ) return CompletionContext::VARIABLE; - else if ( line.starts_with ( "introspect bindings" ) && start == 20 ) + else if ( masterCommandCompletionTest ( line, start, "introspect bindings" ) ) return CompletionContext::BINDING; - else if ( line.starts_with ( "introspect algorithms" ) && start == 22 ) + else if ( masterCommandCompletionTest ( line, start, "introspect algorithms" ) ) return CompletionContext::ALGORITHM_GROUP; - else if ( line.starts_with ( "introspect datatypes" ) && start == 21 ) + else if ( masterCommandCompletionTest ( line, start, "introspect datatypes" ) ) return CompletionContext::DATATYPE_GROUP; /* TODO - else if ( line.starts_with ( "introspect casts" ) && start == 17 ) + else if ( masterCommandCompletionTest ( line, start, "introspect casts" ) ) */ if ( end - start > 0 && text [ 0 ] == '$' ) @@ -98,7 +102,7 @@ ReadlinePromptCompletion::CompletionContext ReadlinePromptCompletion::context ( if ( p >= rl_line_buffer && ( *p == '|' || *p == '(' ) ) return CompletionContext::ALGORITHM; - if ( line.starts_with ( "execute" ) && start == 8 ) + if ( masterCommandCompletionTest ( line, start, "execute" ) ) return CompletionContext::ALGORITHM; /* undecided, fallback to filepath */ diff --git a/aql2/src/prompt/ReadlinePromptCompletion.h b/aql2/src/prompt/ReadlinePromptCompletion.h index e7f65e9111e1d7f7979dcea324d27b2cc9ea8879..b9f0fb2aa58009e571c4f7e887135778436fa3f6 100644 --- a/aql2/src/prompt/ReadlinePromptCompletion.h +++ b/aql2/src/prompt/ReadlinePromptCompletion.h @@ -25,7 +25,7 @@ class ReadlinePromptCompletion { static std::set < std::string > fetchAlgorithmsFullyQualifiedName ( const char *text ) { std::set < std::string > fullyQualifiedNames; - for ( const std::pair < std::string, std::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { + for ( const ext::pair < std::string, ext::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { fullyQualifiedNames.insert ( algo.first ); } @@ -35,7 +35,7 @@ class ReadlinePromptCompletion { static std::set < std::string > fetchAlgorithmsLastSegmentName ( const char *text ) { std::map < std::string, unsigned > collisions; - for ( const std::pair < std::string, std::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { + for ( const ext::pair < std::string, ext::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { size_t pos = algo.first.find_last_of ( ':' ); if ( pos != std::string::npos ) collisions [ algo.first.substr ( pos + 1 ) ] += 1; @@ -52,7 +52,7 @@ class ReadlinePromptCompletion { static std::set < std::string > fetchAlgorithmGroups ( const char *text ) { std::set < std::string > res; - for ( const std::pair < std::string, std::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { + for ( const ext::pair < std::string, ext::vector < std::string > > & algo : abstraction::Registry::listAlgorithms ( ) ) { std::set < std::string > groups = getGroups ( algo.first ); res.insert ( groups.begin ( ), groups.end ( ) ); } @@ -123,9 +123,10 @@ public: }; static char** readline_completion ( const char *text, int start, int end ); - static CompletionContext context ( const char *text, const int start, const int end ); + static CompletionContext context ( const char *text, int start, int end ); private: + static bool masterCommandCompletionTest ( const ext::string & line, int start, const std::string & expectation ); static std::set < std::string > addPrefix ( const std::set < std::string > & collection, const std::string & prefix ); static std::set < std::string > getGroups ( const std::string & qualified_name ); static std::set < std::string > filter_completions ( const std::set < std::string > & choices, const char *text );