mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmMakefile: Add CML command spell checking
Use Levenshtein distance to track when the user may have made a typo in a CMake language command.
This commit is contained in:
@@ -17,6 +17,7 @@ skip =
|
||||
Source/kwsys/*,
|
||||
Tests/RunCMake/CPack/tests/DMG_SLA/German.*,
|
||||
Tests/RunCMake/ParseImplicitData/*.input,
|
||||
Tests/RunCMake/cmake_language/call_typo_function.cmake,
|
||||
Tests/StringFileTest/test.utf8,
|
||||
Utilities/cm*,
|
||||
*.pfx,
|
||||
|
||||
@@ -100,6 +100,12 @@ std::string const kCMAKE_CURRENT_LIST_DIR = "CMAKE_CURRENT_LIST_DIR";
|
||||
std::string const kCMAKE_CURRENT_LIST_FILE = "CMAKE_CURRENT_LIST_FILE";
|
||||
std::string const kCMAKE_PARENT_LIST_FILE = "CMAKE_PARENT_LIST_FILE";
|
||||
|
||||
std::string findClosestCommand(std::string const& name,
|
||||
std::vector<std::string> const& commands)
|
||||
{
|
||||
return cmFindClosestString(name, commands);
|
||||
}
|
||||
|
||||
class FileScopeBase
|
||||
{
|
||||
protected:
|
||||
@@ -643,6 +649,11 @@ bool cmMakefile::ExecuteCommand(cmListFileFunction const& lff,
|
||||
if (!cmSystemTools::GetFatalErrorOccurred()) {
|
||||
std::string error =
|
||||
cmStrCat("Unknown CMake command \"", lff.OriginalName(), "\".");
|
||||
std::string const suggestion = findClosestCommand(
|
||||
lff.OriginalName(), this->GetState()->GetCommandNames());
|
||||
if (!suggestion.empty()) {
|
||||
error = cmStrCat(error, " Did you mean: \"", suggestion, "\"?");
|
||||
}
|
||||
this->IssueMessage(MessageType::FATAL_ERROR, error);
|
||||
result = false;
|
||||
cmSystemTools::SetFatalErrorOccurred();
|
||||
|
||||
@@ -25,6 +25,7 @@ run_cmake(call_message_fatal_error)
|
||||
run_cmake(call_no_parameters)
|
||||
run_cmake(call_preserve_arguments)
|
||||
run_cmake(call_unknown_function)
|
||||
run_cmake(call_typo_function)
|
||||
run_cmake(eval_expand_command_name)
|
||||
run_cmake(eval_expanded_command_and_arguments)
|
||||
run_cmake(eval_extra_parameters_between_eval_and_code)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
CMake Error at call_typo_function\.cmake:1 \(mesage\):
|
||||
Unknown CMake command "mesage"\. Did you mean: "message"\?
|
||||
@@ -0,0 +1 @@
|
||||
cmake_language(CALL mesage "hi")
|
||||
Reference in New Issue
Block a user