Skip to content

Commit 35ee2b9

Browse files
committed
clean up
1 parent 38e7bf2 commit 35ee2b9

File tree

17 files changed

+129
-336
lines changed

17 files changed

+129
-336
lines changed

cabal.project

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,3 @@ if impl(ghc >= 9.11)
5656
allow-newer:
5757
cabal-install-parsers:base,
5858
cabal-install-parsers:time,
59-
60-
source-repository-package
61-
type: git
62-
location: https://github.com/soulomoon/lsp.git
63-
tag: 640c7c755bf16128e3cb19c257688aa3305ff9f5
64-
subdir: lsp lsp-types lsp-test

ghcide-test/exe/ResolveTests.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Language.LSP.Test hiding (resolveCompletion)
2424
import Test.Hls (IdeState, SMethod (..), liftIO,
2525
mkPluginTestDescriptor,
2626
someMethodToMethodString,
27-
waitForKickDone)
27+
waitForAllProgressDone)
2828
import qualified Test.Hls.FileSystem as FS
2929
import Test.Tasty
3030
import Test.Tasty.HUnit
@@ -100,7 +100,7 @@ resolveRequests =
100100
, "data Foo = Foo { foo :: Int }"
101101
, "bar = Foo 4"
102102
]
103-
waitForKickDone
103+
waitForAllProgressDone
104104
items <- getCompletions doc (Position 2 7)
105105
let resolveCompItems = filter (\i -> "test item" `T.isPrefixOf` (i ^. J.label)) items
106106
liftIO $ assertEqual "There must be exactly two results" 2 (length resolveCompItems)
@@ -113,7 +113,7 @@ resolveRequests =
113113
, "data Foo = Foo { foo :: Int }"
114114
, "bar = Foo 4"
115115
]
116-
waitForKickDone
116+
waitForAllProgressDone
117117
-- Cant use 'getAllCodeActions', as this lsp-test function queries the diagnostic
118118
-- locations and we don't have diagnostics in these tests.
119119
cas <- Maybe.mapMaybe (preview _R) <$> getCodeActions doc (Range (Position 0 0) (Position 1 0))
@@ -128,7 +128,7 @@ resolveRequests =
128128
, "data Foo = Foo { foo :: Int }"
129129
, "bar = Foo 4"
130130
]
131-
waitForKickDone
131+
waitForAllProgressDone
132132
cd <- getCodeLenses doc
133133
let resolveCodeLenses = filter (\i -> case i ^. J.command of
134134
Just cmd -> "test item" `T.isPrefixOf` (cmd ^. J.title)

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE ImpredicativeTypes #-}
3-
{-# LANGUAGE TypeFamilies #-}
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE TypeFamilies #-}
43

54
{-|
65
The logic for setting up a ghcide session by tapping into hie-bios.
@@ -105,7 +104,8 @@ import qualified Data.HashSet as Set
105104
import qualified Data.Set as OS
106105
import Database.SQLite.Simple
107106
import Development.IDE.Core.Tracing (withTrace)
108-
import Development.IDE.Core.WorkerThread
107+
import Development.IDE.Core.WorkerThread (awaitRunInThread,
108+
withWorkerQueue)
109109
import qualified Development.IDE.GHC.Compat.Util as Compat
110110
import Development.IDE.Session.Diagnostics (renderCradleError)
111111
import Development.IDE.Types.Shake (WithHieDb,
@@ -119,7 +119,6 @@ import qualified System.Random as Random
119119
import System.Random (RandomGen)
120120
import Text.ParserCombinators.ReadP (readP_to_S)
121121

122-
import qualified Control.Monad.Catch as MC
123122
import GHC.Driver.Env (hsc_all_home_unit_ids)
124123
import GHC.Driver.Errors.Types
125124
import GHC.Types.Error (errMsgDiagnostic,
@@ -150,12 +149,10 @@ data Log
150149
| LogNewComponentCache !(([FileDiagnostic], Maybe HscEnvEq), DependencyInfo)
151150
| LogHieBios HieBios.Log
152151
| LogSessionLoadingChanged
153-
| LogSessionWorkerThread LogWorkerThread
154152
deriving instance Show Log
155153

156154
instance Pretty Log where
157155
pretty = \case
158-
LogSessionWorkerThread msg -> pretty msg
159156
LogNoneCradleFound path ->
160157
"None cradle found for" <+> pretty path <+> ", ignoring the file"
161158
LogSettingInitialDynFlags ->
@@ -384,8 +381,8 @@ runWithDb recorder fp = ContT $ \k -> do
384381
_ <- withWriteDbRetryable deleteMissingRealFiles
385382
_ <- withWriteDbRetryable garbageCollectTypeNames
386383

387-
runContT (withWorkerQueue (cmapWithPrio LogSessionWorkerThread recorder) "hiedb thread" (writer withWriteDbRetryable))
388-
$ \chan -> withHieDb fp (\readDb -> k (WithHieDbShield $ makeWithHieDbRetryable recorder rng readDb, chan))
384+
runContT (withWorkerQueue (writer withWriteDbRetryable)) $ \chan ->
385+
withHieDb fp (\readDb -> k (WithHieDbShield $ makeWithHieDbRetryable recorder rng readDb, chan))
389386
where
390387
writer withHieDbRetryable l = do
391388
-- TODO: probably should let exceptions be caught/logged/handled by top level handler
@@ -418,7 +415,7 @@ getHieDbLoc dir = do
418415
-- components mapping to the same hie.yaml file are mapped to the same
419416
-- HscEnv which is updated as new components are discovered.
420417

421-
loadSessionWithOptions :: Recorder (WithPriority Log) -> SessionLoadingOptions -> FilePath -> TaskQueue (IO ()) -> IO (Action IdeGhcSession)
418+
loadSessionWithOptions :: Recorder (WithPriority Log) -> SessionLoadingOptions -> FilePath -> TQueue (IO ()) -> IO (Action IdeGhcSession)
422419
loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
423420
let toAbsolutePath = toAbsolute rootDir -- see Note [Root Directory]
424421
cradle_files <- newIORef []
@@ -756,7 +753,6 @@ emptyHscEnv :: NameCache -> FilePath -> IO HscEnv
756753
emptyHscEnv nc libDir = do
757754
-- We call setSessionDynFlags so that the loader is initialised
758755
-- We need to do this before we call initUnits.
759-
-- we mask_ here because asynchronous exceptions might be swallowed
760756
env <- runGhc (Just libDir) $
761757
getSessionDynFlags >>= setSessionDynFlags >> getSession
762758
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ import Development.IDE.Core.Preprocessor
7575
import Development.IDE.Core.ProgressReporting (progressUpdate)
7676
import Development.IDE.Core.RuleTypes
7777
import Development.IDE.Core.Shake
78-
import Development.IDE.Core.WorkerThread (writeTaskQueue)
7978
import Development.IDE.Core.Tracing (withTrace)
8079
import qualified Development.IDE.GHC.Compat as Compat
8180
import qualified Development.IDE.GHC.Compat as GHC
@@ -883,7 +882,7 @@ indexHieFile se mod_summary srcPath !hash hf = do
883882
-- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
884883
let !hf' = hf{hie_hs_src = mempty}
885884
modifyTVar' indexPending $ HashMap.insert srcPath hash
886-
writeTaskQueue indexQueue $ \withHieDb -> do
885+
writeTQueue indexQueue $ \withHieDb -> do
887886
-- We are now in the worker thread
888887
-- Check if a newer index of this file has been scheduled, and if so skip this one
889888
newerScheduled <- atomically $ do

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import Development.IDE.Core.IdeConfiguration (isWorkspaceFile)
4545
import Development.IDE.Core.RuleTypes
4646
import Development.IDE.Core.Shake hiding (Log)
4747
import qualified Development.IDE.Core.Shake as Shake
48-
import Development.IDE.Core.WorkerThread
4948
import Development.IDE.GHC.Orphans ()
5049
import Development.IDE.Graph
5150
import Development.IDE.Import.DependencyInformation
@@ -253,8 +252,8 @@ getVersionedTextDoc doc = do
253252
maybe (pure Nothing) getVirtualFile $
254253
uriToNormalizedFilePath $ toNormalizedUri uri
255254
let ver = case mvf of
256-
Just (VirtualFile lspver _ _ _) -> lspver
257-
Nothing -> 0
255+
Just (VirtualFile lspver _ _) -> lspver
256+
Nothing -> 0
258257
return (VersionedTextDocumentIdentifier uri ver)
259258

260259
fileStoreRules :: Recorder (WithPriority Log) -> (NormalizedFilePath -> Action Bool) -> Rules ()
@@ -305,7 +304,7 @@ typecheckParentsAction recorder nfp = do
305304
setSomethingModified :: VFSModified -> IdeState -> String -> IO [Key] -> IO ()
306305
setSomethingModified vfs state reason actionBetweenSession = do
307306
-- Update database to remove any files that might have been renamed/deleted
308-
atomically $ writeTaskQueue (indexQueue $ hiedbWriter $ shakeExtras state) (\withHieDb -> withHieDb deleteMissingRealFiles)
307+
atomically $ writeTQueue (indexQueue $ hiedbWriter $ shakeExtras state) (\withHieDb -> withHieDb deleteMissingRealFiles)
309308
void $ restartShakeSession (shakeExtras state) vfs reason [] actionBetweenSession
310309

311310
registerFileWatches :: [String] -> LSP.LspT Config IO Bool

ghcide/src/Development/IDE/Core/ProgressReporting.hs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,24 @@ import Control.Concurrent.STM (STM)
2323
import Control.Concurrent.STM.Stats (TVar, atomically,
2424
atomicallyNamed, modifyTVar',
2525
newTVarIO, readTVar, retry)
26-
import Control.Concurrent.Strict (modifyVar_, newBarrier, newVar,
27-
signalBarrier, threadDelay)
26+
import Control.Concurrent.Strict (modifyVar_, newVar,
27+
threadDelay)
2828
import Control.Monad.Extra hiding (loop)
2929
import Control.Monad.IO.Class
3030
import Control.Monad.Trans.Class (lift)
31-
import qualified Data.Aeson as J
3231
import Data.Functor (($>))
3332
import qualified Data.Text as T
34-
import Data.Unique (hashUnique, newUnique)
3533
import Development.IDE.GHC.Orphans ()
3634
import Development.IDE.Types.Location
3735
import Development.IDE.Types.Options
3836
import qualified Focus
39-
import Language.LSP.Protocol.Message
4037
import Language.LSP.Protocol.Types
41-
import qualified Language.LSP.Protocol.Types as L
42-
import Language.LSP.Server (MonadLsp, ProgressAmount (..),
38+
import Language.LSP.Server (ProgressAmount (..),
4339
ProgressCancellable (..),
44-
sendNotification, sendRequest,
4540
withProgress)
4641
import qualified Language.LSP.Server as LSP
4742
import qualified StmContainers.Map as STM
4843
import UnliftIO (Async, async, bracket, cancel)
49-
import qualified UnliftIO.Exception as UE
5044

5145
data ProgressEvent
5246
= ProgressNewStarted
@@ -174,7 +168,7 @@ progressReportingNoTrace todo done (Just lspEnv) title optProgressStyle = do
174168
let _progressUpdate event = liftIO $ updateStateVar $ Event event
175169
_progressStop = updateStateVar StopProgress
176170
updateStateVar = modifyVar_ progressState . updateState (progressCounter lspEnv title optProgressStyle todo done)
177-
return ProgressReporting {_progressUpdate, _progressStop}
171+
return ProgressReporting {..}
178172

179173
-- | `progressReporting` initiates a new progress reporting session.
180174
-- It necessitates the active tracking of progress using the `inProgress` function.
@@ -202,28 +196,6 @@ progressReporting (Just lspEnv) title optProgressStyle = do
202196

203197
f = recordProgress inProgress file
204198

205-
withProgressDummy ::
206-
forall c m a.
207-
MonadLsp c m =>
208-
T.Text ->
209-
Maybe ProgressToken ->
210-
ProgressCancellable ->
211-
((ProgressAmount -> m ()) -> m a) ->
212-
m a
213-
withProgressDummy title _ _ f = do
214-
UE.bracket start end $ \_ ->
215-
f (const $ return ())
216-
where
217-
sendProgressReport token report = sendNotification SMethod_Progress $ ProgressParams token $ J.toJSON report
218-
start = UE.uninterruptibleMask_ $ do
219-
t <- L.ProgressToken . L.InR . T.pack . show . hashUnique <$> liftIO newUnique
220-
r <- liftIO newBarrier
221-
_ <- sendRequest SMethod_WindowWorkDoneProgressCreate (WorkDoneProgressCreateParams t) $ \_ -> liftIO $ signalBarrier r ()
222-
sendProgressReport t $ WorkDoneProgressBegin L.AString title Nothing Nothing Nothing
223-
return t
224-
end t = do
225-
sendProgressReport t (WorkDoneProgressEnd L.AString Nothing)
226-
227199
-- Kill this to complete the progress session
228200
progressCounter ::
229201
LSP.LanguageContextEnv c ->
@@ -233,12 +205,8 @@ progressCounter ::
233205
STM Int ->
234206
IO ()
235207
progressCounter lspEnv title optProgressStyle getTodo getDone =
236-
LSP.runLspT lspEnv $ withProgressChoice title Nothing NotCancellable $ \update -> loop update 0
208+
LSP.runLspT lspEnv $ withProgress title Nothing NotCancellable $ \update -> loop update 0
237209
where
238-
withProgressChoice = case optProgressStyle of
239-
TestReporting -> withProgressDummy
240-
_ -> withProgress
241-
242210
loop _ _ | optProgressStyle == NoProgress = forever $ liftIO $ threadDelay maxBound
243211
loop update prevPct = do
244212
(todo, done, nextPct) <- liftIO $ atomically $ do

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ persistentHieFileRule recorder = addPersistentRule GetHieAst $ \file -> runMaybe
516516
vfsRef <- asks vfsVar
517517
vfsData <- liftIO $ _vfsMap <$> readTVarIO vfsRef
518518
(currentSource, ver) <- liftIO $ case M.lookup (filePathToUri' file) vfsData of
519-
Just (Open vf) -> pure (virtualFileText vf, Just $ virtualFileVersion vf)
520-
_ -> (,Nothing) . T.decodeUtf8 <$> BS.readFile (fromNormalizedFilePath file)
519+
Nothing -> (,Nothing) . T.decodeUtf8 <$> BS.readFile (fromNormalizedFilePath file)
520+
Just vf -> pure (virtualFileText vf, Just $ virtualFileVersion vf)
521521
let refmap = generateReferencesMap . getAsts . Compat.hie_asts $ res
522522
del = deltaFromDiff (T.decodeUtf8 $ Compat.hie_hs_src res) currentSource
523523
pure (HAR (Compat.hie_module res) (Compat.hie_asts res) refmap mempty (HieFromDisk res),del,ver)

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Development.IDE.Core.Shake(
2525
IdeState, shakeSessionInit, shakeExtras, shakeDb, rootDir,
2626
ShakeExtras(..), getShakeExtras, getShakeExtrasRules,
2727
KnownTargets(..), Target(..), toKnownFiles, unionKnownTargets, mkKnownTargets,
28-
IdeRule, IdeResult, RestartQueue,
28+
IdeRule, IdeResult,
2929
GetModificationTime(GetModificationTime, GetModificationTime_, missingFileDiagnostics),
3030
shakeOpen, shakeShut,
3131
shakeEnqueue,
@@ -254,15 +254,12 @@ data HieDbWriter
254254
-- | Actions to queue up on the index worker thread
255255
-- The inner `(HieDb -> IO ()) -> IO ()` wraps `HieDb -> IO ()`
256256
-- with (currently) retry functionality
257-
type IndexQueue = TaskQueue (((HieDb -> IO ()) -> IO ()) -> IO ())
258-
type RestartQueue = TaskQueue (IO ())
259-
type LoaderQueue = TaskQueue (IO ())
260-
257+
type IndexQueue = TQueue (((HieDb -> IO ()) -> IO ()) -> IO ())
261258

262259
data ThreadQueue = ThreadQueue {
263260
tIndexQueue :: IndexQueue
264-
, tRestartQueue :: RestartQueue
265-
, tLoaderQueue :: LoaderQueue
261+
, tRestartQueue :: TQueue (IO ())
262+
, tLoaderQueue :: TQueue (IO ())
266263
}
267264

268265
-- Note [Semantic Tokens Cache Location]
@@ -333,9 +330,9 @@ data ShakeExtras = ShakeExtras
333330
-- ^ Default HLS config, only relevant if the client does not provide any Config
334331
, dirtyKeys :: TVar KeySet
335332
-- ^ Set of dirty rule keys since the last Shake run
336-
, restartQueue :: RestartQueue
333+
, restartQueue :: TQueue (IO ())
337334
-- ^ Queue of restart actions to be run.
338-
, loaderQueue :: LoaderQueue
335+
, loaderQueue :: TQueue (IO ())
339336
-- ^ Queue of loader actions to be run.
340337
}
341338

@@ -393,16 +390,11 @@ addPersistentRule k getVal = do
393390

394391
class Typeable a => IsIdeGlobal a where
395392

396-
-- data VirtualFileEntry = Open VirtualFile | Closed ClosedVirtualFile
397-
getOpenFile :: VirtualFileEntry -> Maybe VirtualFile
398-
getOpenFile (Open vf) = Just vf
399-
getOpenFile _ = Nothing
400393
-- | Read a virtual file from the current snapshot
401394
getVirtualFile :: NormalizedFilePath -> Action (Maybe VirtualFile)
402395
getVirtualFile nf = do
403396
vfs <- fmap _vfsMap . liftIO . readTVarIO . vfsVar =<< getShakeExtras
404-
let file = getOpenFile =<< Map.lookup (filePathToUri' nf) vfs
405-
pure $! file -- Don't leak a reference to the entire map
397+
pure $! Map.lookup (filePathToUri' nf) vfs -- Don't leak a reference to the entire map
406398

407399
-- Take a snapshot of the current LSP VFS
408400
vfsSnapshot :: Maybe (LSP.LanguageContextEnv a) -> IO VFS

0 commit comments

Comments
 (0)