1
- {-# LANGUAGE ForeignFunctionInterface, OverloadedStrings #-}
1
+ {-# LANGUAGE CPP, ForeignFunctionInterface, OverloadedStrings #-}
2
2
3
3
module NgxExport.Log.Base (LogLevel (.. )
4
4
,logG
@@ -18,6 +18,15 @@ import Foreign.Ptr
18
18
import Control.Arrow
19
19
import Data.Char
20
20
21
+ -- an ugly workaround of haskell-language-server's
22
+ -- [bug](https://github.com/haskell/haskell-language-server/issues/365),
23
+ -- this lets hls work with Log.hs without errors
24
+ #ifdef __GHCIDE__
25
+ #define C_LOG_STUB(f) \
26
+ f :: Ptr () -> CUIntPtr -> CString -> CSize -> IO () ; \
27
+ f _ _ _ _ = return ()
28
+ #endif
29
+
21
30
-- | Log severity levels.
22
31
--
23
32
-- Being applied to a certain constructor, function 'fromEnum' returns the value
@@ -32,8 +41,12 @@ data LogLevel = LogStderr
32
41
| LogInfo
33
42
| LogDebug deriving Enum
34
43
44
+ #ifdef __GHCIDE__
45
+ C_LOG_STUB (c_log)
46
+ #else
35
47
foreign import ccall unsafe " plugin_ngx_http_haskell_log"
36
48
c_log :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
49
+ #endif
37
50
38
51
-- | Logs a message to the global Nginx log.
39
52
logG :: LogLevel -- ^ Log severity level
@@ -45,8 +58,12 @@ logG l msg = do
45
58
B. unsafeUseAsCStringLen msg $
46
59
\ (x, i) -> c_log c (fromIntegral $ fromEnum l) x $ fromIntegral i
47
60
61
+ #ifdef __GHCIDE__
62
+ C_LOG_STUB (c_log_r)
63
+ #else
48
64
foreign import ccall unsafe " plugin_ngx_http_haskell_log_r"
49
65
c_log_r :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
66
+ #endif
50
67
51
68
-- | Logs a message to the request's Nginx log.
52
69
--
0 commit comments