Skip to content

Add hls-cabal-project-plugin for cabal.project file support #4548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2260,3 +2260,55 @@ test-suite ghcide-bench-test
OverloadedStrings
RecordWildCards
ViewPatterns

flag cabalProject
description: Enable cabal project plugin
default: True
manual: True

common cabalProject
if flag(cabalProject)
build-depends: haskell-language-server:hls-cabal-project-plugin
cpp-options: -Dhls_cabalProject

library hls-cabal-project-plugin
import: defaults, pedantic, warnings
if !flag(cabalProject)
buildable: False
exposed-modules: Ide.Plugin.CabalProject
hs-source-dirs: plugins/hls-cabal-project-plugin/src
build-depends:
, base
, bytestring
, containers
, deepseq
, directory
, filepath
, ghcide == 2.10.0.0
, hls-plugin-api == 2.10.0.0
, lens
, lsp ^>=2.7
, lsp-types ^>=2.3
, text
, text-rope
, transformers
, unordered-containers >=0.2.10.0

default-extensions:
DataKinds
OverloadedStrings
RecordWildCards

test-suite hls-cabal-project-plugin-tests
import: defaults, pedantic, test-defaults, warnings
if !flag(cabalProject)
buildable: False
type: exitcode-stdio-1.0
hs-source-dirs: plugins/hls-cabal-project-plugin/test
main-is: Main.hs
build-depends:
, base
, filepath
, haskell-language-server:hls-cabal-project-plugin
, hls-test-utils == 2.10.0.0
, text
51 changes: 51 additions & 0 deletions plugins/hls-cabal-project-plugin/hls-cabal-project-plugin.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cabal-version: 3.0
name: hls-cabal-project-plugin
version: 2.10.0.0
synopsis: Cabal project file support for Haskell Language Server
description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
category: Development
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: https://github.com/haskell/haskell-language-server/graphs/contributors
license: Apache-2.0
license-file: LICENSE
build-type: Simple

library
import: defaults, pedantic, warnings
exposed-modules: Ide.Plugin.CabalProject
hs-source-dirs: src
build-depends:
, base
, bytestring
, containers
, deepseq
, directory
, filepath
, ghcide == 2.10.0.0
, hls-plugin-api == 2.10.0.0
, lens
, lsp ^>=2.7
, lsp-types ^>=2.3
, text
, text-rope
, transformers
, unordered-containers >=0.2.10.0

default-extensions:
DataKinds
OverloadedStrings
RecordWildCards

test-suite hls-cabal-project-plugin-tests
import: defaults, pedantic, test-defaults, warnings
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends:
, base
, filepath
, haskell-language-server:hls-cabal-project-plugin
, hls-test-utils == 2.10.0.0
, text
69 changes: 69 additions & 0 deletions plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Ide.Plugin.CabalProject (descriptor, Log (..)) where

import Control.DeepSeq
import Control.Lens ((^.))
import Control.Monad.Extra

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / flags (9.12, ubuntu-latest)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, ubuntu-latest, true)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, ubuntu-latest, true)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, macOS-latest, false)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, macOS-latest, false)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, ubuntu-latest, true)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, macOS-latest, false)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

Could not load module ‘Control.Monad.Extra’

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, windows-latest, true)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, windows-latest, true)

Could not load module ‘Control.Monad.Extra’.

Check failure on line 11 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, windows-latest, true)

Could not load module ‘Control.Monad.Extra’.
import Control.Monad.IO.Class
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Data.Text.Encoding as Encoding
import Data.Text.Utf16.Rope.Mixed as Rope
import Development.IDE as D
import Development.IDE.Core.PluginUtils
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.Graph (Key, alwaysRerun)

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / flags (9.12, ubuntu-latest)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, ubuntu-latest, true)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, ubuntu-latest, true)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, macOS-latest, false)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, macOS-latest, false)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, ubuntu-latest, true)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, macOS-latest, false)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

Could not load module ‘Development.IDE.Graph’

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.8, windows-latest, true)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.10, windows-latest, true)

Could not load module ‘Development.IDE.Graph’.

Check failure on line 20 in plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

View workflow job for this annotation

GitHub Actions / test (9.12, windows-latest, true)

Could not load module ‘Development.IDE.Graph’.
import Ide.Types
import qualified Language.LSP.Protocol.Lens as JL
import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types
import qualified Language.LSP.VFS as VFS

data Log
= LogModificationTime NormalizedFilePath FileVersion
| LogShake Shake.Log
| LogDocOpened Uri
| LogDocModified Uri
deriving (Show)

instance Pretty Log where
pretty = \case
LogShake log' -> pretty log'
LogModificationTime nfp modTime ->
"Modified:" <+> pretty (fromNormalizedFilePath nfp) <+> pretty (show modTime)
LogDocOpened uri ->
"Opened text document:" <+> pretty (getUri uri)
LogDocModified uri ->
"Modified text document:" <+> pretty (getUri uri)

descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor recorder plId = (defaultPluginDescriptor plId "Cabal Project File Support")
{ pluginHandlers = mkPluginHandler LSP.SMethod_TextDocumentDidOpen $
\ideState _ vfs (DidOpenTextDocumentParams TextDocumentItem{_uri,_version,_text}) -> do
let filePath = toNormalizedUri _uri
logWith recorder Debug $ LogDocOpened _uri
when (isCabalProjectFile filePath) $ do
-- TODO: Initialize project file handling
pure ()
, pluginHandlers = mkPluginHandler LSP.SMethod_TextDocumentDidChange $
\ideState _ vfs (DidChangeTextDocumentParams TextDocumentIdentifier{_uri} _ _) -> do
let filePath = toNormalizedUri _uri
logWith recorder Debug $ LogDocModified _uri
when (isCabalProjectFile filePath) $ do
-- TODO: Handle file changes
pure ()
, pluginRules = cabalProjectRules recorder plId
}

isCabalProjectFile :: NormalizedFilePath -> Bool
isCabalProjectFile filePath = "cabal.project" `T.isSuffixOf` T.pack (fromNormalizedFilePath filePath)

cabalProjectRules :: Recorder (WithPriority Log) -> PluginId -> Rules ()
cabalProjectRules recorder plId = do
-- TODO: Add rules for parsing and validating cabal.project files
pure ()
7 changes: 7 additions & 0 deletions src/HlsPlugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ import qualified Ide.Plugin.OverloadedRecordDot as OverloadedRecordDot
import qualified Ide.Plugin.Notes as Notes
#endif

#if hls_cabalProject
import qualified Ide.Plugin.CabalProject as CabalProject
#endif

-- formatters

#if hls_floskell
Expand Down Expand Up @@ -247,6 +251,9 @@ idePlugins recorder = pluginDescToIdePlugins allPlugins
#endif
#if hls_notes
let pId = "notes" in Notes.descriptor (pluginRecorder pId) pId :
#endif
#if hls_cabalProject
let pId = "cabal-project" in CabalProject.descriptor (pluginRecorder pId) pId :
#endif
GhcIde.descriptors (pluginRecorder "ghcide")

Loading