From 5206857e0240940f17fba05851098dbedee70cac Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Sun, 11 Oct 2020 02:16:11 +0300 Subject: [PATCH] WIP M exe/Wrapper.hs M src/Ide/Version.hs --- exe/Wrapper.hs | 20 +++++++++++++++++--- src/Ide/Version.hs | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index 61dc26cd99..eda47fc075 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -1,6 +1,4 @@ {-# LANGUAGE RecordWildCards #-} --- | This module is based on the hie-wrapper.sh script in --- https://github.com/alanz/vscode-hie-server module Main where import Control.Monad.Extra @@ -42,9 +40,25 @@ main = do VersionMode PrintNumericVersion -> putStrLn haskellLanguageServerNumericVersion + NixMode nixModeArgs -> loadNixEnv nixArgs + LspMode lspArgs -> launchHaskellLanguageServer lspArgs +loadNixEnv :: NixArguments -> IO () +loadNixEnv nixModeArgs = do + s <- doesFileExist $ "shell.nix" + if s then loadNixShell s else do + d <- doesFileExist $ "default.nix" + if d then loadNixShell d else do + die $ "Nix environment requires `shell.nix` or `default.nix`, but none of them was found. Nix environment can be bootstrapped by `cabal2nix --shell . > default.nix`." + where + loadNixShell nixModeArgs = do + nixShell <- findExecutable "nix-shell" + case nixShell of + Nothing -> die $ "`--nix` option was provided, which requires `nix-shell` to load Nix enviroment, but this executable was not found." + Just nsexe -> callProcess nsexe nixModArgs + launchHaskellLanguageServer :: LspArguments -> IO () launchHaskellLanguageServer LspArguments{..} = do whenJust argsCwd setCurrentDirectory @@ -104,6 +118,7 @@ getRuntimeGhcVersion' cradle = do case actionName (cradleOptsProg cradle) of Stack -> checkToolExists "stack" Cabal -> checkToolExists "cabal" + Nix -> checkToolExists "nix" Default -> checkToolExists "ghc" Direct -> checkToolExists "ghc" _ -> pure () @@ -143,4 +158,3 @@ findLocalCradle fp = do Nothing -> loadImplicitCradle fp hPutStrLn stderr $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl return crdl - diff --git a/src/Ide/Version.hs b/src/Ide/Version.hs index 61b45fe3fa..ee732a2f03 100644 --- a/src/Ide/Version.hs +++ b/src/Ide/Version.hs @@ -54,6 +54,7 @@ findProgramVersions :: IO ProgramsOfInterest findProgramVersions = ProgramsOfInterest <$> findVersionOf "cabal" <*> findVersionOf "stack" + <*> findVersionOf "nix" <*> findVersionOf "ghc" -- | Find the version of the given program.