Skip to content

Commit

Permalink
Fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed Feb 11, 2021
1 parent b385c01 commit e87fb93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
7 changes: 6 additions & 1 deletion ghcide/exe/Main.hs
Expand Up @@ -8,7 +8,9 @@ module Main(main) where
import Arguments ( Arguments'(..), IdeCmd(..), getArguments )
import Control.Concurrent.Extra ( newLock, withLock )
import Control.Monad.Extra ( unless, when, whenJust )
import Data.Default ( Default(def) )
import Data.List.Extra ( upper )
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Version ( showVersion )
Expand All @@ -22,6 +24,7 @@ import Development.IDE.Session (setInitialDynFlags, getHieDbLoc, runWithDb)
import Development.IDE.Types.Options
import qualified Development.IDE.Main as Main
import Development.Shake (ShakeOptions(shakeThreads))
import Ide.Plugin.Config (Config(checkParents, checkProject))
import Ide.PluginUtils (pluginDescToIdePlugins)
import HieDb.Run (Options(..), runCommand)
import Paths_ghcide ( version )
Expand Down Expand Up @@ -102,13 +105,15 @@ main = do
then Test.plugin
else mempty

,Main.argsIdeOptions = \sessionLoader ->
,Main.argsIdeOptions = \(fromMaybe def -> config) sessionLoader ->
let defOptions = defaultIdeOptions sessionLoader
in defOptions
{ optShakeProfiling = argsShakeProfiling
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
, optTesting = IdeTesting argsTesting
, optShakeOptions = (optShakeOptions defOptions){shakeThreads = argsThreads}
, optCheckParents = checkParents config
, optCheckProject = checkProject config
}
}

40 changes: 18 additions & 22 deletions ghcide/src/Development/IDE/Main.hs
Expand Up @@ -68,15 +68,13 @@ import Development.IDE.Types.Options (
import Development.IDE.Types.Shake (Key (Key))
import Development.Shake (action)
import HIE.Bios.Cradle (findCradle)
import Ide.Plugin.Config (
CheckParents (NeverCheck),
Config (checkParents, checkProject),
)
import Ide.Plugin.Config (CheckParents (NeverCheck), Config)
import Ide.PluginUtils (allLspCmdIds', getProcessID, pluginDescToIdePlugins)
import Ide.Types (IdePlugins)
import qualified Language.Haskell.LSP.Core as LSP
import Language.Haskell.LSP.Messages (FromServerMessage)
import Language.Haskell.LSP.Types (
DidChangeConfigurationNotification,
InitializeRequest,
LspId (IdInt),
)
Expand All @@ -99,8 +97,10 @@ data Arguments = Arguments
, argsHlsPlugins :: IdePlugins IdeState
, argsGhcidePlugin :: Plugin Config -- ^ Deprecated
, argsSessionLoadingOptions :: SessionLoadingOptions
, argsIdeOptions :: Action IdeGhcSession -> IdeOptions
, argsIdeOptions :: Maybe Config -> Action IdeGhcSession -> IdeOptions
, argsLspOptions :: LSP.Options
, argsGetInitialConfig :: InitializeRequest -> Either T.Text Config
, argsOnConfigChange :: DidChangeConfigurationNotification -> Either T.Text Config
}

defArguments :: HieDb -> IndexQueue -> Arguments
Expand All @@ -115,8 +115,14 @@ defArguments hiedb hiechan =
, argsGhcidePlugin = mempty
, argsHlsPlugins = pluginDescToIdePlugins Ghcide.descriptors
, argsSessionLoadingOptions = defaultLoadingOptions
, argsIdeOptions = defaultIdeOptions
, argsIdeOptions = const defaultIdeOptions
, argsLspOptions = def {LSP.completionTriggerCharacters = Just "."}
, argsOnConfigChange = const $ Left "Updating Not supported"
, argsGetInitialConfig = \x -> case x ^. params . initializationOptions of
Nothing -> Right def
Just v -> case J.fromJSON v of
J.Error err -> Left $ T.pack err
J.Success a -> Right a
}

