Skip to content

Commit ff47306

Browse files
authored
Merge pull request #79 from alanz/wip-az
Use mpickering/hls ghcide branch
2 parents 2a58af8 + 992ffb1 commit ff47306

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

exe/Main.hs

+32-20
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ main = do
195195
, optInterfaceLoadingDiagnostics = argsTesting
196196
}
197197
debouncer <- newAsyncDebouncer
198-
initialise caps (mainRule >> pluginRules plugins)
198+
fst <$> initialise caps (mainRule >> pluginRules plugins)
199199
getLspId event hlsLogger debouncer options vfs
200200
else do
201201
-- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
@@ -218,15 +218,15 @@ main = do
218218
putStrLn $ "Found " ++ show n ++ " cradle" ++ ['s' | n /= 1]
219219
putStrLn "\nStep 3/6: Initializing the IDE"
220220
vfs <- makeVFSHandle
221-
222221
debouncer <- newAsyncDebouncer
223-
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) debouncer (defaultIdeOptions $ loadSession dir) vfs
222+
(ide, worker) <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) debouncer (defaultIdeOptions $ loadSession dir) vfs
224223

225224
putStrLn "\nStep 4/6: Type checking the files"
226225
setFilesOfInterest ide $ HashSet.fromList $ map toNormalizedFilePath' files
227-
_ <- runActionSync "TypecheckTest" ide $ uses TypeCheck (map toNormalizedFilePath' files)
226+
-- _ <- runActionSync "TypecheckTest" ide $ uses TypeCheck (map toNormalizedFilePath' files)
228227
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "src/Development/IDE/Core/Rules.hs"
229228
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "exe/Main.hs"
229+
cancel worker
230230
return ()
231231

232232
expandFiles :: [FilePath] -> IO [FilePath]
@@ -408,7 +408,7 @@ loadSession dir = liftIO $ do
408408
modifyVar_ fileToFlags $ \var -> do
409409
pure $ Map.insert hieYaml (HM.fromList (cs ++ cached_targets)) var
410410

411-
return res
411+
return (cs, res)
412412

413413
lock <- newLock
414414

@@ -432,7 +432,7 @@ loadSession dir = liftIO $ do
432432
case HM.lookup (toNormalizedFilePath' cfp) v of
433433
Just opts -> do
434434
--putStrLn $ "Cached component of " <> show file
435-
pure (fst opts)
435+
pure ([], fst opts)
436436
Nothing-> do
437437
finished_barrier <- newBarrier
438438
-- fork a new thread here which won't be killed by shake
@@ -442,8 +442,8 @@ loadSession dir = liftIO $ do
442442
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
443443
opts <- cradleToSessionOpts cradle cfp
444444
print opts
445-
res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
446-
signalBarrier finished_barrier res
445+
(cs, res)<- session (hieYaml, toNormalizedFilePath' cfp, opts)
446+
signalBarrier finished_barrier (cs, fst res)
447447
waitBarrier finished_barrier
448448

449449
dummyAs <- async $ return (error "Uninitialised")
@@ -454,18 +454,30 @@ loadSession dir = liftIO $ do
454454
hieYaml <- cradleLoc file
455455
sessionOpts (hieYaml, file)
456456
-- The lock is on the `runningCradle` resource
457-
return $ \file -> liftIO $ withLock lock $ do
458-
as <- readIORef runningCradle
459-
finished <- poll as
460-
case finished of
461-
Just {} -> do
462-
as <- async $ getOptions file
463-
writeIORef runningCradle as
464-
wait as
465-
-- If it's not finished then wait and then get options, this could of course be killed still
466-
Nothing -> do
467-
_ <- wait as
468-
getOptions file
457+
return $ \file -> do
458+
(cs, opts) <-
459+
liftIO $ withLock lock $ do
460+
as <- readIORef runningCradle
461+
finished <- poll as
462+
case finished of
463+
Just {} -> do
464+
as <- async $ getOptions file
465+
writeIORef runningCradle as
466+
wait as
467+
-- If it's not finished then wait and then get options, this could of course be killed still
468+
Nothing -> do
469+
_ <- wait as
470+
getOptions file
471+
let cfps = map fst cs
472+
-- Delayed to avoid recursion and only run if something changed.
473+
unless (null cs) (
474+
delay "InitialLoad" ("InitialLoad" :: String, cfps) (void $ do
475+
cfps' <- liftIO $ filterM (IO.doesFileExist . fromNormalizedFilePath) cfps
476+
mmt <- uses GetModificationTime cfps'
477+
let cs_exist = catMaybes (zipWith (<$) cfps' mmt)
478+
uses GetModIface cs_exist))
479+
return opts
480+
469481

470482

471483

src/Ide/Plugin/Example.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
125125
logInfo (ideLogger ideState) "Example.codeLens entered (ideLogger)" -- AZ
126126
case uriToFilePath' uri of
127127
Just (toNormalizedFilePath -> filePath) -> do
128-
_ <- runAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runIdeAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let

src/Ide/Plugin/Example2.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
125125
logInfo (ideLogger ideState) "Example2.codeLens entered (ideLogger)" -- AZ
126126
case uriToFilePath' uri of
127127
Just (toNormalizedFilePath -> filePath) -> do
128-
_ <- runAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runIdeAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let

src/Ide/Types.hs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ data PluginCommand = forall a. (FromJSON a) =>
8383
, commandDesc :: T.Text
8484
, commandFunc :: CommandFunction a
8585
}
86+
8687
-- ---------------------------------------------------------------------
8788

8889
type CommandFunction a = LSP.LspFuncs Config

stack-8.6.4.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extra-deps:
3737
- monad-memo-0.4.1
3838
- multistate-0.8.0.1
3939
- ormolu-0.0.5.0
40+
- opentelemetry-0.3.0
4041
- parser-combinators-1.2.1
4142
- regex-base-0.94.0.0
4243
- regex-tdfa-1.3.1.0

stack-8.6.5.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extra-deps:
2828
- indexed-profunctors-0.1
2929
- lsp-test-0.10.2.0
3030
- monad-dijkstra-0.1.1.2
31+
- opentelemetry-0.3.0
3132
- optics-core-0.2
3233
- optparse-applicative-0.15.1.0
3334
- ormolu-0.0.5.0

stack.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extra-deps:
2727
- indexed-profunctors-0.1
2828
- lsp-test-0.10.2.0
2929
- monad-dijkstra-0.1.1.2
30+
- opentelemetry-0.3.0
3031
- optics-core-0.2
3132
- optparse-applicative-0.15.1.0
3233
- ormolu-0.0.5.0

0 commit comments

Comments
 (0)