Verified Commit a4a8a880 authored by Camil Staps's avatar Camil Staps 🙂

In using queries, don't return usages of results that are filtered out (e.g.,...

In using queries, don't return usages of results that are filtered out (e.g., searching 'using Text' would return things that use Text in clean-ide even when include_apps was False)
parent 4bff3717
......@@ -278,7 +278,7 @@ filterName :: !String !*CloogleDB -> *CloogleDB
filterExactName :: !String !*CloogleDB -> *CloogleDB
filterUnifying :: !Type !*CloogleDB -> *CloogleDB
filterUsages :: ![String] !*CloogleDB -> *CloogleDB
filterUsages :: !(*CloogleDB -> *CloogleDB) ![String] !*CloogleDB -> *CloogleDB
allTypeSynonyms :: !*CloogleDB -> *(Map Name [TypeDef], *CloogleDB)
alwaysUniquePredicate :: !*CloogleDB -> *(String -> Bool, *CloogleDB)
......
......@@ -445,13 +445,17 @@ where
typeComplexity (Arrow (Just t)) = 5.0 + typeComplexity t
typeComplexity (Arrow Nothing) = 5.0
filterUsages :: ![String] !*CloogleDB -> *CloogleDB
filterUsages names wrap=:{db,name_map}
filterUsages :: !(*CloogleDB -> *CloogleDB) ![String] !*CloogleDB -> *CloogleDB
filterUsages filter names wrap=:{name_map}
// For each name, the corresponding entries
# idxss = map (fromMaybe [] o flip get name_map) names
# db = 'DB'.searchIndices Intersect (sort [(i,[(ExactResult,1)]) \\ is <- idxss, i <- is]) db
# nameidxs = sort [(i,[(ExactResult,1)]) \\ is <- idxss, i <- is]
# wrap=:{db} = filter wrap
# db = 'DB'.searchIndices Intersect nameidxs db
// For all lists of entries, the corresponding usages
# (entriess,db) = mapSt 'DB'.getIndices idxss db
# wrap & db = db
# wrap=:{db} = filter $ resetDB wrap
# usagess = map (foldr mergeUnion [] o map \e -> getUsages e.value) entriess
// AND all usages together
# usages = case usagess of
......@@ -462,7 +466,7 @@ filterUsages names wrap=:{db,name_map}
FunctionEntry {fe_typedef=Just i} -> i
FunctionEntry {fe_class=Just i} -> i
_ -> u) \\ u <- usages & {value=e} <- es]
# db = 'DB'.searchIndices AddExcluded [(u,[]) \\ u <- usages] db
# db = 'DB'.searchIndices Intersect (mergeUnion nameidxs [(u,[]) \\ u <- usages]) db
= {wrap & db=db}
where
getUsages :: !CloogleEntry -> [Index]
......@@ -473,13 +477,13 @@ where
getUsages _ = []
// Efficient union on sorted lists
mergeUnion :: !['DB'.Index] !['DB'.Index] -> ['DB'.Index]
mergeUnion :: ![a] ![a] -> [a] | < a
mergeUnion [] is = is
mergeUnion is [] = is
mergeUnion orgis=:['DB'.Index i:is] orgjs=:['DB'.Index j:js]
| i < j = ['DB'.Index i:mergeUnion is orgjs]
| i > j = ['DB'.Index j:mergeUnion orgis js]
| otherwise = ['DB'.Index i:mergeUnion is js]
mergeUnion orgis=:[i:is] orgjs=:[j:js]
| i < j = [i:mergeUnion is orgjs]
| i > j = [j:mergeUnion orgis js]
| otherwise = [i:mergeUnion is js]
// Efficient intersection on sorted lists
mergeIntersect :: !['DB'.Index] !['DB'.Index] -> ['DB'.Index]
......
......@@ -37,7 +37,7 @@ import Cloogle.DB
| SSUnify Type
| SSTypeName String
| SSClassName String
| SSUsing [String]
| SSUsing (*CloogleDB -> *CloogleDB) [String]
| SSAnd SearchStrategy SearchStrategy
addStrategy :: (Maybe SearchStrategy) SearchStrategy -> SearchStrategy
......@@ -50,7 +50,7 @@ searchStrategy (SSName n) db = filterName n db
searchStrategy (SSUnify t) db = filterUnifying t db
searchStrategy (SSTypeName n) db = filterDB (\ce->ce=:(TypeDefEntry _)) $ filterExactName n db
searchStrategy (SSClassName n) db = filterDB (\ce->ce=:(ClassEntry _)) $ filterExactName n db
searchStrategy (SSUsing ns) db = filterUsages ns db
searchStrategy (SSUsing f ns) db = filterUsages f ns db
searchStrategy (SSAnd a b) db = searchStrategy b $ searchStrategy a db
search :: !Request !*CloogleDB -> *([Result], *CloogleDB)
......@@ -59,15 +59,13 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built
# include_core = fromMaybe DEFAULT_INCLUDE_CORE include_core
# include_apps = fromMaybe DEFAULT_INCLUDE_APPS include_apps
// Initial filters
# cdb = if include_core cdb (excludeCore cdb)
# cdb = if include_apps cdb (excludeApps cdb)
# cdb = case libraries of
Just ls -> filterLibraries ls cdb
Nothing -> cdb
# cdb = case modules of
Just ms -> filterModules ms cdb
Nothing -> cdb
# cdb = if include_builtins includeBuiltins excludeBuiltins cdb
# initfilter =
if include_core id excludeCore o
if include_apps id excludeApps o
(case libraries of Just ls -> filterLibraries ls; Nothing -> id) o
(case modules of Just ms -> filterModules ms; Nothing -> id) o
if include_builtins includeBuiltins excludeBuiltins
# cdb = initfilter cdb
// Search strategy
# strat = SSIdentity
// Name search
......@@ -82,7 +80,7 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built
# mbType = snd <$> mbPreppedType
# strat = addStrategy (SSUnify <$> mbType) strat
// Usage search
# strat = addStrategy (SSUsing <$> using) strat
# strat = addStrategy (SSUsing initfilter <$> using) strat
// Search and return results
# cdb = searchStrategy strat cdb
# cdb = removeContainedEntries cdb
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment