Skip to content

Commit 2a58af8

Browse files
authored
Merge pull request #73 from alanz/rebase-ghcide-multi
Rebase on mpickering ghcide at wip/multi-rebase
2 parents 1f56104 + 61f364c commit 2a58af8

13 files changed

+63
-25
lines changed

cabal.project

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ source-repository-package
1212
location: https://github.com/fendor/hie-bios.git
1313
tag: 89d28817716a1c8df7e191f3a43c4504bc6379eb
1414

15+
source-repository-package
16+
type: git
17+
location: https://github.com/mpickering/shake
18+
tag: 4d56fe9f09bd3bd63ead541c571c756995da490a
1519

1620
tests: true
1721
documentation: false

exe/Arguments.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data Arguments = Arguments
3636
-- them to just change the name of the exe and still work.
3737
, argsDebugOn :: Bool
3838
, argsLogFile :: Maybe String
39-
, argsThread :: Int
39+
, argsThreads :: Int
4040
} deriving Show
4141

4242
getArguments :: String -> IO Arguments

exe/Main.hs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
module Main(main) where
1414

1515
import Arguments
16+
import Control.Concurrent.Async
1617
import Control.Concurrent.Extra
1718
import Control.Exception
1819
import Control.Monad.Extra
@@ -48,7 +49,7 @@ import Development.IDE.Types.Diagnostics
4849
import Development.IDE.Types.Location
4950
import Development.IDE.Types.Logger
5051
import Development.IDE.Types.Options
51-
import Development.Shake (Action, action)
52+
import Development.Shake (Action)
5253
import DynFlags (gopt_set, gopt_unset,
5354
updOptLevel)
5455
import DynFlags (PackageFlag(..), PackageArg(..))
@@ -190,11 +191,11 @@ main = do
190191
{ optReportProgress = clientSupportsProgress caps
191192
, optShakeProfiling = argsShakeProfiling
192193
, optTesting = argsTesting
194+
, optThreads = argsThreads
193195
, optInterfaceLoadingDiagnostics = argsTesting
194-
, optThreads = argsThread
195196
}
196197
debouncer <- newAsyncDebouncer
197-
initialise caps (mainRule >> pluginRules plugins >> action kick)
198+
initialise caps (mainRule >> pluginRules plugins)
198199
getLspId event hlsLogger debouncer options vfs
199200
else do
200201
-- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
@@ -223,7 +224,7 @@ main = do
223224

