cabal-version:      2.4
category:           Development
name:               haskell-language-server
version:            1.7.0.0
synopsis:           LSP server for GHC
description:
  Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>

homepage:           https://github.com/haskell/haskell-language-server#readme
bug-reports:        https://github.com/haskell/haskell-language-server/issues
author:             The Haskell IDE Team
maintainer:         alan.zimm@gmail.com
copyright:          The Haskell IDE Team
license:            Apache-2.0
license-file:       LICENSE
build-type:         Simple
tested-with:        GHC == 8.6.5 || == 8.8.4 || == 8.10.6 || == 8.10.7 || == 9.0.2 || == 9.2.2
extra-source-files:
  README.md
  ChangeLog.md
  test/testdata/**/*.project
  test/testdata/**/*.cabal
  test/testdata/**/*.yaml
  test/testdata/**/*.hs

flag pedantic
  description: Enable -Werror
  default:     False
  manual:      True

source-repository head
  type:     git
  location: https://github.com/haskell/haskell-language-server

common common-deps
  build-depends:
    , base       >=4.12 && <5
    , directory
    , extra
    , filepath
    , text
    , prettyprinter

-- Default warnings in HLS
common warnings
  ghc-options: -Wall -Wredundant-constraints -Wno-name-shadowing -Wno-unticked-promoted-constructors

-- Allow compiling in pedantic mode
common pedantic
  if flag(pedantic)
    ghc-options: -Werror

library
  import:           common-deps
                    -- configuration
                  , warnings
                  , pedantic
  exposed-modules:
    Ide.Arguments
    Ide.Main
    Ide.Version

  other-modules:    Paths_haskell_language_server
  autogen-modules:  Paths_haskell_language_server
  hs-source-dirs:   src
  build-depends:
    , async
    , base16-bytestring
    , bytestring
    , containers
    , cryptohash-sha1
    , data-default
    , ghc
    , ghcide                ^>=1.7
    , githash
    , lsp
    , hie-bios
    , hiedb
    , hls-plugin-api        ^>=1.4
    , optparse-applicative
    , optparse-simple
    , process
    , hls-graph
    , safe-exceptions
    , sqlite-simple
    , unordered-containers
    , aeson-pretty

  default-language: Haskell2010
  default-extensions: DataKinds, TypeOperators

-- Plugin flags are designed for 'cabal install haskell-language-server':
-- - Bulk flags should be default:False
-- - Individual flags should be default:True

-- The intent of this flag is being able to keep the ghc condition for hackage
-- but skip it via flags in cabal.project as plugins for new ghcs usually
-- are buildable using cabal.project tweaks
flag ignore-plugins-ghc-bounds
  description: Force the inclusion of plugins even if they are not buildable by default with a specific ghc version
  default:     False
  manual:      True

flag class
  description: Enable class plugin
  default:     True
  manual:      True

flag callHierarchy
  description: Enable call hierarchy plugin
  default:     True
  manual:      True

flag haddockComments
  description: Enable haddockComments plugin
  default:     True
  manual:      True

flag eval
  description: Enable eval plugin
  default:     True
  manual:      True

flag importLens
  description: Enable importLens plugin
  default:     True
  manual:      True

flag refineImports
  description: Enable refineImports plugin
  default:     True
  manual:      True

flag rename
  description: Enable rename plugin
  default:     True
  manual:      True

flag retrie
  description: Enable retrie plugin
  default:     True
  manual:      True

flag tactic
  description: Enable tactic plugin
  default:     True
  manual:      True

flag hlint
  description: Enable hlint plugin
  default:     True
  manual:      True

flag moduleName
  description: Enable moduleName plugin
  default:     True
  manual:      True

flag pragmas
  description: Enable pragmas plugin
  default:     True
  manual:      True

flag splice
  description: Enable splice plugin
  default:     True
  manual:      True

flag alternateNumberFormat
  description: Enable Alternate Number Format plugin
  default:     True
  manual:      True

flag qualifyImportedNames
  description: Enable qualifyImportedNames plugin
  default:     True
  manual:      True

flag selectionRange
  description: Enable selectionRange plugin
  default:     True
  manual:      True

flag changeTypeSignature
  description: Enable changeTypeSignature plugin
  default:     True
  manual:      True

-- formatters

flag floskell
  description: Enable floskell plugin
  default:     True
  manual:      True

