Skip to content
Snippets Groups Projects
Commit fed959a2 authored by Jan Travnicek's avatar Jan Travnicek
Browse files

tune ReadlinePromptCompletion to comply with clang-tidy

parent a1942d8f
No related branches found
No related tags found
1 merge request!95Many clang-tidy fixes
......@@ -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 */
......
......@@ -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 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment