Skip to content

Commit

Permalink
Show the package name in output too
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Sydney Kerckhove committed Jun 3, 2024
1 parent 3ac5751 commit d9c7372
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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
2 changes: 2 additions & 0 deletions weeder.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ test-suite weeder-test
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: test
build-tool-depends:
hspec-discover:hspec-discover
autogen-modules:
Paths_weeder
other-modules:
Expand Down

0 comments on commit d9c7372

Please sign in to comment.