ghc-tags-plugin 0.2.4.1 → 0.3.0.0
raw patch · 4 files changed
+60/−10 lines, 4 files
Files
- CHANGELOG.md +8/−0
- README.md +5/−0
- ghc-tags-plugin.cabal +1/−1
- lib/Plugin/GhcTags.hs +46/−9
CHANGELOG.md view
@@ -56,3 +56,11 @@ * `ghc-tags-vim` a vim plugin which helps to maintain a `cabal.project.local` file. * better tag info++## 0.3.0.0 -- 2021-05-01++* filter adjacents tags: preserve only type signatures (filter out adjacent+ terms) or data constructors (filter out adjacent type constructors).+* fix emacs support: ghc-tags-plugin can now correctly display multiple tags+ (e.g. instance declarations). Thanks to @nfrisby for finding out how to do+ that.
README.md view
@@ -185,6 +185,11 @@ to parse a large `tags` file. Working with tag files of size 10000 tags (or ~1.5MB) is ok - though this will depend on the hardware. +- If you're working on a project that is using `safe-haskell`, you will likely+ need to pass+ [-fplugin-trustworthy](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/extending_ghc.html?highlight=plugin#ghc-flag--fplugin-trustworthy)+ `ghc` flag.+ ● Security implications of compiler plugins -------------------------------------------
ghc-tags-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: ghc-tags-plugin-version: 0.2.4.1+version: 0.3.0.0 synopsis: A compiler plugin which generates tags file from GHC parsed syntax tree. description: A [GHC compiler plugin](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/extending_ghc.html?highlight=compiler%20plugin#compiler-plugins)
lib/Plugin/GhcTags.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-}@@ -344,6 +345,7 @@ let tags :: [CTag] tags = map (fixTagFilePath cwd tagsDir) -- fix file names+ . filterAdjacentTags . sortBy compareTags -- sort . mapMaybe (ghcTagToTag SingCTag dynFlags) -- translate 'GhcTag' to 'Tag'@@ -392,21 +394,16 @@ printMessageDoc dynFlags ParserException (Just ms_mod) err Right (Right tags) -> do-- -- read the source file to calculate byteoffsets- ll <- map (succ . BS.length) . BSC.lines <$> BS.readFile sourcePath- let sourcePathBS = Text.encodeUtf8 (Text.pack sourcePath) newTags :: [ETag] newTags =- (sortBy ETag.compareTags- . map ( ETag.withByteOffset ll- . fixTagFilePath cwd tagsDir- )+ filterAdjacentTags+ . sortBy ETag.compareTags+ . map (fixTagFilePath cwd tagsDir) . mapMaybe (ghcTagToTag SingETag dynFlags) . getGhcTags- $ lmodule)+ $ lmodule tags' :: [ETag] tags' = combineTags@@ -424,6 +421,46 @@ ]) BB.hPutBuilder writeHandle (ETag.formatETagsFile tags')+++-- | Filter adjacent tags.+--+filterAdjacentTags :: [Tag tk] -> [Tag tk]+filterAdjacentTags tags =+ foldr+ (\(mprev, c, mnext) acc ->+ case (mprev, mnext) of+ -- filter out terms preceded by a type signature+ (Just p, _) | tagName p == tagName c+ , TkTypeSignature <- tagKind p+ , k <- tagKind c+ , k == TkTerm+ || k == TkFunction+ -> acc++ -- filter out type constructors followed by a data constructor+ (_, Just n) | tagName c == tagName n+ , TkTypeConstructor <- tagKind c+ , k <- tagKind n+ , k == TkDataConstructor+ || k == TkGADTConstructor+ -> acc++ _ -> c : acc+ + )+ []+ (zip3 tags' tags tags'')+ where+ -- previous+ tags' = case tags of+ [] -> []+ _ -> Nothing : map Just (init tags)++ -- next+ tags'' = case tags of+ [] -> []+ _ -> map Just (tail tags) ++ [Nothing] #if __GLASGOW_HASKELL__ >= 810