Skip to content

Commit

Permalink
Make hls-code-range-plugin buildable on 9.4 by removing usused exactp…
Browse files Browse the repository at this point in the history
…rint dependencies
  • Loading branch information
wz1000 committed Sep 6, 2022
1 parent 68be91e commit bc5bacc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ common qualifyImportedNames
cpp-options: -Dhls_qualifyImportedNames

common codeRange
if flag(codeRange) && (impl(ghc < 9.4.1) || flag(ignore-plugins-ghc-bounds))
if flag(codeRange)
build-depends: hls-code-range-plugin ^>= 1.0
cpp-options: -Dhls_codeRange

Expand Down
9 changes: 0 additions & 9 deletions plugins/hls-code-range-plugin/hls-code-range-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ extra-source-files:
test/testdata/selection-range/*.txt

library
if impl(ghc >= 9.3)
buildable: False
else
buildable: True
exposed-modules:
Ide.Plugin.CodeRange
Ide.Plugin.CodeRange.Rules
Expand All @@ -42,7 +38,6 @@ library
, ghcide ^>=1.6 || ^>=1.7
, hashable
, hls-plugin-api ^>=1.3 || ^>=1.4
, hls-refactor-plugin
, lens
, lsp
, mtl
Expand All @@ -52,10 +47,6 @@ library
, vector

test-suite tests
if impl(ghc >= 9.3)
buildable: False
else
buildable: True
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: test
Expand Down
6 changes: 1 addition & 5 deletions plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import Development.IDE.Core.PositionMapping (PositionMapping,
fromCurrentPosition,
toCurrentRange)
import Development.IDE.Types.Logger (Pretty (..))
import qualified Development.IDE.GHC.ExactPrint as E
import Development.IDE.Plugin.CodeAction
import Ide.Plugin.CodeRange.Rules (CodeRange (..),
GetCodeRange (..),
codeRangeRule)
Expand All @@ -57,20 +55,18 @@ import Language.LSP.Types (List (List),
import Prelude hiding (log, span)

descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor recorder plId = mkExactprintPluginDescriptor (cmapWithPrio LogExactPrint recorder) $ (defaultPluginDescriptor plId)
descriptor recorder plId = (defaultPluginDescriptor plId)
{ pluginHandlers = mkPluginHandler STextDocumentSelectionRange selectionRangeHandler
-- TODO @sloorush add folding range
-- <> mkPluginHandler STextDocumentFoldingRange foldingRangeHandler
, pluginRules = codeRangeRule (cmapWithPrio LogRules recorder)
}

data Log = LogRules Rules.Log
| LogExactPrint E.Log

instance Pretty Log where
pretty log = case log of
LogRules codeRangeLog -> pretty codeRangeLog
LogExactPrint exactPrintLog -> pretty exactPrintLog

selectionRangeHandler :: IdeState -> PluginId -> SelectionRangeParams -> LspM c (Either ResponseError (List SelectionRange))
selectionRangeHandler ide _ SelectionRangeParams{..} = do
Expand Down
12 changes: 4 additions & 8 deletions plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ import qualified Data.Vector as V
import Development.IDE
import Development.IDE.Core.Rules (toIdeResult)
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.GHC.Compat.ExactPrint (Annotated)
import Development.IDE.GHC.Compat (HieAST (..),
HieASTs (getAsts),
ParsedSource, RefMap)
RefMap)
import Development.IDE.GHC.Compat.Util
import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (GetAnnotatedParsedSource))
import GHC.Generics (Generic)
import Ide.Plugin.CodeRange.ASTPreProcess (CustomNodeType (..),
PreProcessEnv (..),
Expand Down Expand Up @@ -105,8 +103,8 @@ instance Ord CodeRange where

-- | Construct a 'CodeRange'. A valid CodeRange will be returned in any case. If anything go wrong,
-- a list of warnings will be returned as 'Log'
buildCodeRange :: HieAST a -> RefMap a -> Annotated ParsedSource -> Writer [Log] CodeRange
buildCodeRange ast refMap _ = do
buildCodeRange :: HieAST a -> RefMap a -> Writer [Log] CodeRange
buildCodeRange ast refMap = do
-- We work on 'HieAST', then convert it to 'CodeRange', so that applications such as selection range and folding
-- range don't need to care about 'HieAST'
-- TODO @sloorush actually use 'Annotated ParsedSource' to handle structures not in 'HieAST' properly (for example comments)
Expand Down Expand Up @@ -178,9 +176,7 @@ codeRangeRule recorder =
HAR{hieAst, refMap} <- lift $ use_ GetHieAst file
ast <- maybeToExceptT LogNoAST . MaybeT . pure $
getAsts hieAst Map.!? (coerce . mkFastString . fromNormalizedFilePath) file
annPS <- lift $ use_ GetAnnotatedParsedSource file

let (codeRange, warnings) = runWriter (buildCodeRange ast refMap annPS)
let (codeRange, warnings) = runWriter (buildCodeRange ast refMap)
traverse_ (logWith recorder Warning) warnings

pure codeRange
Expand Down

0 comments on commit bc5bacc

Please sign in to comment.