summaryrefslogtreecommitdiffstats
path: root/src/stat_cache.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2011-11-16 05:38:21 (GMT)
committerNico Weber <nicolasweber@gmx.de>2011-11-16 05:42:34 (GMT)
commitf72a4137f5a9b3ee4001d60888612b22a6a63020 (patch)
tree7901b64ddb1a4def692eb6c151e357367443a720 /src/stat_cache.cc
parentd838f8ed07d5cc2550a8b083ad7e866de49fe45d (diff)
downloadNinja-f72a4137f5a9b3ee4001d60888612b22a6a63020.zip
Ninja-f72a4137f5a9b3ee4001d60888612b22a6a63020.tar.gz
Ninja-f72a4137f5a9b3ee4001d60888612b22a6a63020.tar.bz2
Add spelling suggestions for four cases:
1. For targets, when invoking ninja to build a target. 2. For targets, when doing a "query" command. 3. For command names. 4. For the subcommands of the "targets" command. Also change CmdTargets() to call LookupNode() instead of GetNode() -- since the result was checked for NULL, that's probably what was intended here originally.
Diffstat (limited to 'src/stat_cache.cc')
-rw-r--r--src/stat_cache.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/stat_cache.cc b/src/stat_cache.cc
index 3309837..368f545 100644
--- a/src/stat_cache.cc
+++ b/src/stat_cache.cc
@@ -16,6 +16,7 @@
#include <stdio.h>
+#include "edit_distance.h"
#include "graph.h"
FileStat* StatCache::GetFile(const std::string& path) {
@@ -27,6 +28,23 @@ FileStat* StatCache::GetFile(const std::string& path) {
return file;
}
+FileStat* StatCache::SpellcheckFile(const std::string& path) {
+ const bool kAllowReplacements = true;
+ const int kMaxValidEditDistance = 3;
+
+ int min_distance = kMaxValidEditDistance + 1;
+ FileStat* result = NULL;
+ for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
+ int distance = EditDistance(
+ i->first, path, kAllowReplacements, kMaxValidEditDistance);
+ if (distance < min_distance && i->second->node_) {
+ min_distance = distance;
+ result = i->second;
+ }
+ }
+ return result;
+}
+
void StatCache::Dump() {
for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
FileStat* file = i->second;