1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Seconds -> milliseconds

This commit is contained in:
Patrick Thomson 2018-05-22 16:38:18 -04:00
parent 3eb550ac62
commit dd23a2c513
2 changed files with 5 additions and 4 deletions

View File

@ -25,9 +25,10 @@ import qualified TreeSitter.Node as TS
import qualified TreeSitter.Parser as TS import qualified TreeSitter.Parser as TS
import qualified TreeSitter.Tree as TS import qualified TreeSitter.Tree as TS
newtype Timeout = Seconds Int newtype Timeout = Milliseconds Int
-- Change this to putStrLn if you want to debug the locking/cancellation code. -- Change this to putStrLn if you want to debug the locking/cancellation code.
-- TODO: Someday we should run this all in Eff so that we can 'trace'.
dbg :: String -> IO () dbg :: String -> IO ()
dbg = const (pure ()) dbg = const (pure ())
@ -54,8 +55,8 @@ runParser parser blobSource = unsafeUseAsCStringLen (sourceBytes blobSource) $
-- | Parse 'Source' with the given 'TS.Language' and return its AST. -- | Parse 'Source' with the given 'TS.Language' and return its AST.
-- Returns Nothing if the operation timed out. -- Returns Nothing if the operation timed out.
parseToAST :: (Bounded grammar, Enum grammar) => Timeout -> Ptr TS.Language -> Blob -> IO (Maybe (AST [] grammar)) parseToAST :: (Bounded grammar, Enum grammar) => Timeout -> Ptr TS.Language -> Blob -> IO (Maybe (AST [] grammar))
parseToAST (Seconds s) language Blob{..} = bracket TS.ts_parser_new TS.ts_parser_delete $ \ parser -> do parseToAST (Milliseconds s) language Blob{..} = bracket TS.ts_parser_new TS.ts_parser_delete $ \ parser -> do
let parserTimeout = s * 1000000 let parserTimeout = s * 1000
TS.ts_parser_halt_on_error parser (CBool 1) TS.ts_parser_halt_on_error parser (CBool 1)
TS.ts_parser_set_language parser language TS.ts_parser_set_language parser language

View File

@ -185,7 +185,7 @@ data ParserCancelled = ParserTimedOut deriving (Show, Typeable)
instance Exception ParserCancelled instance Exception ParserCancelled
defaultTimeout :: Timeout defaultTimeout :: Timeout
defaultTimeout = Seconds 5 defaultTimeout = Milliseconds 5000
-- | Parse a 'Blob' in 'IO'. -- | Parse a 'Blob' in 'IO'.
runParser :: Members '[Reader Options, Telemetry, Exc SomeException, IO, Trace] effs => Blob -> Parser term -> Eff effs term runParser :: Members '[Reader Options, Telemetry, Exc SomeException, IO, Trace] effs => Blob -> Parser term -> Eff effs term