Skip to content

Use mpickering/hls ghcide branch #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ main = do
, optInterfaceLoadingDiagnostics = argsTesting
}
debouncer <- newAsyncDebouncer
initialise caps (mainRule >> pluginRules plugins)
fst <$> initialise caps (mainRule >> pluginRules plugins)
getLspId event hlsLogger debouncer options vfs
else do
-- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
Expand All @@ -218,15 +218,15 @@ main = do
putStrLn $ "Found " ++ show n ++ " cradle" ++ ['s' | n /= 1]
putStrLn "\nStep 3/6: Initializing the IDE"
vfs <- makeVFSHandle

debouncer <- newAsyncDebouncer
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) debouncer (defaultIdeOptions $ loadSession dir) vfs
(ide, worker) <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) debouncer (defaultIdeOptions $ loadSession dir) vfs

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

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

return res
return (cs, res)

lock <- newLock

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

dummyAs <- async $ return (error "Uninitialised")
Expand All @@ -454,18 +454,30 @@ loadSession dir = liftIO $ do
hieYaml <- cradleLoc file
sessionOpts (hieYaml, file)
-- The lock is on the `runningCradle` resource
return $ \file -> liftIO $ withLock lock $ do
as <- readIORef runningCradle
finished <- poll as
case finished of
Just {} -> do
as <- async $ getOptions file
writeIORef runningCradle as
wait as
-- If it's not finished then wait and then get options, this could of course be killed still
Nothing -> do
_ <- wait as
getOptions file
return $ \file -> do
(cs, opts) <-
liftIO $ withLock lock $ do
as <- readIORef runningCradle
finished <- poll as
case finished of
Just {} -> do
as <- async $ getOptions file
writeIORef runningCradle as
wait as
-- If it's not finished then wait and then get options, this could of course be killed still
Nothing -> do
_ <- wait as
getOptions file
let cfps = map fst cs
-- Delayed to avoid recursion and only run if something changed.
unless (null cs) (
delay "InitialLoad" ("InitialLoad" :: String, cfps) (void $ do
cfps' <- liftIO $ filterM (IO.doesFileExist . fromNormalizedFilePath) cfps
mmt <- uses GetModificationTime cfps'
let cs_exist = catMaybes (zipWith (<$) cfps' mmt)
uses GetModIface cs_exist))
return opts




Expand Down
2 changes: 1 addition & 1 deletion src/Ide/Plugin/Example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
logInfo (ideLogger ideState) "Example.codeLens entered (ideLogger)" -- AZ
case uriToFilePath' uri of
Just (toNormalizedFilePath -> filePath) -> do
_ <- runAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
_ <- runIdeAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
_diag <- getDiagnostics ideState
_hDiag <- getHiddenDiagnostics ideState
let
Expand Down
2 changes: 1 addition & 1 deletion src/Ide/Plugin/Example2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
logInfo (ideLogger ideState) "Example2.codeLens entered (ideLogger)" -- AZ
case uriToFilePath' uri of
Just (toNormalizedFilePath -> filePath) -> do
_ <- runAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
_ <- runIdeAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
_diag <- getDiagnostics ideState
_hDiag <- getHiddenDiagnostics ideState
let
Expand Down
1 change: 1 addition & 0 deletions src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ data PluginCommand = forall a. (FromJSON a) =>
, commandDesc :: T.Text
, commandFunc :: CommandFunction a
}

-- ---------------------------------------------------------------------

type CommandFunction a = LSP.LspFuncs Config
Expand Down
1 change: 1 addition & 0 deletions stack-8.6.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extra-deps:
- monad-memo-0.4.1
- multistate-0.8.0.1
- ormolu-0.0.5.0
- opentelemetry-0.3.0
- parser-combinators-1.2.1
- regex-base-0.94.0.0
- regex-tdfa-1.3.1.0
Expand Down
1 change: 1 addition & 0 deletions stack-8.6.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extra-deps:
- indexed-profunctors-0.1
- lsp-test-0.10.2.0
- monad-dijkstra-0.1.1.2
- opentelemetry-0.3.0
- optics-core-0.2
- optparse-applicative-0.15.1.0
- ormolu-0.0.5.0
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extra-deps:
- indexed-profunctors-0.1
- lsp-test-0.10.2.0
- monad-dijkstra-0.1.1.2
- opentelemetry-0.3.0
- optics-core-0.2
- optparse-applicative-0.15.1.0
- ormolu-0.0.5.0
Expand Down