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