defaultMain :: Arguments -> IO ()
Expand All @@ -127,22 +133,14 @@ defaultMain Arguments{..} = do
let hlsPlugin = asGhcIdePlugin argsHlsPlugins
hlsCommands = allLspCmdIds' pid argsHlsPlugins
plugins = hlsPlugin <> argsGhcidePlugin
onInitialConfiguration :: InitializeRequest -> Either T.Text Config
onInitialConfiguration x = case x ^. params . initializationOptions of
Nothing -> Right def
Just v -> case J.fromJSON v of
J.Error err -> Left $ T.pack err
J.Success a -> Right a
onConfigurationChange = const $ Left "Updating Not supported"
options = argsLspOptions
{ LSP.executeCommandCommands = Just hlsCommands
}
options = argsLspOptions { LSP.executeCommandCommands = Just hlsCommands }

case argFiles of
Nothing -> do
t <- offsetTime
hPutStrLn stderr "Starting LSP server..."
hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
runLanguageServer options (pluginHandler plugins) onInitialConfiguration onConfigurationChange $ \getLspId event vfs caps wProg wIndefProg getConfig rootPath -> do
runLanguageServer options (pluginHandler plugins) argsGetInitialConfig argsOnConfigChange $ \getLspId event vfs caps wProg wIndefProg getConfig rootPath -> do
t <- t
hPutStrLn stderr $ "Started LSP server in " ++ showDuration t

Expand All @@ -155,11 +153,9 @@ defaultMain Arguments{..} = do
`catchAny` (\e -> (hPutStrLn stderr $ "setInitialDynFlags: " ++ displayException e) >> pure Nothing)

sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions $ fromMaybe dir rootPath
config <- fromMaybe def <$> getConfig
let options = (argsIdeOptions sessionLoader)
config <- getConfig
let options = (argsIdeOptions config sessionLoader)
{ optReportProgress = clientSupportsProgress caps
, optCheckParents = checkParents config
, optCheckProject = checkProject config
}
rules = argsRules >> pluginRules plugins
debouncer <- newAsyncDebouncer
Expand Down Expand Up @@ -201,7 +197,7 @@ defaultMain Arguments{..} = do
debouncer <- newAsyncDebouncer
let dummyWithProg _ _ f = f (const (pure ()))
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions dir
let options = (argsIdeOptions sessionLoader)
let options = (argsIdeOptions Nothing sessionLoader)
{ optCheckParents = NeverCheck
, optCheckProject = False
}
Expand Down
5 changes: 4 additions & 1 deletion src/Ide/Main.hs
Expand Up @@ -31,6 +31,7 @@ import HieDb.Run
import qualified Development.IDE.Main as Main
import qualified Development.IDE.Types.Options as Ghcide
import Development.Shake (ShakeOptions(shakeThreads))
import Ide.Plugin.Config (getInitialConfig, getConfigFromNotification)

defaultMain :: Arguments -> IdePlugins IdeState -> IO ()
defaultMain args idePlugins = do
Expand Down Expand Up @@ -99,7 +100,9 @@ runLspMode lspArgs@LspArguments{..} idePlugins = do
{ Main.argFiles = if argLSP then Nothing else Just []
, Main.argsHlsPlugins = idePlugins
, Main.argsLogger = hlsLogger
, Main.argsIdeOptions = \sessionLoader ->
, Main.argsGetInitialConfig = getInitialConfig
, Main.argsOnConfigChange = getConfigFromNotification
, Main.argsIdeOptions = \_config sessionLoader ->
let defOptions = Ghcide.defaultIdeOptions sessionLoader
in defOptions
{ Ghcide.optShakeProfiling = argsShakeProfiling
Expand Down

0 comments on commit e87fb93

Please sign in to comment.