flag fourmolu
  description: Enable fourmolu plugin
  default:     True
  manual:      True

flag ormolu
  description: Enable ormolu plugin
  default:     True
  manual:      True

flag stylishHaskell
  description: Enable stylishHaskell plugin
  default:     True
  manual:      True

flag brittany
  description: Enable brittany plugin
  default:     True
  manual:      True

flag dynamic
  description: Build with the dyn rts
  default:     True
  manual:      True

common example-plugins
  hs-source-dirs: plugins/default/src
  other-modules: Ide.Plugin.Example,
                 Ide.Plugin.Example2

common class
  if flag(class) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-class-plugin ^>= 1.0
    cpp-options: -Dclass

common callHierarchy
  if flag(callHierarchy)
    build-depends: hls-call-hierarchy-plugin ^>= 1.0
    cpp-options: -DcallHierarchy

common haddockComments
  if flag(haddockComments)
    build-depends: hls-haddock-comments-plugin ^>= 1.0
    cpp-options: -DhaddockComments

common eval
  if flag(eval)
    build-depends: hls-eval-plugin ^>= 1.2
    cpp-options: -Deval

common importLens
  if flag(importLens)
    build-depends: hls-explicit-imports-plugin ^>= 1.1
    cpp-options: -DimportLens

common refineImports
  if flag(refineImports)
    build-depends: hls-refine-imports-plugin ^>=1.0
    cpp-options: -DrefineImports

common rename
  if flag(rename)
    build-depends: hls-rename-plugin ^>= 1.0
    cpp-options: -Drename

common retrie
  if flag(retrie) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-retrie-plugin ^>= 1.0
    cpp-options: -Dretrie

common tactic
  if flag(tactic) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-tactics-plugin >=1.2.0.0 && <1.7
    cpp-options: -Dtactic

common hlint
  if flag(hlint) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-hlint-plugin ^>= 1.0
    cpp-options: -Dhlint

common moduleName
  if flag(moduleName)
    build-depends: hls-module-name-plugin ^>= 1.0
    cpp-options: -DmoduleName

common pragmas
  if flag(pragmas)
    build-depends: hls-pragmas-plugin ^>= 1.0
    cpp-options: -Dpragmas

common splice
  if flag(splice) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-splice-plugin ^>=1.0.0.1
    cpp-options: -Dsplice

common alternateNumberFormat
  if flag(alternateNumberFormat)
    build-depends: hls-alternate-number-format-plugin ^>= 1.1
    cpp-options: -DalternateNumberFormat

common qualifyImportedNames
  if flag(qualifyImportedNames)
    build-depends: hls-qualify-imported-names-plugin ^>=1.0
    cpp-options: -DqualifyImportedNames

common selectionRange
  if flag(selectionRange)
    build-depends: hls-selection-range-plugin ^>= 1.0
    cpp-options: -DselectionRange

common changeTypeSignature
  if flag(changeTypeSignature)
    build-depends: hls-change-type-signature-plugin ^>= 1.0
    cpp-options: -DchangeTypeSignature

-- formatters

common floskell
  if flag(floskell)
    build-depends: hls-floskell-plugin ^>= 1.0
    cpp-options: -Dfloskell

common fourmolu
  if flag(fourmolu)
    build-depends: hls-fourmolu-plugin ^>= 1.0
    cpp-options: -Dfourmolu

common ormolu
  if flag(ormolu)
    build-depends: hls-ormolu-plugin ^>= 1.0
    cpp-options: -Dormolu

common stylishHaskell
  if flag(stylishHaskell) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-stylish-haskell-plugin ^>= 1.0
    cpp-options: -DstylishHaskell

common brittany
  if flag(brittany) && (impl(ghc < 9.0.2) || flag(ignore-plugins-ghc-bounds))
    build-depends: hls-brittany-plugin ^>= 1.0
    cpp-options: -Dbrittany

