Skip to content

Commit 36e8d7f

Browse files
authored
Merge pull request #15 from alanz/wrapper
Brute force copy of hie-wrapper from hie to ide
2 parents fb1cdb7 + ae6d02a commit 36e8d7f

File tree

7 files changed

+1160
-2
lines changed

7 files changed

+1160
-2
lines changed

exe/Wrapper.hs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{-# LANGUAGE CPP #-}
2+
-- | This module is based on the hie-wrapper.sh script in
3+
-- https://github.com/alanz/vscode-hie-server
4+
module Main where
5+
6+
#if __GLASGOW_HASKELL__ < 804
7+
import Data.Semigroup
8+
#endif
9+
import Data.Foldable
10+
import Data.List
11+
import Data.Version (showVersion)
12+
import HIE.Bios
13+
import Ide.Cradle (findLocalCradle, logm)
14+
import Ide.Options
15+
import Ide.Version
16+
import qualified Language.Haskell.LSP.Core as Core
17+
import Options.Applicative.Simple
18+
import qualified Paths_ide as Meta
19+
import System.Directory
20+
import System.Environment
21+
import System.FilePath
22+
import System.Info
23+
import qualified System.Log.Logger as L
24+
import System.Process
25+
26+
-- ---------------------------------------------------------------------
27+
28+
main :: IO ()
29+
main = do
30+
let
31+
numericVersion :: Parser (a -> a)
32+
numericVersion =
33+
infoOption
34+
(showVersion Meta.version)
35+
(long "numeric-version" <>
36+
help "Show only version number")
37+
compiler :: Parser (a -> a)
38+
compiler =
39+
infoOption
40+
hieGhcDisplayVersion
41+
(long "compiler" <>
42+
help "Show only compiler and version supported")
43+
-- Parse the options and run
44+
(global, ()) <-
45+
simpleOptions
46+
hieVersion
47+
"haskell-ide-wrapper - Launch the appropriate haskell-ide for a given project"
48+
""
49+
(numericVersion <*> compiler <*> globalOptsParser)
50+
empty
51+
52+
run global
53+
54+
-- ---------------------------------------------------------------------
55+
56+
run :: GlobalOpts -> IO ()
57+
run opts = do
58+
let mLogFileName = optLogFile opts
59+
60+
logLevel = if optDebugOn opts
61+
then L.DEBUG
62+
else L.INFO
63+
64+
Core.setupLogger mLogFileName ["hie"] logLevel
65+
66+
maybe (pure ()) setCurrentDirectory $ projectRoot opts
67+
68+
69+
progName <- getProgName
70+
logm $ "run entered for haskell-ide-wrapper(" ++ progName ++ ") " ++ hieVersion
71+
d <- getCurrentDirectory
72+
logm $ "Current directory:" ++ d
73+
logm $ "Operating system:" ++ os
74+
args <- getArgs
75+
logm $ "args:" ++ show args
76+
77+
-- Get the cabal directory from the cradle
78+
cradle <- findLocalCradle (d </> "File.hs")
79+
let dir = cradleRootDir cradle
80+
logm $ "Cradle directory:" ++ dir
81+
setCurrentDirectory dir
82+
83+
ghcVersion <- getProjectGhcVersion cradle
84+
logm $ "Project GHC version:" ++ ghcVersion
85+
86+
let
87+
hieBin = "haskell-ide-" ++ ghcVersion
88+
backupHieBin =
89+
case dropWhileEnd (/='.') ghcVersion of
90+
[] -> "haskell-ide"
91+
xs -> "haskell-ide-" ++ init xs
92+
candidates' = [hieBin, backupHieBin, "haskell-ide"]
93+
candidates = map (++ exeExtension) candidates'
94+
95+
logm $ "haskell-ide exe candidates :" ++ show candidates
96+
97+
mexes <- traverse findExecutable candidates
98+
99+
case asum mexes of
100+
Nothing -> logm $ "cannot find any haskell-ide exe, looked for:" ++ intercalate ", " candidates
101+
Just e -> do
102+
logm $ "found haskell-ide exe at:" ++ e
103+
logm $ "args:" ++ show args
104+
logm "launching ....\n\n\n"
105+
callProcess e args
106+
logm "done"
107+
108+
-- ---------------------------------------------------------------------

ghcide

hie.yaml.cbl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ cradle:
88
- path: "./test"
99
component: "ide:test"
1010

11-
- path: "./exe"
11+
- path: "./exe/Main.hs"
1212
component: "ide:exe:haskell-ide"
1313

14+
- path: "./exe/Wrapper.hs"
15+
component: "ide:exe:haskell-ide-wrapper"
16+
1417
- path: "./src"
1518
component: "lib:ide"

ide.cabal

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ source-repository head
2828

2929
library
3030
exposed-modules:
31+
Ide.Cradle
3132
Ide.Plugin.Example
33+
Ide.Options
34+
Ide.Version
3235
other-modules:
3336
Paths_ide
3437
hs-source-dirs:
@@ -39,6 +42,8 @@ library
3942
, async
4043
, binary
4144
, bytestring
45+
, Cabal
46+
, cabal-helper >= 1.0
4247
, containers
4348
, data-default
4449
, deepseq
@@ -48,16 +53,20 @@ library
4853
, fuzzy
4954
, ghc
5055
, ghcide
56+
, gitrev
5157
, haddock-library
5258
, hashable
5359
, haskell-lsp == 0.19.*
5460
, haskell-lsp-types == 0.19.*
61+
, hie-bios
5562
, hslogger
5663
, mtl
5764
, network-uri
65+
, optparse-simple
5866
, prettyprinter
5967
, prettyprinter-ansi-terminal
6068
, prettyprinter-ansi-terminal
69+
, process
6170
, regex-tdfa >= 1.3.1.0
6271
, rope-utf16-splay
6372
, safe-exceptions
@@ -123,6 +132,26 @@ executable haskell-ide
123132
Paths_ide
124133
default-language: Haskell2010
125134

135+
executable haskell-ide-wrapper
136+
hs-source-dirs: exe
137+
main-is: Wrapper.hs
138+
other-modules: Paths_ide
139+
autogen-modules: Paths_ide
140+
build-depends: base
141+
, directory
142+
, filepath
143+
, haskell-lsp
144+
, hie-bios
145+
, hslogger
146+
, optparse-simple
147+
, process
148+
, ide
149+
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints
150+
-with-rtsopts=-T
151+
if flag(pedantic)
152+
ghc-options: -Werror
153+
default-language: Haskell2010
154+
126155
test-suite test
127156
type: exitcode-stdio-1.0
128157
main-is: Spec.hs

0 commit comments

Comments
 (0)