Skip to content

Commit 132868f

Browse files
committed
workaround of hls bug related to linking of TH code depending on C code
(see haskell/haskell-language-server#365)
1 parent 14cd449 commit 132868f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ jobs:
3737
experimental: true
3838
steps:
3939
- name: Checkout
40-
uses: actions/checkout@v2
40+
uses: actions/checkout@v3
4141
- name: Install GHC and Cabal
42-
uses: haskell/actions/setup@v1
42+
uses: haskell/actions/setup@v2
4343
with:
4444
ghc-version: ${{ matrix.ghc }}
4545
cabal-version: ${{ matrix.cabal }}

NgxExport/Log/Base.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE ForeignFunctionInterface, OverloadedStrings #-}
1+
{-# LANGUAGE CPP, ForeignFunctionInterface, OverloadedStrings #-}
22

33
module NgxExport.Log.Base (LogLevel (..)
44
,logG
@@ -18,6 +18,15 @@ import Foreign.Ptr
1818
import Control.Arrow
1919
import Data.Char
2020

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+
2130
-- | Log severity levels.
2231
--
2332
-- Being applied to a certain constructor, function 'fromEnum' returns the value
@@ -32,8 +41,12 @@ data LogLevel = LogStderr
3241
| LogInfo
3342
| LogDebug deriving Enum
3443

44+
#ifdef __GHCIDE__
45+
C_LOG_STUB(c_log)
46+
#else
3547
foreign import ccall unsafe "plugin_ngx_http_haskell_log"
3648
c_log :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
49+
#endif
3750

3851
-- | Logs a message to the global Nginx log.
3952
logG :: LogLevel -- ^ Log severity level
@@ -45,8 +58,12 @@ logG l msg = do
4558
B.unsafeUseAsCStringLen msg $
4659
\(x, i) -> c_log c (fromIntegral $ fromEnum l) x $ fromIntegral i
4760

61+
#ifdef __GHCIDE__
62+
C_LOG_STUB(c_log_r)
63+
#else
4864
foreign import ccall unsafe "plugin_ngx_http_haskell_log_r"
4965
c_log_r :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
66+
#endif
5067

5168
-- | Logs a message to the request's Nginx log.
5269
--

0 commit comments

Comments
 (0)