|
1 | | --- Copyright (c) 2019 The DAML Authors. All rights reserved. |
2 | | --- SPDX-License-Identifier: Apache-2.0 |
3 | | -{-# LANGUAGE CPP #-} |
4 | | -{-# LANGUAGE RecordWildCards #-} |
5 | | -{-# LANGUAGE TemplateHaskell #-} |
6 | | -{-# LANGUAGE TupleSections #-} |
7 | | -{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above |
8 | | - |
9 | | -module Ide.Arguments |
10 | | - ( Arguments(..) |
11 | | - , GhcideArguments(..) |
12 | | - , PrintVersion(..) |
13 | | - , BiosAction(..) |
14 | | - , getArguments |
15 | | - , haskellLanguageServerVersion |
16 | | - , haskellLanguageServerNumericVersion |
17 | | - ) where |
18 | | - |
19 | | -import Data.Version |
20 | | -import Development.IDE (IdeState) |
21 | | -import Development.IDE.Main (Command (..), commandP) |
22 | | -import GitHash (giHash, tGitInfoCwdTry) |
23 | | -import Ide.Types (IdePlugins) |
24 | | -import Options.Applicative |
25 | | -import Paths_haskell_language_server |
26 | | -import System.Environment |
27 | | - |
28 | | --- --------------------------------------------------------------------- |
29 | | - |
30 | | -data Arguments |
31 | | - = VersionMode PrintVersion |
32 | | - | ProbeToolsMode |
33 | | - | ListPluginsMode |
34 | | - | BiosMode BiosAction |
35 | | - | Ghcide GhcideArguments |
36 | | - | VSCodeExtensionSchemaMode |
37 | | - | DefaultConfigurationMode |
38 | | - | PrintLibDir |
39 | | - |
40 | | -data GhcideArguments = GhcideArguments |
41 | | - {argsCommand :: Command |
42 | | - ,argsCwd :: Maybe FilePath |
43 | | - ,argsShakeProfiling :: Maybe FilePath |
44 | | - ,argsTesting :: Bool |
45 | | - ,argsExamplePlugin :: Bool |
46 | | - -- These next two are for compatibility with existing hie clients, allowing |
47 | | - -- them to just change the name of the exe and still work. |
48 | | - , argsDebugOn :: Bool |
49 | | - , argsLogFile :: Maybe String |
50 | | - , argsThreads :: Int |
51 | | - , argsProjectGhcVersion :: Bool |
52 | | - } deriving Show |
53 | | - |
54 | | -data PrintVersion |
55 | | - = PrintVersion |
56 | | - | PrintNumericVersion |
57 | | - deriving (Show, Eq, Ord) |
58 | | - |
59 | | -data BiosAction |
60 | | - = PrintCradleType |
61 | | - deriving (Show, Eq, Ord) |
62 | | - |
63 | | -getArguments :: String -> IdePlugins IdeState -> IO Arguments |
64 | | -getArguments exeName plugins = execParser opts |
65 | | - where |
66 | | - opts = info (( |
67 | | - VersionMode <$> printVersionParser exeName |
68 | | - <|> probeToolsParser exeName |
69 | | - <|> listPluginsParser |
70 | | - <|> BiosMode <$> biosParser |
71 | | - <|> Ghcide <$> arguments plugins |
72 | | - <|> flag' PrintLibDir (long "print-libdir" <> help ("Print project GHCs libdir")) |
73 | | - ) |
74 | | - <**> helper) |
75 | | - ( fullDesc |
76 | | - <> progDesc "Used as a test bed to check your IDE Client will work" |
77 | | - <> header (exeName ++ " - GHC Haskell LSP server")) |
78 | | - |
79 | | -printVersionParser :: String -> Parser PrintVersion |
80 | | -printVersionParser exeName = |
81 | | - flag' PrintVersion |
82 | | - (long "version" <> help ("Show " ++ exeName ++ " and GHC versions")) |
83 | | - <|> |
84 | | - flag' PrintNumericVersion |
85 | | - (long "numeric-version" <> help ("Show numeric version of " ++ exeName)) |
86 | | - |
87 | | -biosParser :: Parser BiosAction |
88 | | -biosParser = |
89 | | - flag' PrintCradleType |
90 | | - (long "print-cradle" <> help "Print the project cradle type") |
91 | | - |
92 | | -probeToolsParser :: String -> Parser Arguments |
93 | | -probeToolsParser exeName = |
94 | | - flag' ProbeToolsMode |
95 | | - (long "probe-tools" <> help ("Show " ++ exeName ++ " version and other tools of interest")) |
96 | | - |
97 | | -listPluginsParser :: Parser Arguments |
98 | | -listPluginsParser = |
99 | | - flag' ListPluginsMode |
100 | | - (long "list-plugins" <> help "List all available plugins") |
101 | | - |
102 | | -arguments :: IdePlugins IdeState -> Parser GhcideArguments |
103 | | -arguments plugins = GhcideArguments |
104 | | - <$> (commandP plugins <|> lspCommand <|> checkCommand) |
105 | | - <*> optional (strOption $ long "cwd" <> metavar "DIR" |
106 | | - <> help "Change to this directory") |
107 | | - <*> optional (strOption $ long "shake-profiling" <> metavar "DIR" |
108 | | - <> help "Dump profiling reports to this directory") |
109 | | - <*> switch (long "test" |
110 | | - <> help "Enable additional lsp messages used by the testsuite") |
111 | | - <*> switch (long "example" |
112 | | - <> help "Include the Example Plugin. For Plugin devs only") |
113 | | - |
114 | | - <*> switch |
115 | | - ( long "debug" |
116 | | - <> short 'd' |
117 | | - <> help "Generate debug output" |
118 | | - ) |
119 | | - <*> optional (strOption |
120 | | - ( long "logfile" |
121 | | - <> short 'l' |
122 | | - <> metavar "LOGFILE" |
123 | | - <> help "File to log to, defaults to stdout" |
124 | | - )) |
125 | | - <*> option auto |
126 | | - (short 'j' |
127 | | - <> help "Number of threads (0: automatic)" |
128 | | - <> metavar "NUM" |
129 | | - <> value 0 |
130 | | - <> showDefault |
131 | | - ) |
132 | | - <*> switch (long "project-ghc-version" |
133 | | - <> help "Work out the project GHC version and print it") |
134 | | - where |
135 | | - lspCommand = LSP <$ flag' True (long "lsp" <> help "Start talking to an LSP server") |
136 | | - checkCommand = Check <$> many (argument str (metavar "FILES/DIRS...")) |
137 | | - |
138 | | --- --------------------------------------------------------------------- |
139 | | - |
140 | | -haskellLanguageServerNumericVersion :: String |
141 | | -haskellLanguageServerNumericVersion = showVersion version |
142 | | - |
143 | | -haskellLanguageServerVersion :: IO String |
144 | | -haskellLanguageServerVersion = do |
145 | | - path <- getExecutablePath |
146 | | - let gi = $$tGitInfoCwdTry |
147 | | - gitHashSection = case gi of |
148 | | - Right gi -> " (GIT hash: " <> giHash gi <> ")" |
149 | | - Left _ -> "" |
150 | | - return $ "haskell-language-server version: " <> haskellLanguageServerNumericVersion |
151 | | - <> " (GHC: " <> VERSION_ghc |
152 | | - <> ") (PATH: " <> path <> ")" |
153 | | - <> gitHashSection |
| 1 | +-- Copyright (c) 2019 The DAML Authors. All rights reserved. |
| 2 | +-- SPDX-License-Identifier: Apache-2.0 |
| 3 | +{-# LANGUAGE CPP #-} |
| 4 | +{-# LANGUAGE RecordWildCards #-} |
| 5 | +{-# LANGUAGE TemplateHaskell #-} |
| 6 | +{-# LANGUAGE TupleSections #-} |
| 7 | +{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above |
| 8 | + |
| 9 | +module Ide.Arguments |
| 10 | + ( Arguments(..) |
| 11 | + , GhcideArguments(..) |
| 12 | + , PrintVersion(..) |
| 13 | + , BiosAction(..) |
| 14 | + , getArguments |
| 15 | + , haskellLanguageServerVersion |
| 16 | + , haskellLanguageServerNumericVersion |
| 17 | + ) where |
| 18 | + |
| 19 | +import Data.Version |
| 20 | +import Development.IDE (IdeState) |
| 21 | +import Development.IDE.Main (Command (..), commandP) |
| 22 | +import GitHash (giHash, tGitInfoCwdTry) |
| 23 | +import Ide.Types (IdePlugins) |
| 24 | +import Options.Applicative |
| 25 | +import Paths_haskell_language_server |
| 26 | +import System.Environment |
| 27 | + |
| 28 | +-- --------------------------------------------------------------------- |
| 29 | + |
| 30 | +data Arguments |
| 31 | + = VersionMode PrintVersion |
| 32 | + | ProbeToolsMode |
| 33 | + | ListPluginsMode |
| 34 | + | BiosMode BiosAction |
| 35 | + | Ghcide GhcideArguments |
| 36 | + | VSCodeExtensionSchemaMode |
| 37 | + | DefaultConfigurationMode |
| 38 | + | PrintLibDir |
| 39 | + |
| 40 | +data GhcideArguments = GhcideArguments |
| 41 | + {argsCommand :: Command |
| 42 | + ,argsCwd :: Maybe FilePath |
| 43 | + ,argsShakeProfiling :: Maybe FilePath |
| 44 | + ,argsTesting :: Bool |
| 45 | + ,argsExamplePlugin :: Bool |
| 46 | + -- These next two are for compatibility with existing hie clients, allowing |
| 47 | + -- them to just change the name of the exe and still work. |
| 48 | + , argsDebugOn :: Bool |
| 49 | + , argsLogFile :: Maybe String |
| 50 | + , argsThreads :: Int |
| 51 | + , argsProjectGhcVersion :: Bool |
| 52 | + } deriving Show |
| 53 | + |
| 54 | +data PrintVersion |
| 55 | + = PrintVersion |
| 56 | + | PrintNumericVersion |
| 57 | + deriving (Show, Eq, Ord) |
| 58 | + |
| 59 | +data BiosAction |
| 60 | + = PrintCradleType |
| 61 | + deriving (Show, Eq, Ord) |
| 62 | + |
| 63 | +getArguments :: String -> IdePlugins IdeState -> IO Arguments |
| 64 | +getArguments exeName plugins = execParser opts |
| 65 | + where |
| 66 | + opts = info (( |
| 67 | + VersionMode <$> printVersionParser exeName |
| 68 | + <|> probeToolsParser exeName |
| 69 | + <|> listPluginsParser |
| 70 | + <|> BiosMode <$> biosParser |
| 71 | + <|> Ghcide <$> arguments plugins |
| 72 | + <|> flag' PrintLibDir (long "print-libdir" <> help "Print project GHCs libdir") |
| 73 | + ) |
| 74 | + <**> helper) |
| 75 | + ( fullDesc |
| 76 | + <> progDesc "Used as a test bed to check your IDE Client will work" |
| 77 | + <> header (exeName ++ " - GHC Haskell LSP server")) |
| 78 | + |
| 79 | +printVersionParser :: String -> Parser PrintVersion |
| 80 | +printVersionParser exeName = |
| 81 | + flag' PrintVersion |
| 82 | + (long "version" <> help ("Show " ++ exeName ++ " and GHC versions")) |
| 83 | + <|> |
| 84 | + flag' PrintNumericVersion |
| 85 | + (long "numeric-version" <> help ("Show numeric version of " ++ exeName)) |
| 86 | + |
| 87 | +biosParser :: Parser BiosAction |
| 88 | +biosParser = |
| 89 | + flag' PrintCradleType |
| 90 | + (long "print-cradle" <> help "Print the project cradle type") |
| 91 | + |
| 92 | +probeToolsParser :: String -> Parser Arguments |
| 93 | +probeToolsParser exeName = |
| 94 | + flag' ProbeToolsMode |
| 95 | + (long "probe-tools" <> help ("Show " ++ exeName ++ " version and other tools of interest")) |
| 96 | + |
| 97 | +listPluginsParser :: Parser Arguments |
| 98 | +listPluginsParser = |
| 99 | + flag' ListPluginsMode |
| 100 | + (long "list-plugins" <> help "List all available plugins") |
| 101 | + |
| 102 | +arguments :: IdePlugins IdeState -> Parser GhcideArguments |
| 103 | +arguments plugins = GhcideArguments |
| 104 | + <$> (commandP plugins <|> lspCommand <|> checkCommand) |
| 105 | + <*> optional (strOption $ long "cwd" <> metavar "DIR" |
| 106 | + <> help "Change to this directory") |
| 107 | + <*> optional (strOption $ long "shake-profiling" <> metavar "DIR" |
| 108 | + <> help "Dump profiling reports to this directory") |
| 109 | + <*> switch (long "test" |
| 110 | + <> help "Enable additional lsp messages used by the testsuite") |
| 111 | + <*> switch (long "example" |
| 112 | + <> help "Include the Example Plugin. For Plugin devs only") |
| 113 | + |
| 114 | + <*> switch |
| 115 | + ( long "debug" |
| 116 | + <> short 'd' |
| 117 | + <> help "Generate debug output" |
| 118 | + ) |
| 119 | + <*> optional (strOption |
| 120 | + ( long "logfile" |
| 121 | + <> short 'l' |
| 122 | + <> metavar "LOGFILE" |
| 123 | + <> help "File to log to, defaults to stdout" |
| 124 | + )) |
| 125 | + <*> option auto |
| 126 | + (short 'j' |
| 127 | + <> help "Number of threads (0: automatic)" |
| 128 | + <> metavar "NUM" |
| 129 | + <> value 0 |
| 130 | + <> showDefault |
| 131 | + ) |
| 132 | + <*> switch (long "project-ghc-version" |
| 133 | + <> help "Work out the project GHC version and print it") |
| 134 | + where |
| 135 | + lspCommand = LSP <$ flag' True (long "lsp" <> help "Start talking to an LSP server") |
| 136 | + checkCommand = Check <$> many (argument str (metavar "FILES/DIRS...")) |
| 137 | + |
| 138 | +-- --------------------------------------------------------------------- |
| 139 | + |
| 140 | +haskellLanguageServerNumericVersion :: String |
| 141 | +haskellLanguageServerNumericVersion = showVersion version |
| 142 | + |
| 143 | +haskellLanguageServerVersion :: IO String |
| 144 | +haskellLanguageServerVersion = do |
| 145 | + path <- getExecutablePath |
| 146 | + let gi = $$tGitInfoCwdTry |
| 147 | + gitHashSection = case gi of |
| 148 | + Right gi -> " (GIT hash: " <> giHash gi <> ")" |
| 149 | + Left _ -> "" |
| 150 | + return $ "haskell-language-server version: " <> haskellLanguageServerNumericVersion |
| 151 | + <> " (GHC: " <> VERSION_ghc |
| 152 | + <> ") (PATH: " <> path <> ")" |
| 153 | + <> gitHashSection |
0 commit comments