Verified Commit c49b8bc8 authored by Camil Staps's avatar Camil Staps 🚀

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.
......
......@@ -6,13 +6,14 @@ from Data.Maybe import :: Maybe
from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
:: Request
= { unify :: Maybe String
, name :: Maybe String
, className :: Maybe String
, typeName :: Maybe String
, modules :: Maybe [String]
, libraries :: Maybe ([String], Bool)
, page :: Maybe Int
= { unify :: Maybe String
, name :: Maybe String
, className :: Maybe String
, typeName :: Maybe String
, modules :: Maybe [String]
, libraries :: Maybe [String]
, include_builtins :: Maybe Bool
, page :: Maybe Int
}
:: Response
......
......@@ -11,13 +11,14 @@ derive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,
instance zero Request
where
zero = { unify = Nothing
, name = Nothing
, className = Nothing
, typeName = Nothing
, modules = Nothing
, libraries = Nothing
, page = Nothing
zero = { unify = Nothing
, name = Nothing
, className = Nothing
, typeName = Nothing
, modules = Nothing
, libraries = Nothing
, include_builtins = Nothing
, page = Nothing
}
instance zero Response
......
......@@ -38,13 +38,14 @@ MAX_RESULTS :== 15
CACHE_PREFETCH :== 5
:: RequestCacheKey
= { c_unify :: Maybe Type
, c_name :: Maybe String
, c_className :: Maybe String
, c_typeName :: Maybe String
, c_modules :: Maybe [String]
, c_libraries :: Maybe ([String], Bool)
, c_page :: Maybe Int
= { c_unify :: Maybe Type
, c_name :: Maybe String
, c_className :: Maybe String
, c_typeName :: Maybe String
, c_modules :: Maybe [String]
, c_libraries :: Maybe [String]
, c_include_builtins :: Bool
, c_page :: Int
}
derive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey
......@@ -53,13 +54,14 @@ where toString rck = toString $ toJSON rck
toRequestCacheKey :: Request -> RequestCacheKey
toRequestCacheKey r =
{ c_unify = r.unify >>= parseType o fromString
, c_name = r.name
, 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_unify = r.unify >>= parseType o fromString
, c_name = r.name
, c_className = r.className
, c_typeName = r.typeName
, c_modules = sort <$> r.modules
, 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