@@ -1019,23 +1019,25 @@ CommandInterpreter::VerifyUserMultiwordCmdPath(Args &path, bool leaf_is_command,
1019
1019
}
1020
1020
1021
1021
CommandObjectSP CommandInterpreter::GetFrameLanguageCommand () const {
1022
- if (auto frame_sp = GetExecutionContext ().GetFrameSP ()) {
1023
- auto frame_language = Language::GetPrimaryLanguage (
1024
- frame_sp->GuessLanguage ().AsLanguageType ());
1025
-
1026
- auto it = m_command_dict.find (" language" );
1027
- if (it != m_command_dict.end ()) {
1028
- // The root "language" command.
1029
- CommandObjectSP language_cmd_sp = it->second ;
1030
-
1031
- if (auto *plugin = Language::FindPlugin (frame_language)) {
1032
- // "cplusplus", "objc", etc.
1033
- auto lang_name = plugin->GetPluginName ();
1034
- return language_cmd_sp->GetSubcommandSPExact (lang_name);
1035
- }
1036
- }
1037
- }
1038
- return {};
1022
+ auto frame_sp = GetExecutionContext ().GetFrameSP ();
1023
+ if (!frame_sp)
1024
+ return {};
1025
+ auto frame_language =
1026
+ Language::GetPrimaryLanguage (frame_sp->GuessLanguage ().AsLanguageType ());
1027
+
1028
+ auto it = m_command_dict.find (" language" );
1029
+ if (it == m_command_dict.end ())
1030
+ return {};
1031
+ // The root "language" command.
1032
+ CommandObjectSP language_cmd_sp = it->second ;
1033
+
1034
+ auto *plugin = Language::FindPlugin (frame_language);
1035
+ if (!plugin)
1036
+ return {};
1037
+ // "cplusplus", "objc", etc.
1038
+ auto lang_name = plugin->GetPluginName ();
1039
+
1040
+ return language_cmd_sp->GetSubcommandSPExact (lang_name);
1039
1041
}
1040
1042
1041
1043
CommandObjectSP
@@ -1070,20 +1072,11 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1070
1072
command_sp = pos->second ;
1071
1073
}
1072
1074
1073
- // The `language` subcommand ("language objc", "language cplusplus", etc).
1074
- CommandObjectMultiword *lang_subcmd = nullptr ;
1075
- if (!command_sp) {
1076
- if (auto subcmd_sp = GetFrameLanguageCommand ()) {
1077
- lang_subcmd = subcmd_sp->GetAsMultiwordCommand ();
1078
- command_sp = subcmd_sp->GetSubcommandSPExact (cmd_str);
1079
- }
1080
- }
1081
-
1082
1075
if (!exact && !command_sp) {
1083
1076
// We will only get into here if we didn't find any exact matches.
1084
1077
1085
1078
CommandObjectSP user_match_sp, user_mw_match_sp, alias_match_sp,
1086
- real_match_sp, lang_match_sp ;
1079
+ real_match_sp;
1087
1080
1088
1081
StringList local_matches;
1089
1082
if (matches == nullptr )
@@ -1093,7 +1086,6 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1093
1086
unsigned int num_alias_matches = 0 ;
1094
1087
unsigned int num_user_matches = 0 ;
1095
1088
unsigned int num_user_mw_matches = 0 ;
1096
- unsigned int num_lang_matches = 0 ;
1097
1089
1098
1090
// Look through the command dictionaries one by one, and if we get only one
1099
1091
// match from any of them in toto, then return that, otherwise return an
@@ -1151,41 +1143,49 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1151
1143
user_mw_match_sp = pos->second ;
1152
1144
}
1153
1145
1154
- if (lang_subcmd) {
1155
- num_lang_matches =
1156
- AddNamesMatchingPartialString (lang_subcmd->GetSubcommandDictionary (),
1157
- cmd_str, *matches, descriptions);
1158
- }
1159
-
1160
- if (num_lang_matches == 1 ) {
1161
- cmd.assign (matches->GetStringAtIndex (num_cmd_matches + num_alias_matches +
1162
- num_user_matches +
1163
- num_user_mw_matches));
1164
-
1165
- auto &lang_dict = lang_subcmd->GetSubcommandDictionary ();
1166
- auto pos = lang_dict.find (cmd);
1167
- if (pos != lang_dict.end ())
1168
- lang_match_sp = pos->second ;
1169
- }
1170
-
1171
1146
// If we got exactly one match, return that, otherwise return the match
1172
1147
// list.
1173
1148
1174
1149
if (num_user_matches + num_user_mw_matches + num_cmd_matches +
1175
- num_alias_matches + num_lang_matches ==
1150
+ num_alias_matches ==
1176
1151
1 ) {
1177
1152
if (num_cmd_matches)
1178
1153
return real_match_sp;
1179
1154
else if (num_alias_matches)
1180
1155
return alias_match_sp;
1181
1156
else if (num_user_mw_matches)
1182
1157
return user_mw_match_sp;
1183
- else if (num_user_matches)
1184
- return user_match_sp;
1185
1158
else
1186
- return lang_match_sp;
1159
+ return user_match_sp;
1160
+ }
1161
+ }
1162
+
1163
+ // When no single match is found, attempt to resolve the command as a language
1164
+ // plugin subcommand.
1165
+ if (!command_sp) {
1166
+ // The `language` subcommand ("language objc", "language cplusplus", etc).
1167
+ CommandObjectMultiword *lang_subcmd = nullptr ;
1168
+ if (auto lang_subcmd_sp = GetFrameLanguageCommand ()) {
1169
+ lang_subcmd = lang_subcmd_sp->GetAsMultiwordCommand ();
1170
+ command_sp = lang_subcmd_sp->GetSubcommandSPExact (cmd_str);
1171
+ }
1172
+
1173
+ if (!command_sp && !exact && lang_subcmd) {
1174
+ StringList lang_matches;
1175
+ AddNamesMatchingPartialString (lang_subcmd->GetSubcommandDictionary (),
1176
+ cmd_str, lang_matches, descriptions);
1177
+ if (matches)
1178
+ matches->AppendList (lang_matches);
1179
+ if (lang_matches.GetSize () == 1 ) {
1180
+ const auto &lang_dict = lang_subcmd->GetSubcommandDictionary ();
1181
+ auto pos = lang_dict.find (lang_matches[0 ]);
1182
+ if (pos != lang_dict.end ())
1183
+ return pos->second ;
1184
+ }
1187
1185
}
1188
- } else if (matches && command_sp) {
1186
+ }
1187
+
1188
+ if (matches && command_sp) {
1189
1189
matches->AppendString (cmd_str);
1190
1190
if (descriptions)
1191
1191
descriptions->AppendString (command_sp->GetHelp ());
0 commit comments