224225
putStrLn "\nStep 4/6: Type checking the files"
225226
setFilesOfInterest ide $ HashSet.fromList $ map toNormalizedFilePath' files
226-
_ <- runActionSync ide $ uses TypeCheck (map toNormalizedFilePath' files)
227+
_ <- runActionSync "TypecheckTest" ide $ uses TypeCheck (map toNormalizedFilePath' files)
227228
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "src/Development/IDE/Core/Rules.hs"
228229
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "exe/Main.hs"
229230
return ()
@@ -240,11 +241,13 @@ expandFiles = concatMapM $ \x -> do
240241
fail $ "Couldn't find any .hs/.lhs files inside directory: " ++ x
241242
return files
242243

243-
244+
-- Running this every hover is too expensive, 0.2s on GHC for example
245+
{-
244246
kick :: Action ()
245247
kick = do
246248
files <- getFilesOfInterest
247249
void $ uses TypeCheck $ HashSet.toList files
250+
-}
248251

249252
-- | Print an LSP event.
250253
showEvent :: Lock -> FromServerMessage -> IO ()
@@ -408,7 +411,6 @@ loadSession dir = liftIO $ do
408411
return res
409412

410413
lock <- newLock
411-
cradle_lock <- newLock
412414

413415
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
414416
sessionOpts <- return $ \(hieYaml, file) -> do
@@ -435,17 +437,39 @@ loadSession dir = liftIO $ do
435437
finished_barrier <- newBarrier
436438
-- fork a new thread here which won't be killed by shake
437439
-- throwing an async exception
438-
void $ forkIO $ withLock cradle_lock $ do
439-
putStrLn $ "Shelling out to cabal " <> show file
440+
void $ forkIO $ do
441+
putStrLn $ "Consulting the cradle for " <> show file
440442
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
441443
opts <- cradleToSessionOpts cradle cfp
442444
print opts
443445
res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
444446
signalBarrier finished_barrier res
445447
waitBarrier finished_barrier
446-
return $ \file -> liftIO $ mask_ $ withLock lock $ do
447-
hieYaml <- cradleLoc file
448-
sessionOpts (hieYaml, file)
448+
449+
dummyAs <- async $ return (error "Uninitialised")
450+
runningCradle <- newIORef dummyAs
451+
-- The main function which gets options for a file. We only want one of these running
452+
-- at a time.
453+
let getOptions file = do
454+
hieYaml <- cradleLoc file
455+
sessionOpts (hieYaml, file)
456+
-- 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
469+
470+
471+
472+
449473

450474
checkDependencyInfo :: Map.Map FilePath (Maybe UTCTime) -> IO Bool
451475
checkDependencyInfo old_di = do

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ executable haskell-language-server
133133
build-depends:
134134
base >=4.7 && <5
135135
, aeson
136+
, async
136137
, base16-bytestring
137138
, binary
138139
, bytestring

src/Ide/Plugin/Example.hs

Lines changed: 2 additions & 2 deletions
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 ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let
@@ -190,7 +190,7 @@ logAndRunRequest label getResults ide pos path = do
190190
logInfo (ideLogger ide) $
191191
label <> " request at position " <> T.pack (showPosition pos) <>
192192
" in file: " <> T.pack path
193-
runAction ide $ getResults filePath pos
193+
runAction "Example" ide $ getResults filePath pos
194194

195195
-- ---------------------------------------------------------------------
196196

src/Ide/Plugin/Example2.hs

Lines changed: 2 additions & 2 deletions
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 ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let
@@ -187,7 +187,7 @@ logAndRunRequest label getResults ide pos path = do
187187
logInfo (ideLogger ide) $
188188
label <> " request at position " <> T.pack (showPosition pos) <>
189189
" in file: " <> T.pack path
190-
runAction ide $ getResults filePath pos
190+
runAction "Example2" ide $ getResults filePath pos
191191

192192
-- ---------------------------------------------------------------------
193193

src/Ide/Plugin/Formatter.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ doFormatting lf providers ideState ft uri params = do
6464
Just provider ->
6565
case uriToFilePath uri of
6666
Just (toNormalizedFilePath -> fp) -> do
67-
(_, mb_contents) <- runAction ideState $ getFileContents fp
67+
(_, mb_contents) <- runAction "Formatter" ideState $ getFileContents fp
6868
case mb_contents of
6969
Just contents -> do
7070
logDebug (ideLogger ideState) $ T.pack $

src/Ide/Plugin/Ormolu.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ provider _lf ideState typ contents fp _ = do
5959
in
6060
return $ map DynOption $ pp <> pm <> ex
6161

62-
m_parsed <- runAction ideState $ getParsedModule fp
62+
m_parsed <- runAction "Ormolu" ideState $ getParsedModule fp
6363
fileOpts <- case m_parsed of
6464
Nothing -> return []
6565
Just pm -> fromDyn pm

stack-8.6.4.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extra-deps:
1414
- cabal-plan-0.5.0.0
1515
- constrained-dynamic-0.1.0.0
1616
# - ghcide-0.1.0
17-
- extra-1.6.18
17+
- extra-1.6.21
1818
- floskell-0.10.2
1919
- fuzzy-0.1.0.0
2020
- ghc-check-0.1.0.3
@@ -28,7 +28,7 @@ extra-deps:
2828
- haskell-src-exts-1.21.1
2929
# - hie-bios-0.4.0
3030
- github: fendor/hie-bios
31-
commit: 89d28817716a1c8df7e191f3a43c4504bc6379eb
31+
commit: 87db34de1b10b03bb2c3d7f6bd3623bc1da96ba8
3232
- hlint-2.2.8
3333
- hoogle-5.0.17.11
3434
- hsimport-0.11.0
@@ -41,7 +41,9 @@ extra-deps:
4141
- regex-base-0.94.0.0
4242
- regex-tdfa-1.3.1.0
4343
- rope-utf16-splay-0.3.1.0
44-
- shake-0.18.5
44+
# - shake-0.18.5
45+
- github: mpickering/shake
46+
commit: 4d56fe9f09bd3bd63ead541c571c756995da490a
4547
- syz-0.2.0.0
4648
- tasty-rerun-1.1.17
4749
- temporary-1.2.1.1

stack-8.6.5.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extra-deps:
1414
- clock-0.7.2
1515
- floskell-0.10.2
1616
# - ghcide-0.1.0
17+
- extra-1.6.21
1718
- fuzzy-0.1.0.0
1819
- ghc-check-0.1.0.3
1920
- ghc-lib-parser-8.10.1.20200412
@@ -23,7 +24,7 @@ extra-deps:
2324
- haskell-lsp-types-0.21.0.0
2425
# - hie-bios-0.4.0
2526
- github: fendor/hie-bios
26-
commit: 89d28817716a1c8df7e191f3a43c4504bc6379eb
27+
commit: 87db34de1b10b03bb2c3d7f6bd3623bc1da96ba8
2728
- indexed-profunctors-0.1
2829
- lsp-test-0.10.2.0
2930
- monad-dijkstra-0.1.1.2
@@ -34,6 +35,8 @@ extra-deps:
3435
- regex-base-0.94.0.0
3536
- regex-pcre-builtin-0.95.1.1.8.43
3637
- regex-tdfa-1.3.1.0
38+
- github: mpickering/shake
39+
commit: 4d56fe9f09bd3bd63ead541c571c756995da490a
3740
- semialign-1.1
3841
- tasty-rerun-1.1.17
3942
- temporary-1.2.1.1

stack-8.8.2.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extra-deps:
2323
- haskell-src-exts-1.21.1
2424
# - hie-bios-0.4.0
2525
- github: fendor/hie-bios
26-
commit: 89d28817716a1c8df7e191f3a43c4504bc6379eb
26+
commit: 87db34de1b10b03bb2c3d7f6bd3623bc1da96ba8
2727
- hlint-2.2.8
2828
- hoogle-5.0.17.11
2929
- hsimport-0.11.0
@@ -32,6 +32,8 @@ extra-deps:
3232
- monad-dijkstra-0.1.1.2
3333
- ormolu-0.0.5.0
3434
- semigroups-0.18.5
35+
- github: mpickering/shake
36+
commit: 4d56fe9f09bd3bd63ead541c571c756995da490a
3537
- temporary-1.2.1.1
3638

3739
flags:

stack-8.8.3.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extra-deps:
2323
- haskell-src-exts-1.21.1
2424
# - hie-bios-0.4.0
2525
- github: fendor/hie-bios
26-
commit: 89d28817716a1c8df7e191f3a43c4504bc6379eb
26+
commit: 87db34de1b10b03bb2c3d7f6bd3623bc1da96ba8
2727
- hlint-2.2.8
2828
- hoogle-5.0.17.11
2929
- hsimport-0.11.0
@@ -32,6 +32,8 @@ extra-deps:
3232
- monad-dijkstra-0.1.1.2
3333
- ormolu-0.0.5.0
3434
- semigroups-0.18.5
35+
- github: mpickering/shake
36+
commit: 4d56fe9f09bd3bd63ead541c571c756995da490a
3537
- temporary-1.2.1.1
3638

3739
flags:

0 commit comments

Comments
 (0)