Skip to content

Commit

Permalink
workaround of hls bug related to linking of TH code depending on C code
Browse files Browse the repository at this point in the history
  • Loading branch information
lyokha committed Oct 24, 2022
1 parent 14cd449 commit 132868f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install GHC and Cabal
uses: haskell/actions/setup@v1
uses: haskell/actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
Expand Down
19 changes: 18 additions & 1 deletion NgxExport/Log/Base.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ForeignFunctionInterface, OverloadedStrings #-}
{-# LANGUAGE CPP, ForeignFunctionInterface, OverloadedStrings #-}

module NgxExport.Log.Base (LogLevel (..)
,logG
Expand All @@ -18,6 +18,15 @@ import Foreign.Ptr
import Control.Arrow
import Data.Char

-- an ugly workaround of haskell-language-server's
-- [bug](https://github.com/haskell/haskell-language-server/issues/365),
-- this lets hls work with Log.hs without errors
#ifdef __GHCIDE__
#define C_LOG_STUB(f) \
f :: Ptr () -> CUIntPtr -> CString -> CSize -> IO (); \
f _ _ _ _ = return ()
#endif

-- | Log severity levels.
--
-- Being applied to a certain constructor, function 'fromEnum' returns the value
Expand All @@ -32,8 +41,12 @@ data LogLevel = LogStderr
| LogInfo
| LogDebug deriving Enum

#ifdef __GHCIDE__
C_LOG_STUB(c_log)
#else
foreign import ccall unsafe "plugin_ngx_http_haskell_log"
c_log :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
#endif

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

#ifdef __GHCIDE__
C_LOG_STUB(c_log_r)
#else
foreign import ccall unsafe "plugin_ngx_http_haskell_log_r"
c_log_r :: Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
#endif

-- | Logs a message to the request's Nginx log.
--
Expand Down

0 comments on commit 132868f

Please sign in to comment.