Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit e1aeb18

Browse files
authored
Merge pull request #1018 from alanz/vscode-129-hanging-dispatcher
Remove unprotected 'head` in GhcMod codeactions
2 parents 337fd9b + 302caa0 commit e1aeb18

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

hie-plugin-api/Haskell/Ide/Engine/GhcModuleCache.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ data UriCacheResult = UriCacheSuccess UriCache
2222
| UriCacheFailed
2323
deriving (Show)
2424

25+
uriCacheState :: UriCacheResult -> String
26+
uriCacheState UriCacheFailed = "UriCacheFailed"
27+
uriCacheState UriCacheSuccess{} = "UriCacheSuccess"
28+
2529
data UriCache = UriCache
2630
{ cachedInfo :: !CachedInfo
2731
, cachedPsMod :: !ParsedModule

hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ import qualified GhcMod.Utils as GM
4242
import qualified GHC as GHC
4343

4444
import Haskell.Ide.Engine.ArtifactMap
45+
import Haskell.Ide.Engine.GhcModuleCache
4546
import Haskell.Ide.Engine.MultiThreadState
4647
import Haskell.Ide.Engine.PluginsIdeMonads
47-
import Haskell.Ide.Engine.GhcModuleCache
48-
4948

5049
-- ---------------------------------------------------------------------
5150

@@ -228,7 +227,7 @@ cacheModule uri modul = do
228227
_ -> UriCache defInfo pm Nothing mempty
229228

230229
Right tm -> do
231-
typm <- GM.unGmlT $ genTypeMap tm
230+
typm <- GM.unGmlT $ genTypeMap tm
232231
let info = CachedInfo (genLocMap tm) typm (genImportMap tm) (genDefMap tm) rfm return return
233232
pm = GHC.tm_parsed_module tm
234233
return $ UriCache info pm (Just tm) mempty
@@ -267,11 +266,12 @@ failModule fp = do
267266
runDeferredActions :: FilePath -> UriCacheResult -> IdeGhcM ()
268267
runDeferredActions uri res = do
269268
actions <- fmap (fromMaybe [] . Map.lookup uri) (requestQueue <$> readMTS)
270-
liftToGhc $ forM_ actions (\a -> a res)
271-
272269
-- remove queued actions
273270
modifyMTS $ \s -> s { requestQueue = Map.delete uri (requestQueue s) }
274271

272+
liftToGhc $ forM_ actions (\a -> a res)
273+
274+
275275
-- | Saves a module to the cache without clearing the associated cache data - use only if you are
276276
-- sure that the cached data associated with the module doesn't change
277277
cacheInfoNoClear :: (GM.MonadIO m, HasGhcModuleCache m)

hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ type IdeDeferM = FreeT Defer IdeM
298298

299299
type IdeM = ReaderT IdeEnv (MultiThreadState IdeState)
300300

301-
-- | Run an IdeM
301+
-- | Run an IdeM
302302
runIdeM :: IdePlugins -> Maybe (Core.LspFuncs Config) -> TVar IdeState -> IdeM a -> IO a
303303
runIdeM plugins mlf stateVar f = do
304304
env <- IdeEnv <$> pure mlf <*> getProcessID <*> pure plugins
@@ -338,13 +338,13 @@ instance MonadIde IdeM where
338338
case mlf of
339339
Just lf -> fromMaybe def <$> liftIO (Core.config lf)
340340
Nothing -> return def
341-
341+
342342
getClientCapabilities = do
343343
mlf <- asks ideEnvLspFuncs
344344
case mlf of
345345
Just lf -> return (Core.clientCapabilities lf)
346346
Nothing -> return def
347-
347+
348348
getPlugins = asks idePlugins
349349

350350
instance MonadIde IdeGhcM where
@@ -360,7 +360,7 @@ instance MonadIde IdeDeferM where
360360
getConfig = lift getConfig
361361
getClientCapabilities = lift getClientCapabilities
362362
getPlugins = lift getPlugins
363-
363+
364364
data IdeState = IdeState
365365
{ moduleCache :: GhcModuleCache
366366
-- | A queue of requests to be performed once a module is loaded

src/Haskell/Ide/Engine/LSP/Reactor.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ where
1717

1818
import Control.Monad.Reader
1919
import qualified Data.Map as Map
20-
import qualified Language.Haskell.LSP.Core as Core
21-
import qualified Language.Haskell.LSP.Messages as J
22-
import qualified Language.Haskell.LSP.Types as J
2320
import Haskell.Ide.Engine.Compat
2421
import Haskell.Ide.Engine.Config
2522
import Haskell.Ide.Engine.PluginsIdeMonads
2623
import qualified Haskell.Ide.Engine.Scheduler as Scheduler
2724
import Haskell.Ide.Engine.Types
25+
import qualified Language.Haskell.LSP.Core as Core
26+
import qualified Language.Haskell.LSP.Messages as J
27+
import qualified Language.Haskell.LSP.Types as J
28+
29+
-- ---------------------------------------------------------------------
2830

2931
data REnv = REnv
3032
{ scheduler :: Scheduler.Scheduler R
3133
, lspFuncs :: Core.LspFuncs Config
32-
, reactorPidCache :: Int
34+
, reactorPidCache :: Int -- TODO:AZ: do we need this? what is it for?
3335
, diagnosticSources :: Map.Map DiagnosticTrigger [(PluginId,DiagnosticProviderFunc)]
3436
, hoverProviders :: [HoverProvider]
3537
, symbolProviders :: [SymbolProvider]

src/Haskell/Ide/Engine/Plugin/GhcMod.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,10 @@ extractRedundantImport msg =
491491
&& " is redundant" `T.isSuffixOf` firstLine
492492
then Just $ T.init $ T.tail $ T.dropWhileEnd (/= '') $ T.dropWhile (/= '') firstLine
493493
else Nothing
494-
where firstLine = head (T.lines msg)
494+
where
495+
firstLine = case T.lines msg of
496+
[] -> ""
497+
(l:_) -> l
495498

496499
extractHoleSubstitutions :: T.Text -> Maybe (TypeDef, ValidSubstitutions, Bindings)
497500
extractHoleSubstitutions diag

src/Haskell/Ide/Engine/Transport/LspStdio.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module Haskell.Ide.Engine.Transport.LspStdio
1616
) where
1717

1818
import Control.Concurrent
19-
import Control.Concurrent.Async
2019
import Control.Concurrent.STM.TChan
2120
import qualified Control.FoldDebounce as Debounce
2221
import qualified Control.Exception as E
@@ -142,7 +141,7 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
142141
let diagnosticsQueue tr = forever $ do
143142
inval <- liftIO $ atomically $ readTChan diagIn
144143
Debounce.send tr (coerce . Just $ MostRecent inval)
145-
144+
146145
-- Debounce for (default) 350ms.
147146
debounceDuration <- diagnosticsDebounceDuration . fromMaybe def <$> Core.config lf
148147
tr <- Debounce.new
@@ -153,8 +152,8 @@ run scheduler _origDir plugins captureFp = flip E.catches handlers $ do
153152
-- We launch the dispatcher after that so that the default cradle is
154153
-- recognized properly by ghc-mod
155154
_ <- forkIO $ Scheduler.runScheduler scheduler errorHandler callbackHandler (Just lf)
156-
`race_` reactorFunc
157-
`race_` diagnosticsQueue tr
155+
_ <- forkIO reactorFunc
156+
_ <- forkIO $ diagnosticsQueue tr
158157
return Nothing
159158

160159
diagnosticProviders :: Map.Map DiagnosticTrigger [(PluginId,DiagnosticProviderFunc)]
@@ -375,6 +374,7 @@ reactor inp diagIn = do
375374
let
376375
loop :: TrackingNumber -> R void
377376
loop tn = do
377+
liftIO $ U.logs $ "****** reactor: top of loop"
378378
inval <- liftIO $ atomically $ readTChan inp
379379
liftIO $ U.logs $ "****** reactor: got message number:" ++ show tn
380380

0 commit comments

Comments
 (0)