Skip to content

Commit

Permalink
Update HLS
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Jan 9, 2021
1 parent a153727 commit 3e7f624
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
5 changes: 2 additions & 3 deletions plugins/tactics/src/Ide/Plugin/Tactic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ judgementForHole state nfp range = do
let dflags = ms_hspp_opts modsum

case asts of
(HAR _ hf _ kind) -> do
(HAR _ hf _ _ kind) -> do
(rss, goal) <- liftMaybe $ join $ listToMaybe $ M.elems $ flip M.mapWithKey (getAsts hf) $ \fs ast ->
case selectSmallestContaining (rangeToRealSrcSpan (FastString.unpackFS fs) range') ast of
Nothing -> Nothing
Expand All @@ -276,8 +276,7 @@ judgementForHole state nfp range = do
cls_hy = contextMethodHypothesis ctx
case kind of
HieFromDisk hf' ->
-- TODO FIXME XXX.
fail undefined
fail "Need a fresh hie file"
HieFresh ->
pure ( resulting_range
, mkFirstJudgement
Expand Down
48 changes: 4 additions & 44 deletions src/Ide/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Development.IDE.LSP.LanguageServer
import Development.IDE.LSP.Protocol
import Development.IDE.Plugin
import Development.IDE.Plugin.HLS
import Development.IDE.Session (loadSession, findCradle, defaultLoadingOptions, cacheDir)
import Development.IDE.Session (loadSession, findCradle, defaultLoadingOptions, setInitialDynFlags, getHieDbLoc, runWithDb)
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Location
import Development.IDE.Types.Logger as G
Expand All @@ -57,24 +57,6 @@ import qualified System.Log.Logger as L
import System.Time.Extra
import Development.Shake (action)

import HieDb.Create
import HieDb.Types
import Database.SQLite.Simple
import qualified Data.ByteString.Char8 as B
import qualified Crypto.Hash.SHA1 as H
import Control.Concurrent.Async
import Control.Exception
import System.Directory
import Data.ByteString.Base16

-- ---------------------------------------------------------------------
-- ghcide partialhandlers
import Development.IDE.Plugin.CodeAction as CodeAction
import Development.IDE.Plugin.Completions as Completions
import Development.IDE.LSP.HoverDefinition as HoverDefinition

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

ghcIdePlugins :: T.Text -> IdePlugins IdeState -> (Plugin Config, [T.Text])
ghcIdePlugins pid ps = (asGhcIdePlugin ps, allLspCmdIds' pid ps)

Expand Down Expand Up @@ -116,36 +98,12 @@ hlsLogger = G.Logger $ \pri txt ->
-- ---------------------------------------------------------------------

runLspMode :: LspArguments -> IdePlugins IdeState -> IO ()
runLspMode lspArgs@LspArguments{..} idePlugins = do

getHieDbLoc :: FilePath -> IO FilePath
getHieDbLoc dir = do
let db = dirHash++"-"++takeBaseName dir++"-"++VERSION_ghc <.> "hiedb"
dirHash = B.unpack $ encode $ H.hash $ B.pack dir
cDir <- IO.getXdgDirectory IO.XdgCache cacheDir
createDirectoryIfMissing True cDir
pure (cDir </> db)

runLspMode :: LspArguments -> IdePlugins -> IO ()
runLspMode lspArgs idePlugins = do
dir <- IO.getCurrentDirectory
dbLoc <- getHieDbLoc dir
runWithDb dbLoc $ runLspMode' lspArgs idePlugins

runWithDb :: FilePath -> (HieDb -> HieWriterChan -> IO ()) -> IO ()
runWithDb fp k =
withHieDb fp $ \writedb -> do
execute_ (getConn writedb) "PRAGMA journal_mode=WAL;"
initConn writedb
chan <- newChan
race_ (writerThread writedb chan) (withHieDb fp (flip k chan))
where
writerThread db chan = forever $ do
k <- readChan chan
k db `catch` \e@SQLError{} -> do
hPutStrLn stderr $ "Error in worker, ignoring: " ++ show e

runLspMode' :: LspArguments -> IdePlugins -> HieDb -> HieWriterChan -> IO ()
runLspMode' :: LspArguments -> IdePlugins IdeState -> HieDb -> IndexQueue -> IO ()
runLspMode' lspArgs@LspArguments{..} idePlugins hiedb hiechan = do
LSP.setupLogger argsLogFile ["hls", "hie-bios"]
$ if argsDebugOn then L.DEBUG else L.INFO
Expand All @@ -159,6 +117,8 @@ runLspMode' lspArgs@LspArguments{..} idePlugins hiedb hiechan = do

dir <- IO.getCurrentDirectory

libdir <- setInitialDynFlags

pid <- T.pack . show <$> getProcessID
let
(plugins, commandIds) = ghcIdePlugins pid idePlugins
Expand Down

0 comments on commit 3e7f624

Please sign in to comment.