executable haskell-language-server
  import:             common-deps
                    -- configuration
                    , warnings
                    , pedantic
                    -- plugins
                    , example-plugins
                    , callHierarchy
                    , changeTypeSignature
                    , class
                    , haddockComments
                    , eval
                    , importLens
                    , refineImports
                    , rename
                    , retrie
                    , tactic
                    , hlint
                    , moduleName
                    , pragmas
                    , splice
                    , alternateNumberFormat
                    , qualifyImportedNames
                    , selectionRange
                    , floskell
                    , fourmolu
                    , ormolu
                    , stylishHaskell
                    , brittany

  main-is:          Main.hs
  hs-source-dirs:   exe
  other-modules:    Plugins

  ghc-options:
    -threaded
    -- allow user RTS overrides
    -rtsopts
    -- disable idle GC
    -- increase nursery size
    -- Enable collection of heap statistics
    "-with-rtsopts=-I0 -A128M -T"
    -Wno-unticked-promoted-constructors
  if flag(pedantic)
    ghc-options: -Werror
  if !os(windows) && flag(dynamic)
  -- We want to link against the dyn rts just like official GHC binaries do;
  --   the linked rts determines how external libs are loaded dynamically by TH.
  -- The standard way of doing this is via the --enable-dynamic-executables Cabal option
  -- Unfortunately it doesnt' work, see https://github.com/haskell/haskell-language-server/issues/2659
  -- One can use --ghc-options=-dynamic but this gets applied to the dependencies as well,
  -- which results in massive rebuilds and incompatibilities with profiling.
  -- So instead we set the -dynamic flag diretly here.
    ghc-options: -dynamic

  build-depends:
    , aeson
    , async
    , base16-bytestring
    , binary
    , bytestring
    , containers
    , cryptohash-sha1
    , deepseq
    , ghc
    , ghc-boot-th
    , ghcide
    , hashable
    , haskell-language-server
    , lsp
    , hie-bios
    , hiedb
    , lens
    , regex-tdfa
    , optparse-applicative
    , hls-plugin-api
    , lens
    , mtl
    , regex-tdfa
    , safe-exceptions
    , hls-graph
    , sqlite-simple
    , stm
    , temporary
    , transformers
    , unordered-containers

  default-language: Haskell2010
  default-extensions: DataKinds, TypeOperators

executable haskell-language-server-wrapper
  import:           common-deps
                  , warnings
                  , pedantic
  main-is:          Wrapper.hs
  hs-source-dirs:   exe
  other-modules:    Paths_haskell_language_server
  autogen-modules:  Paths_haskell_language_server
  ghc-options:
    -threaded
    -- allow user RTS overrides
    -rtsopts
    -- disable idle GC
    -- increase nursery size
    "-with-rtsopts=-I0 -A128M"

  build-depends:
    , data-default
    , ghc
    , ghc-paths
    , ghcide
    , gitrev
    , haskell-language-server
    , hie-bios
    , optparse-applicative
    , optparse-simple
    , process
  if !os(windows)
      build-depends:
          unix
        , containers

  default-language: Haskell2010


test-suite func-test
  import:             common-deps
                    , warnings
                    , pedantic
  type:               exitcode-stdio-1.0
  default-language:   Haskell2010
  build-tool-depends:
    haskell-language-server:haskell-language-server -any,
    ghcide:ghcide-test-preprocessor -any

  build-depends:
    , bytestring
    , data-default
    , hspec-expectations
    , lens
    , lens-aeson
    , ghcide
    , hls-test-utils ^>=1.3
    , lsp-types
    , aeson
    , hls-plugin-api
    , lsp-test
    , containers
    , unordered-containers

  hs-source-dirs:     test/functional test/utils

  main-is:            Main.hs
  other-modules:
    Command
    Completion
    Config
    Deferred
    Definition
    Diagnostic
    Format
    FunctionalBadProject
    FunctionalCodeAction
    HieBios
    Highlight
    Progress
    Reference
    Symbol
    TypeDefinition
    Test.Hls.Command
    Test.Hls.Flags

  default-extensions: OverloadedStrings
  ghc-options:
    -threaded -rtsopts -with-rtsopts=-N

-- Duplicating inclusion plugin conditions until tests are moved to their own packages
  if flag(eval)
    cpp-options: -Deval
-- formatters
  if flag(floskell) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
    cpp-options: -Dfloskell
  if flag(fourmolu)
    cpp-options: -Dfourmolu
  if flag(ormolu)
    cpp-options: -Dormolu

test-suite wrapper-test
  import:             common-deps
                    , warnings
                    , pedantic
  type:               exitcode-stdio-1.0
  build-tool-depends:
    haskell-language-server:haskell-language-server-wrapper -any,
    haskell-language-server:haskell-language-server -any

  default-language:   Haskell2010
  build-depends:
      process
    , hls-test-utils

  hs-source-dirs:     test/wrapper
  main-is:            Main.hs