Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package name in output #156

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Weeder/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import qualified Data.Map.Strict as Map
-- ghc
import GHC.Plugins
( occNameString
, unitString
, moduleUnit
, moduleName
, moduleNameString
)
Expand All @@ -43,7 +45,8 @@ import Weeder.Config


data Weed = Weed
{ weedPath :: FilePath
{ weedPackage :: String
, weedPath :: FilePath
, weedLine :: Int
, weedCol :: Int
, weedDeclaration :: Declaration
Expand All @@ -53,7 +56,7 @@ data Weed = Weed

formatWeed :: Weed -> String
formatWeed Weed{..} =
weedPath <> ":" <> show weedLine <> ":" <> show weedCol <> ": "
weedPackage <> ": " <> weedPath <> ":" <> show weedLine <> ":" <> show weedCol <> ": "
<> case weedPrettyPrintedType of
Nothing -> occNameString ( declOccName weedDeclaration )
Just t -> "(Instance) :: " <> t
Expand Down Expand Up @@ -114,16 +117,19 @@ runWeeder weederConfig@Config{ rootPatterns, typeClassRoots, rootInstances } hie
( \d ->
fold $ do
moduleFilePath <- Map.lookup ( declModule d ) ( modulePaths analysis )
let packageName = unitString . moduleUnit . declModule $ d
starts <- Map.lookup d ( declarationSites analysis )
let locs = (,) packageName <$> Set.toList starts
guard $ not $ null starts
return [ Map.singleton moduleFilePath ( liftA2 (,) (Set.toList starts) (pure d) ) ]
return [ Map.singleton moduleFilePath ( liftA2 (,) locs (pure d) ) ]
)
dead

weeds =
Map.toList warnings & concatMap \( weedPath, declarations ) ->
sortOn fst declarations & map \( (weedLine, weedCol) , weedDeclaration ) ->
sortOn fst declarations & map \( (weedPackage, (weedLine, weedCol)) , weedDeclaration ) ->
Weed { weedPrettyPrintedType = Map.lookup weedDeclaration (prettyPrintedType analysis)
, weedPackage
, weedPath
, weedLine
, weedCol
Expand Down
4 changes: 2 additions & 2 deletions test/Spec/ApplicativeDo.failing
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/ApplicativeDo/ApplicativeDo.hs:6:1: (Instance) :: Functor Foo
test/Spec/ApplicativeDo/ApplicativeDo.hs:9:1: (Instance) :: Applicative Foo
main: test/Spec/ApplicativeDo/ApplicativeDo.hs:6:1: (Instance) :: Functor Foo
main: test/Spec/ApplicativeDo/ApplicativeDo.hs:9:1: (Instance) :: Applicative Foo
2 changes: 1 addition & 1 deletion test/Spec/BasicExample.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/BasicExample/BasicExample.hs:4:1: unrelated
main: test/Spec/BasicExample/BasicExample.hs:4:1: unrelated
4 changes: 2 additions & 2 deletions test/Spec/ConfigInstanceModules.stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/ConfigInstanceModules/Module1.hs:3:24: (Instance) :: Show T
test/Spec/ConfigInstanceModules/Module2.hs:3:30: (Instance) :: Bounded T
main: test/Spec/ConfigInstanceModules/Module1.hs:3:24: (Instance) :: Show T
main: test/Spec/ConfigInstanceModules/Module2.hs:3:30: (Instance) :: Bounded T
2 changes: 1 addition & 1 deletion test/Spec/DeriveGeneric.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/DeriveGeneric/DeriveGeneric.hs:12:7: (Instance) :: FromJSON T
main: test/Spec/DeriveGeneric/DeriveGeneric.hs:12:7: (Instance) :: FromJSON T
4 changes: 2 additions & 2 deletions test/Spec/InstanceTypeclass.stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:4:1: Foo
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:10:1: (Instance) :: Foo Char
main: test/Spec/InstanceTypeclass/InstanceTypeclass.hs:4:1: Foo
main: test/Spec/InstanceTypeclass/InstanceTypeclass.hs:10:1: (Instance) :: Foo Char
6 changes: 3 additions & 3 deletions test/Spec/Monads.failing
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test/Spec/Monads/Monads.hs:20:1: (Instance) :: Functor Identity'
test/Spec/Monads/Monads.hs:23:1: (Instance) :: Applicative Identity'
test/Spec/Monads/Monads.hs:27:1: (Instance) :: Monad Identity'
main: test/Spec/Monads/Monads.hs:20:1: (Instance) :: Functor Identity'
main: test/Spec/Monads/Monads.hs:23:1: (Instance) :: Applicative Identity'
main: test/Spec/Monads/Monads.hs:27:1: (Instance) :: Monad Identity'
2 changes: 1 addition & 1 deletion test/Spec/NumInstanceLiteral.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/NumInstanceLiteral/NumInstanceLiteral.hs:7:1: (Instance) :: Num Modulo1
main: test/Spec/NumInstanceLiteral/NumInstanceLiteral.hs:7:1: (Instance) :: Num Modulo1
2 changes: 1 addition & 1 deletion test/Spec/OverloadedLabels.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedLabels/OverloadedLabels.hs:17:1: (Instance) :: Has Point "y" Int
main: test/Spec/OverloadedLabels/OverloadedLabels.hs:17:1: (Instance) :: Has Point "y" Int
2 changes: 1 addition & 1 deletion test/Spec/OverloadedLists.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedLists/OverloadedLists.hs:9:1: (Instance) :: IsList (BetterList x)
main: test/Spec/OverloadedLists/OverloadedLists.hs:9:1: (Instance) :: IsList (BetterList x)
2 changes: 1 addition & 1 deletion test/Spec/OverloadedStrings.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedStrings/OverloadedStrings.hs:10:1: (Instance) :: IsString BetterString
main: test/Spec/OverloadedStrings/OverloadedStrings.hs:10:1: (Instance) :: IsString BetterString
2 changes: 1 addition & 1 deletion test/Spec/RangeEnum.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/RangeEnum/RangeEnum.hs:14:13: (Instance) :: Enum Colour
main: test/Spec/RangeEnum/RangeEnum.hs:14:13: (Instance) :: Enum Colour
2 changes: 1 addition & 1 deletion test/Spec/RootClasses.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/RootClasses/RootClasses.hs:5:34: (Instance) :: Enum T
main: test/Spec/RootClasses/RootClasses.hs:5:34: (Instance) :: Enum T
2 changes: 1 addition & 1 deletion test/Spec/StandaloneDeriving.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/StandaloneDeriving/StandaloneDeriving.hs:6:1: (Instance) :: Show A
main: test/Spec/StandaloneDeriving/StandaloneDeriving.hs:6:1: (Instance) :: Show A
2 changes: 1 addition & 1 deletion test/Spec/Types.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/Types/Usages.hs:16:1: notRoot
main: test/Spec/Types/Usages.hs:16:1: notRoot
8 changes: 4 additions & 4 deletions test/Spec/TypesUnused.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test/Spec/TypesUnused/TypesUnused.hs:6:1: Modulo1
test/Spec/TypesUnused/TypesUnused.hs:8:1: Number
test/Spec/TypesUnused/TypesUnused.hs:10:1: Vector
test/Spec/TypesUnused/TypesUnused.hs:12:1: Family
main: test/Spec/TypesUnused/TypesUnused.hs:6:1: Modulo1
main: test/Spec/TypesUnused/TypesUnused.hs:8:1: Number
main: test/Spec/TypesUnused/TypesUnused.hs:10:1: Vector
main: test/Spec/TypesUnused/TypesUnused.hs:12:1: Family
2 changes: 2 additions & 0 deletions weeder.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ test-suite weeder-test
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test
autogen-modules:
Paths_weeder
other-modules:
Paths_weeder
-- Tests
Expand Down
Loading