packages feed

hls-module-name-plugin 1.0.0.3 → 1.0.1.0

raw patch · 2 files changed

+13/−11 lines, 2 filesdep ~ghcidedep ~hls-plugin-apidep ~hls-test-utilsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils

API changes (from Hackage documentation)

Files

hls-module-name-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-module-name-plugin-version:            1.0.0.3+version:            1.0.1.0 synopsis:           Module name plugin for Haskell Language Server description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -25,8 +25,8 @@     , base                  >=4.12 && <5     , directory     , filepath-    , ghcide                >=1.2  && <1.6-    , hls-plugin-api        >=1.1  && <1.3+    , ghcide                ^>=1.6+    , hls-plugin-api        ^>=1.3     , lsp     , text     , transformers@@ -44,4 +44,4 @@     , base     , filepath     , hls-module-name-plugin-    , hls-test-utils          >=1.0 && <1.2+    , hls-test-utils          ^>=1.2
src/Ide/Plugin/ModuleName.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms   #-} {-# LANGUAGE RecordWildCards   #-}+{-# LANGUAGE ViewPatterns      #-} {-# OPTIONS_GHC -Wall -Wwarn -fno-warn-type-defaults #-}  {- | Keep the module name in sync with its file path.@@ -22,7 +23,9 @@ import           Data.Char                  (isLower) import qualified Data.HashMap.Strict        as HashMap import           Data.List                  (intercalate, isPrefixOf, minimumBy)+import qualified Data.List.NonEmpty         as NE import           Data.Maybe                 (maybeToList)+import           Data.Ord                   (comparing) import           Data.String                (IsString) import qualified Data.Text                  as T import           Development.IDE            (GetParsedModule (GetParsedModule),@@ -31,7 +34,7 @@                                              realSrcSpanToRange, runAction,                                              uriToFilePath', use, use_) import           Development.IDE.GHC.Compat (GenLocated (L), getSessionDynFlags,-                                             hsmodName, importPaths,+                                             hsmodName, importPaths, locA,                                              pattern RealSrcSpan,                                              pm_parsed_source, unLoc) import           Ide.Types@@ -41,10 +44,9 @@                                              SemanticTokenRelative (length),                                              SemanticTokensEdit (_start)) import           Language.LSP.VFS           (virtualFileText)-import           System.Directory           (canonicalizePath)+import           System.Directory           (makeAbsolute) import           System.FilePath            (dropExtension, splitDirectories,                                              takeFileName)-import Data.Ord (comparing)  -- |Plugin descriptor descriptor :: PluginId -> PluginDescriptor IdeState@@ -99,7 +101,7 @@     let emptyModule = maybe True (T.null . T.strip . virtualFileText) contents      correctNames <- liftIO $ traceAs "correctNames" <$> pathModuleNames state nfp fp-    let bestName = minimumBy (comparing T.length) correctNames+    bestName <- minimumBy (comparing T.length) <$> (MaybeT . pure $ NE.nonEmpty correctNames)      statedNameMaybe <- liftIO $ traceAs "statedName" <$> codeModuleName state nfp     case statedNameMaybe of@@ -121,8 +123,8 @@   | otherwise = do       session <- runAction "ModuleName.ghcSession" state $ use_ GhcSession normFilePath       srcPaths <- evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags-      paths <- mapM canonicalizePath srcPaths-      mdlPath <- canonicalizePath filePath+      paths <- mapM makeAbsolute srcPaths+      mdlPath <- makeAbsolute filePath       let prefixes = filter (`isPrefixOf` mdlPath) paths       pure (map (moduleNameFrom mdlPath) prefixes)   where@@ -137,7 +139,7 @@ codeModuleName :: IdeState -> NormalizedFilePath -> IO (Maybe (Range, T.Text)) codeModuleName state nfp = runMaybeT $ do   pm <- MaybeT . runAction "ModuleName.GetParsedModule" state $ use GetParsedModule nfp-  L (RealSrcSpan l _) m <- MaybeT . pure . hsmodName . unLoc $ pm_parsed_source pm+  L (locA -> (RealSrcSpan l _)) m <- MaybeT . pure . hsmodName . unLoc $ pm_parsed_source pm   pure (realSrcSpanToRange l, T.pack $ show m)  -- traceAs :: Show a => String -> a -> a