Skip to content

Brute force copy of hie-wrapper from hie to ide #15

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 1 commit into from
Jan 29, 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
108 changes: 108 additions & 0 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{-# LANGUAGE CPP #-}
-- | This module is based on the hie-wrapper.sh script in
-- https://github.com/alanz/vscode-hie-server
module Main where

#if __GLASGOW_HASKELL__ < 804
import Data.Semigroup
#endif
import Data.Foldable
import Data.List
import Data.Version (showVersion)
import HIE.Bios
import Ide.Cradle (findLocalCradle, logm)
import Ide.Options
import Ide.Version
import qualified Language.Haskell.LSP.Core as Core
import Options.Applicative.Simple
import qualified Paths_ide as Meta
import System.Directory
import System.Environment
import System.FilePath
import System.Info
import qualified System.Log.Logger as L
import System.Process

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

main :: IO ()
main = do
let
numericVersion :: Parser (a -> a)
numericVersion =
infoOption
(showVersion Meta.version)
(long "numeric-version" <>
help "Show only version number")
compiler :: Parser (a -> a)
compiler =
infoOption
hieGhcDisplayVersion
(long "compiler" <>
help "Show only compiler and version supported")
-- Parse the options and run
(global, ()) <-
simpleOptions
hieVersion
"haskell-ide-wrapper - Launch the appropriate haskell-ide for a given project"
""
(numericVersion <*> compiler <*> globalOptsParser)
empty

run global

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

run :: GlobalOpts -> IO ()
run opts = do
let mLogFileName = optLogFile opts

logLevel = if optDebugOn opts
then L.DEBUG
else L.INFO

Core.setupLogger mLogFileName ["hie"] logLevel

maybe (pure ()) setCurrentDirectory $ projectRoot opts


progName <- getProgName
logm $ "run entered for haskell-ide-wrapper(" ++ progName ++ ") " ++ hieVersion
d <- getCurrentDirectory
logm $ "Current directory:" ++ d
logm $ "Operating system:" ++ os
args <- getArgs
logm $ "args:" ++ show args

-- Get the cabal directory from the cradle
cradle <- findLocalCradle (d </> "File.hs")
let dir = cradleRootDir cradle
logm $ "Cradle directory:" ++ dir
setCurrentDirectory dir

ghcVersion <- getProjectGhcVersion cradle
logm $ "Project GHC version:" ++ ghcVersion

let
hieBin = "haskell-ide-" ++ ghcVersion
backupHieBin =
case dropWhileEnd (/='.') ghcVersion of
[] -> "haskell-ide"
xs -> "haskell-ide-" ++ init xs
candidates' = [hieBin, backupHieBin, "haskell-ide"]
candidates = map (++ exeExtension) candidates'

logm $ "haskell-ide exe candidates :" ++ show candidates

mexes <- traverse findExecutable candidates

case asum mexes of
Nothing -> logm $ "cannot find any haskell-ide exe, looked for:" ++ intercalate ", " candidates
Just e -> do
logm $ "found haskell-ide exe at:" ++ e
logm $ "args:" ++ show args
logm "launching ....\n\n\n"
callProcess e args
logm "done"

-- ---------------------------------------------------------------------
2 changes: 1 addition & 1 deletion ghcide
5 changes: 4 additions & 1 deletion hie.yaml.cbl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ cradle:
- path: "./test"
component: "ide:test"

- path: "./exe"
- path: "./exe/Main.hs"
component: "ide:exe:haskell-ide"

- path: "./exe/Wrapper.hs"
component: "ide:exe:haskell-ide-wrapper"

- path: "./src"
component: "lib:ide"
29 changes: 29 additions & 0 deletions ide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ source-repository head

library
exposed-modules:
Ide.Cradle
Ide.Plugin.Example
Ide.Options
Ide.Version
other-modules:
Paths_ide
hs-source-dirs:
Expand All @@ -39,6 +42,8 @@ library
, async
, binary
, bytestring
, Cabal
, cabal-helper >= 1.0
, containers
, data-default
, deepseq
Expand All @@ -48,16 +53,20 @@ library
, fuzzy
, ghc
, ghcide
, gitrev
, haddock-library
, hashable
, haskell-lsp == 0.19.*
, haskell-lsp-types == 0.19.*
, hie-bios
, hslogger
, mtl
, network-uri
, optparse-simple
, prettyprinter
, prettyprinter-ansi-terminal
, prettyprinter-ansi-terminal
, process
, regex-tdfa >= 1.3.1.0
, rope-utf16-splay
, safe-exceptions
Expand Down Expand Up @@ -123,6 +132,26 @@ executable haskell-ide
Paths_ide
default-language: Haskell2010

executable haskell-ide-wrapper
hs-source-dirs: exe
main-is: Wrapper.hs
other-modules: Paths_ide
autogen-modules: Paths_ide
build-depends: base
, directory
, filepath
, haskell-lsp
, hie-bios
, hslogger
, optparse-simple
, process
, ide
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints
-with-rtsopts=-T
if flag(pedantic)
ghc-options: -Werror
default-language: Haskell2010

test-suite test
type: exitcode-stdio-1.0
main-is: Spec.hs
Expand Down
Loading