Verified Commit c49b8bc8 authored by Camil Staps's avatar Camil Staps 🦆
Browse files

Add include_builtins field

parent 8394d109
......@@ -127,9 +127,8 @@ JSON request with at least one of the following fields:
* `name`, the name of the function to search for.
* `className`, the name of the class to search for.
* `typeName`, the name of the type to search for.
* `libraries`, a list of two elements:
* A list of names of libraries to search in
* A boolean, whether language builtins should be searched or not.
* `libraries`, a list of names of libraries to search in.
* `include_builtins`, a boolean, whether language builtins should be searched or not.
* `modules`, a list of names of modules to search in.
* `page`: 0 for the first *n* results, 1 for the next *n*, etc.
......
......@@ -11,7 +11,8 @@ from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
, className :: Maybe String
, typeName :: Maybe String
, modules :: Maybe [String]
, libraries :: Maybe ([String], Bool)
, libraries :: Maybe [String]
, include_builtins :: Maybe Bool
, page :: Maybe Int
}
......
......@@ -17,6 +17,7 @@ where
, typeName = Nothing
, modules = Nothing
, libraries = Nothing
, include_builtins = Nothing
, page = Nothing
}
......
......@@ -43,8 +43,9 @@ CACHE_PREFETCH :== 5
, c_className :: Maybe String
, c_typeName :: Maybe String
, c_modules :: Maybe [String]
, c_libraries :: Maybe ([String], Bool)
, c_page :: Maybe Int
, c_libraries :: Maybe [String]
, c_include_builtins :: Bool
, c_page :: Int
}
derive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey
......@@ -58,8 +59,9 @@ toRequestCacheKey r =
, c_className = r.className
, c_typeName = r.typeName
, c_modules = sort <$> r.modules
, c_libraries = appFst sort <$> r.libraries
, c_page = r.page <|> Just 0
, c_libraries = sort <$> r.libraries
, c_include_builtins = fromJust (r.include_builtins <|> Just True)
, c_page = fromJust (r.page <|> Just 0)
}
Start w
......@@ -135,7 +137,7 @@ where
# w = writeCache Brief req` resp` w
= cachePages key (npages - 1) (i + 1) response keep w
where
req` = { key & c_page = ((+) i) <$> (key.c_page <|> pure 0) }
req` = { key & c_page = key.c_page + i }
resp` =
{ response
& more_available = Just $ max 0 (length results - MAX_RESULTS)
......@@ -153,9 +155,10 @@ where
suggs _ _ _ = Nothing
search :: !Request !TypeDB -> [Result]
search {unify,name,className,typeName,modules,libraries,page} db
search {unify,name,className,typeName,modules,libraries,page,include_builtins} db
# include_builtins = fromJust (include_builtins <|> Just True)
# db = case libraries of
(Just ls) = filterLocations (isLibMatch ls) db
(Just ls) = filterLocations (isLibMatch include_builtins ls) db
Nothing = db
# db = case modules of
(Just ms) = filterLocations (isModMatch ms) db
......@@ -387,9 +390,9 @@ where
isModMatch mods (Location _ mod _ _ _) = isMember mod mods
isModMatch _ (Builtin _) = False
isLibMatch :: (![String], !Bool) Location -> Bool
isLibMatch (libs,_) (Location lib _ _ _ _) = any (\l -> indexOf l lib == 0) libs
isLibMatch (_,blti) (Builtin _) = blti
isLibMatch :: !Bool ![String] Location -> Bool
isLibMatch _ libs (Location lib _ _ _ _) = any (\l -> indexOf l lib == 0) libs
isLibMatch blti _ (Builtin _) = blti
loc :: Location -> LocationResult
loc (Location lib mod ln iln _) = (lib, mod, ln, iln)
......
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