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 ...@@ -278,7 +278,7 @@ filterName :: !String !*CloogleDB -> *CloogleDB
filterExactName :: !String !*CloogleDB -> *CloogleDB filterExactName :: !String !*CloogleDB -> *CloogleDB
filterUnifying :: !Type !*CloogleDB -> *CloogleDB filterUnifying :: !Type !*CloogleDB -> *CloogleDB
filterUsages :: ![String] !*CloogleDB -> *CloogleDB filterUsages :: !(*CloogleDB -> *CloogleDB) ![String] !*CloogleDB -> *CloogleDB
allTypeSynonyms :: !*CloogleDB -> *(Map Name [TypeDef], *CloogleDB) allTypeSynonyms :: !*CloogleDB -> *(Map Name [TypeDef], *CloogleDB)
alwaysUniquePredicate :: !*CloogleDB -> *(String -> Bool, *CloogleDB) alwaysUniquePredicate :: !*CloogleDB -> *(String -> Bool, *CloogleDB)
......
...@@ -445,13 +445,17 @@ where ...@@ -445,13 +445,17 @@ where
typeComplexity (Arrow (Just t)) = 5.0 + typeComplexity t typeComplexity (Arrow (Just t)) = 5.0 + typeComplexity t
typeComplexity (Arrow Nothing) = 5.0 typeComplexity (Arrow Nothing) = 5.0
filterUsages :: ![String] !*CloogleDB -> *CloogleDB filterUsages :: !(*CloogleDB -> *CloogleDB) ![String] !*CloogleDB -> *CloogleDB
filterUsages names wrap=:{db,name_map} filterUsages filter names wrap=:{name_map}
// For each name, the corresponding entries // For each name, the corresponding entries
# idxss = map (fromMaybe [] o flip get name_map) names # 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 // For all lists of entries, the corresponding usages
# (entriess,db) = mapSt 'DB'.getIndices idxss db # (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 # usagess = map (foldr mergeUnion [] o map \e -> getUsages e.value) entriess
// AND all usages together // AND all usages together
# usages = case usagess of # usages = case usagess of
...@@ -462,7 +466,7 @@ filterUsages names wrap=:{db,name_map} ...@@ -462,7 +466,7 @@ filterUsages names wrap=:{db,name_map}
FunctionEntry {fe_typedef=Just i} -> i FunctionEntry {fe_typedef=Just i} -> i
FunctionEntry {fe_class=Just i} -> i FunctionEntry {fe_class=Just i} -> i
_ -> u) \\ u <- usages & {value=e} <- es] _ -> 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} = {wrap & db=db}
where where
getUsages :: !CloogleEntry -> [Index] getUsages :: !CloogleEntry -> [Index]
...@@ -473,13 +477,13 @@ where ...@@ -473,13 +477,13 @@ where
getUsages _ = [] getUsages _ = []
// Efficient union on sorted lists // Efficient union on sorted lists
mergeUnion :: !['DB'.Index] !['DB'.Index] -> ['DB'.Index] mergeUnion :: ![a] ![a] -> [a] | < a
mergeUnion [] is = is mergeUnion [] is = is
mergeUnion is [] = is mergeUnion is [] = is
mergeUnion orgis=:['DB'.Index i:is] orgjs=:['DB'.Index j:js] mergeUnion orgis=:[i:is] orgjs=:[j:js]
| i < j = ['DB'.Index i:mergeUnion is orgjs] | i < j = [i:mergeUnion is orgjs]
| i > j = ['DB'.Index j:mergeUnion orgis js] | i > j = [j:mergeUnion orgis js]
| otherwise = ['DB'.Index i:mergeUnion is js] | otherwise = [i:mergeUnion is js]
// Efficient intersection on sorted lists // Efficient intersection on sorted lists
mergeIntersect :: !['DB'.Index] !['DB'.Index] -> ['DB'.Index] mergeIntersect :: !['DB'.Index] !['DB'.Index] -> ['DB'.Index]
......
...@@ -37,7 +37,7 @@ import Cloogle.DB ...@@ -37,7 +37,7 @@ import Cloogle.DB
| SSUnify Type | SSUnify Type
| SSTypeName String | SSTypeName String
| SSClassName String | SSClassName String
| SSUsing [String] | SSUsing (*CloogleDB -> *CloogleDB) [String]
| SSAnd SearchStrategy SearchStrategy | SSAnd SearchStrategy SearchStrategy
addStrategy :: (Maybe SearchStrategy) SearchStrategy -> SearchStrategy addStrategy :: (Maybe SearchStrategy) SearchStrategy -> SearchStrategy
...@@ -50,7 +50,7 @@ searchStrategy (SSName n) db = filterName n db ...@@ -50,7 +50,7 @@ searchStrategy (SSName n) db = filterName n db
searchStrategy (SSUnify t) db = filterUnifying t db searchStrategy (SSUnify t) db = filterUnifying t db
searchStrategy (SSTypeName n) db = filterDB (\ce->ce=:(TypeDefEntry _)) $ filterExactName n db searchStrategy (SSTypeName n) db = filterDB (\ce->ce=:(TypeDefEntry _)) $ filterExactName n db
searchStrategy (SSClassName n) db = filterDB (\ce->ce=:(ClassEntry _)) $ 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 searchStrategy (SSAnd a b) db = searchStrategy b $ searchStrategy a db
search :: !Request !*CloogleDB -> *([Result], *CloogleDB) search :: !Request !*CloogleDB -> *([Result], *CloogleDB)
...@@ -59,15 +59,13 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built ...@@ -59,15 +59,13 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built
# include_core = fromMaybe DEFAULT_INCLUDE_CORE include_core # include_core = fromMaybe DEFAULT_INCLUDE_CORE include_core
# include_apps = fromMaybe DEFAULT_INCLUDE_APPS include_apps # include_apps = fromMaybe DEFAULT_INCLUDE_APPS include_apps
// Initial filters // Initial filters
# cdb = if include_core cdb (excludeCore cdb) # initfilter =
# cdb = if include_apps cdb (excludeApps cdb) if include_core id excludeCore o
# cdb = case libraries of if include_apps id excludeApps o
Just ls -> filterLibraries ls cdb (case libraries of Just ls -> filterLibraries ls; Nothing -> id) o
Nothing -> cdb (case modules of Just ms -> filterModules ms; Nothing -> id) o
# cdb = case modules of if include_builtins includeBuiltins excludeBuiltins
Just ms -> filterModules ms cdb # cdb = initfilter cdb
Nothing -> cdb
# cdb = if include_builtins includeBuiltins excludeBuiltins cdb
// Search strategy // Search strategy
# strat = SSIdentity # strat = SSIdentity
// Name search // Name search
...@@ -82,7 +80,7 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built ...@@ -82,7 +80,7 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built
# mbType = snd <$> mbPreppedType # mbType = snd <$> mbPreppedType
# strat = addStrategy (SSUnify <$> mbType) strat # strat = addStrategy (SSUnify <$> mbType) strat
// Usage search // Usage search
# strat = addStrategy (SSUsing <$> using) strat # strat = addStrategy (SSUsing initfilter <$> using) strat
// Search and return results // Search and return results
# cdb = searchStrategy strat cdb # cdb = searchStrategy strat cdb
# cdb = removeContainedEntries 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