Skip to content

Commit

Permalink
Stylish Haskell: CPP parse issues (#3199)
Browse files Browse the repository at this point in the history
* Stylish Haskell: Parse issues

* CPP language extension
* Manually fix some files with duplication

* Pre-commit: Fix ignored files

It looks like `ExactPrint` was ignored before, but since absolute paths
are used and weren't adapted it wasn't ignored afterwards.
  • Loading branch information
andys8 authored Sep 19, 2022
1 parent 0046919 commit bd1d0a1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"hooks": [
{
"entry": "stylish-haskell --inplace",
"exclude": "(^Setup.hs$|test/testdata/.*$|test/data/.*$|test/manual/lhs/.*$|^hie-compat/.*$|^plugins/hls-tactics-plugin/.*$|^ghcide/src/Development/IDE/GHC/Compat.hs$|^ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs$|^ghcide/src/Development/IDE/GHC/Compat/Core.hs$|^ghcide/src/Development/IDE/Spans/Pragmas.hs$|^ghcide/src/Development/IDE/LSP/Outline.hs$|^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$|^ghcide/test/exe/Main.hs$|ghcide/src/Development/IDE/Core/Rules.hs|^hls-test-utils/src/Test/Hls/Util.hs$)",
"exclude": "(^Setup.hs$|test/testdata/.*$|test/data/.*$|test/manual/lhs/.*$|^hie-compat/.*$|^plugins/hls-tactics-plugin/.*$|^ghcide/src/Development/IDE/GHC/Compat.hs$|^plugins/hls-refactor-plugin/src/Development/IDE/GHC/Compat/ExactPrint.hs$|^ghcide/src/Development/IDE/GHC/Compat/Core.hs$|^ghcide/src/Development/IDE/Spans/Pragmas.hs$|^ghcide/src/Development/IDE/LSP/Outline.hs$|^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$|^ghcide/test/exe/Main.hs$|^ghcide/src/Development/IDE/Core/Rules.hs$|^hls-test-utils/src/Test/Hls/Util.hs$|^ghcide/src/Development/IDE/Core/Compile.hs$|^plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs$|^plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs$)",
"files": "\\.l?hs$",
"id": "stylish-haskell",
"language": "system",
Expand Down
1 change: 1 addition & 0 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ newline: lf

language_extensions:
- BangPatterns
- CPP
- DataKinds
- DeriveFunctor
- DeriveGeneric
Expand Down
16 changes: 8 additions & 8 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}

{-|
The logic for setting up a ghcide session by tapping into hie-bios.
Expand Down Expand Up @@ -67,15 +67,16 @@ import Development.IDE.Types.Location
import Development.IDE.Types.Logger (Pretty (pretty),
Priority (Debug, Error, Info, Warning),
Recorder, WithPriority,
logWith, nest, vcat,
viaShow, (<+>),
toCologActionWithPrio, cmapWithPrio)
cmapWithPrio, logWith,
nest,
toCologActionWithPrio,
vcat, viaShow, (<+>))
import Development.IDE.Types.Options
import GHC.Check
import qualified HIE.Bios as HieBios
import qualified HIE.Bios.Types as HieBios
import HIE.Bios.Environment hiding (getCacheDir)
import HIE.Bios.Types hiding (Log)
import qualified HIE.Bios.Types as HieBios
import Hie.Implicit.Cradle (loadImplicitHieCradle)
import Language.LSP.Server
import Language.LSP.Types
Expand All @@ -90,6 +91,8 @@ import Data.Void
import Control.Concurrent.STM.Stats (atomically, modifyTVar',
readTVar, writeTVar)
import Control.Concurrent.STM.TQueue
import Control.DeepSeq
import Control.Exception (evaluate)
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Data.Foldable (for_)
import Data.HashMap.Strict (HashMap)
Expand All @@ -103,9 +106,6 @@ import HieDb.Types
import HieDb.Utils
import qualified System.Random as Random
import System.Random (RandomGen)
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Exception (evaluate)
import Control.DeepSeq

data Log
= LogSettingInitialDynFlags
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/GHC/Compat/Iface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Development.IDE.GHC.Compat.Iface (

import GHC
#if MIN_VERSION_ghc(9,3,0)
import GHC.Driver.Session (targetProfile)
import GHC.Driver.Session (targetProfile)
#endif
#if MIN_VERSION_ghc(9,2,0)
import qualified GHC.Iface.Load as Iface
Expand Down
7 changes: 4 additions & 3 deletions ghcide/src/Development/IDE/Import/FindImports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Data.List (isSuffixOf)
import Data.Maybe
import System.FilePath
#if MIN_VERSION_ghc(9,3,0)
import GHC.Types.PkgQual
import GHC.Types.PkgQual
#endif

data Import
Expand Down Expand Up @@ -123,11 +123,12 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do
#if MIN_VERSION_ghc(9,3,0)
OtherPkg uid
| Just dirs <- lookup uid import_paths
-> lookupLocal uid dirs
#else
Just pkgName
| Just (uid, dirs) <- lookup (PackageName pkgName) import_paths
#endif
-> lookupLocal uid dirs
#endif
| otherwise -> lookupInPackageDB env
#if MIN_VERSION_ghc(9,3,0)
NoPkgQual -> do
Expand All @@ -148,7 +149,7 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do

mbFile <- locateModuleFile ((homeUnitId_ dflags, importPaths dflags) : import_paths') exts targetFor isSource $ unLoc modName
case mbFile of
Nothing -> lookupInPackageDB env
Nothing -> lookupInPackageDB env
Just (uid, file) -> toModLocation uid file
where
dflags = hsc_dflags env
Expand Down
6 changes: 4 additions & 2 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ import GHC.Plugins (Depth (AllTheWay),
#endif
import Ide.PluginUtils (mkLspCommand)
import Ide.Types (CommandId (..),
IdePlugins(..), PluginId)
IdePlugins (..),
PluginId)
import Language.LSP.Types
import Language.LSP.Types.Capabilities
import qualified Language.LSP.VFS as VFS
Expand Down Expand Up @@ -516,7 +517,6 @@ findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result
PrefixCon{} -> Just []
_ -> Nothing

extract ConDeclField{..}
-- NOTE: 'cd_fld_names' is grouped so that the fields
-- sharing the same type declaration to fit in the same group; e.g.
--
Expand All @@ -527,8 +527,10 @@ findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result
-- is encoded as @[[arg1, arg2], [arg3], [arg4]]@
-- Hence, we must concat nested arguments into one to get all the fields.
#if MIN_VERSION_ghc(9,3,0)
extract ConDeclField{..}
= map (foLabel . unLoc) cd_fld_names
#else
extract ConDeclField{..}
= map (rdrNameFieldOcc . unLoc) cd_fld_names
#endif
-- XConDeclField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import qualified Data.Map as Map
import qualified Data.Text as T
import Development.IDE hiding (pluginHandlers)
import Development.IDE.GHC.Compat
import Development.IDE.Plugin.CodeAction
import Development.IDE.GHC.Compat.ExactPrint
import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (..))
import qualified Development.IDE.GHC.ExactPrint as E
import qualified Development.IDE.GHC.ExactPrint as E
import Development.IDE.Plugin.CodeAction
import Ide.Types
import Language.Haskell.GHC.ExactPrint
import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Control.Arrow (second,
(&&&),
(>>>))
import Control.Concurrent.STM.Stats (atomically)
import Control.Monad.Extra
import Control.Monad.IO.Class
import Control.Monad.Trans.Maybe
import Control.Monad.Extra
import Data.Aeson
import Data.Char
import qualified Data.DList as DL
Expand All @@ -39,50 +39,52 @@ import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.Utf16.Rope as Rope
import Data.Tuple.Extra (fst3)
import Development.IDE.Types.Logger hiding (group)
import Development.IDE.Core.Rules
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Service
import Development.IDE.Core.Shake hiding (Log)
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.ExactPrint
import Development.IDE.GHC.Compat.Util
import Development.IDE.GHC.Error
import Development.IDE.GHC.ExactPrint
import qualified Development.IDE.GHC.ExactPrint as E
import qualified Development.IDE.GHC.ExactPrint as E
import Development.IDE.GHC.Util (printOutputable,
printRdrName)
import Development.IDE.Core.Shake hiding (Log)
import Development.IDE.Plugin.CodeAction.Args
import Development.IDE.Plugin.CodeAction.ExactPrint
import Development.IDE.Plugin.CodeAction.Util
import Development.IDE.Plugin.CodeAction.PositionIndexed
import Development.IDE.Plugin.CodeAction.Util
import Development.IDE.Plugin.Completions.Types
import Development.IDE.Plugin.TypeLenses (suggestSignature)
import Development.IDE.Types.Exports
import Development.IDE.Types.Location
import Development.IDE.Types.Logger hiding
(group)
import Development.IDE.Types.Options
import GHC.Exts (fromList)
import qualified GHC.LanguageExtensions as Lang
import Ide.PluginUtils (subRange)
import Ide.Types
import qualified Language.LSP.Server as LSP
import Language.LSP.Types (ApplyWorkspaceEditParams(..), CodeAction (..),
import Language.LSP.Types (ApplyWorkspaceEditParams (..),
CodeAction (..),
CodeActionContext (CodeActionContext, _diagnostics),
CodeActionKind (CodeActionQuickFix, CodeActionUnknown),
CodeActionParams (CodeActionParams),
Command,
Diagnostic (..),
MessageType (..),
ShowMessageParams (..),
List (..),
MessageType (..),
ResponseError,
SMethod (..),
ShowMessageParams (..),
TextDocumentIdentifier (TextDocumentIdentifier),
TextEdit (TextEdit, _range),
UInt,
WorkspaceEdit (WorkspaceEdit, _changeAnnotations, _changes, _documentChanges),
type (|?) (InR),
uriToFilePath)
import GHC.Exts (fromList)
import Language.LSP.VFS (VirtualFile,
_file_text)
import Text.Regex.TDFA (mrAfter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
module Development.IDE.Plugin.CodeAction.Util where

import Data.Data (Data)
import qualified Data.Unique as U
import Data.Data (Data)
import Data.Time.Clock.POSIX (POSIXTime,
getCurrentTime,
utcTimeToPOSIXSeconds)
import qualified Data.Unique as U
import Debug.Trace
import Development.IDE.GHC.Compat.ExactPrint as GHC
import Development.IDE.GHC.Dump (showAstDataHtml)
import GHC.Stack
import System.Environment.Blank (getEnvDefault)
import System.Environment.Blank (getEnvDefault)
import System.IO.Unsafe
import Text.Printf
import Development.IDE.GHC.Dump (showAstDataHtml)
import Data.Time.Clock.POSIX (POSIXTime, getCurrentTime,
utcTimeToPOSIXSeconds)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Utils.Outputable
#else
import Development.IDE.GHC.Util
import Development.IDE.GHC.Compat.Util
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.Util
import Development.IDE.GHC.Util
#endif
--------------------------------------------------------------------------------
-- Tracing exactprint terms
Expand Down
4 changes: 2 additions & 2 deletions plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Maybe (MaybeT (MaybeT), runMaybeT)
import Data.Default
import Data.Foldable (toList)
import qualified Data.HashMap.Strict as HM
import Data.Hashable (Hashable)
import qualified Data.HashMap.Strict as HM
import qualified Data.Map as Map
import Data.Maybe (fromJust, mapMaybe)
import qualified Data.Text as T
import Development.IDE
import Development.IDE.Core.RuleTypes (HieAstResult (..))
import Development.IDE.Core.Rules (getHieFile,
getSourceFileSource)
import Development.IDE.Core.RuleTypes (HieAstResult (..))
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.GHC.Compat (HieASTs (HieASTs),
RealSrcSpan (..), mkHieFile',
Expand Down

0 comments on commit bd1d0a1

Please sign in to comment.