Skip to content

Commit 46f8049

Browse files
committed
Extract cabal plugin in its own package
1 parent b689abb commit 46f8049

File tree

12 files changed

+206
-0
lines changed

12 files changed

+206
-0
lines changed

cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ packages:
66
./ghcide
77
./hls-plugin-api
88
./hls-test-utils
9+
./plugins/hls-cabal-plugin
910
./plugins/hls-tactics-plugin
1011
./plugins/hls-brittany-plugin
1112
./plugins/hls-stylish-haskell-plugin

exe/Plugins.hs

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import qualified Ide.Plugin.QualifyImportedNames as QualifyImportedNames
2424
import qualified Ide.Plugin.CallHierarchy as CallHierarchy
2525
#endif
2626

27+
#if cabal
28+
import qualified Ide.Plugin.Cabal as Cabal
29+
#endif
30+
2731
#if class
2832
import qualified Ide.Plugin.Class as Class
2933
#endif
@@ -130,6 +134,9 @@ idePlugins recorder includeExamples = pluginDescToIdePlugins allPlugins
130134
then basePlugins ++ examplePlugins
131135
else basePlugins
132136
basePlugins =
137+
#if cabal
138+
Cabal.descriptor pluginRecorder "cabal" :
139+
#endif
133140
#if pragmas
134141
Pragmas.descriptor "pragmas" :
135142
#endif

haskell-language-server.cabal

+19
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ flag ignore-plugins-ghc-bounds
101101
default: False
102102
manual: True
103103

104+
105+
flag cabal
106+
description: Enable cabal plugin
107+
default: True
108+
manual: True
109+
104110
flag class
105111
description: Enable class plugin
106112
default: True
@@ -229,6 +235,18 @@ common example-plugins
229235
Ide.Plugin.Example2,
230236
Ide.Plugin.ExampleCabal
231237

238+
common cabal
239+
if flag(cabal)
240+
build-depends: hls-cabal-plugin ^>= 0.1
241+
cpp-options: -Dcabal
242+
243+
244+
common cabal
245+
if flag(cabal)
246+
build-depends: hls-cabal-plugin ^>= 0.1
247+
cpp-options: -Dcabal
248+
249+
232250
common class
233251
if flag(class)
234252
build-depends: hls-class-plugin ^>= 1.0
@@ -353,6 +371,7 @@ executable haskell-language-server
353371
, pedantic
354372
-- plugins
355373
, example-plugins
374+
, cabal
356375
, callHierarchy
357376
, changeTypeSignature
358377
, class

plugins/hls-cabal-plugin/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for hls-cabal-plugin
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

plugins/hls-cabal-plugin/LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2022 Fendor
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cabal-version: 3.0
2+
name: hls-cabal-plugin
3+
version: 0.1.0.0
4+
synopsis:
5+
homepage:
6+
license: MIT
7+
license-file: LICENSE
8+
author: Fendor
9+
maintainer: [email protected]
10+
category: Development
11+
extra-source-files: CHANGELOG.md
12+
13+
library
14+
exposed-modules: Ide.Plugin.Cabal
15+
build-depends:
16+
, aeson
17+
, base >=4.12 && <5
18+
, czipwith
19+
, extra
20+
, filepath
21+
, ghc-exactprint
22+
, ghcide >=1.6 && <1.8
23+
, hls-plugin-api >=1.3 && <1.5
24+
, lens
25+
, lsp-types
26+
, text
27+
, transformers
28+
29+
-- see https://github.com/lspitzner/brittany/issues/364
30+
-- TODO: remove these when GH issue #2005 is resolved
31+
hs-source-dirs: src
32+
default-language: Haskell2010
33+
34+
test-suite hls-cabal-plugin-test
35+
default-language: Haskell2010
36+
type: exitcode-stdio-1.0
37+
hs-source-dirs: test
38+
main-is: Main.hs
39+
build-depends:
40+
, base
41+
, filepath
42+
, hls-cabal-plugin
43+
, hls-test-utils ^>=1.3
44+
, lsp
45+
, lsp-types
46+
, text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DeriveAnyClass #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE DuplicateRecordFields #-}
5+
{-# LANGUAGE FlexibleContexts #-}
6+
{-# LANGUAGE FlexibleInstances #-}
7+
{-# LANGUAGE LambdaCase #-}
8+
{-# LANGUAGE OverloadedStrings #-}
9+
{-# LANGUAGE RecordWildCards #-}
10+
{-# LANGUAGE TupleSections #-}
11+
{-# LANGUAGE TypeFamilies #-}
12+
{-# LANGUAGE ViewPatterns #-}
13+
14+
module Ide.Plugin.Cabal where
15+
16+
import Control.Monad.IO.Class
17+
import Data.Aeson
18+
import qualified Data.Text as T
19+
import Development.IDE as D
20+
import GHC.Generics
21+
import Ide.PluginUtils
22+
import Ide.Types
23+
import Language.LSP.Types
24+
25+
26+
newtype Log = LogText T.Text deriving Show
27+
28+
instance Pretty Log where
29+
pretty = \case
30+
LogText log -> pretty log
31+
32+
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
33+
descriptor recorder plId = (defaultCabalPluginDescriptor plId)
34+
{ pluginHandlers = mkPluginHandler STextDocumentCodeLens (codeLens recorder)
35+
}
36+
37+
-- ---------------------------------------------------------------------
38+
39+
codeLens :: Recorder (WithPriority Log) -> PluginMethodHandler IdeState TextDocumentCodeLens
40+
codeLens recorder _ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = liftIO $ do
41+
log Debug $ LogText "ExampleCabal.codeLens entered (ideLogger)"
42+
case uriToFilePath' uri of
43+
Just (toNormalizedFilePath -> _filePath) -> do
44+
let
45+
title = "Add TODO Item via Code Lens"
46+
range = Range (Position 3 0) (Position 4 0)
47+
let cmdParams = AddTodoParams uri "do abc"
48+
cmd = mkLspCommand plId "codelens.todo" title (Just [toJSON cmdParams])
49+
pure $ Right $ List [ CodeLens range (Just cmd) Nothing ]
50+
Nothing -> pure $ Right $ List []
51+
where
52+
log = logWith recorder
53+
-- ---------------------------------------------------------------------
54+
55+
data AddTodoParams = AddTodoParams
56+
{ file :: Uri -- ^ Uri of the file to add the pragma to
57+
, todoText :: T.Text
58+
}
59+
deriving (Show, Eq, Generic, ToJSON, FromJSON)

plugins/hls-cabal-plugin/test/Main.hs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main
3+
( main
4+
) where
5+
6+
import qualified Data.Text as T
7+
import qualified Language.LSP.Types.Lens as L
8+
import Ide.Plugin.Cabal
9+
import System.FilePath
10+
import Test.Hls
11+
import Test.Hls.Util (onlyWorkForGhcVersions)
12+
13+
main :: IO ()
14+
main = defaultTestRunner tests
15+
16+
pragmasPlugin :: PluginDescriptor IdeState
17+
pragmasPlugin = descriptor mempty "cabal"
18+
19+
tests :: TestTree
20+
tests =
21+
testGroup "cabal"
22+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cabal-version: 3.0
2+
name: hls-cabal-plugin
3+
version: 0.1.0.0
4+
synopsis:
5+
homepage:
6+
license: MIT
7+
license-file: LICENSE
8+
author: Fendor
9+
maintainer: [email protected]
10+
category: Development
11+
extra-source-files: CHANGELOG.md
12+
13+
library
14+
exposed-modules: IDE.Plugin.Cabal
15+
build-depends: base ^>=4.14.3.0
16+
hs-source-dirs: src
17+
default-language: Haskell2010
18+
19+
test-suite hls-cabal-plugin-test
20+
default-language: Haskell2010
21+
type: exitcode-stdio-1.0
22+
hs-source-dirs: test
23+
main-is: Main.hs
24+
build-depends: base ^>=4.14.3.0

stack-lts16.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ packages:
88
- ./shake-bench
99
- ./hls-plugin-api
1010
- ./hls-test-utils
11+
- ./plugins/hls-cabal-plugin
1112
- ./plugins/hls-call-hierarchy-plugin
1213
- ./plugins/hls-class-plugin
1314
- ./plugins/hls-haddock-comments-plugin

stack-lts19.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ packages:
88
- ./hls-plugin-api
99
- ./hls-test-utils
1010
# - ./shake-bench
11+
- ./plugins/hls-cabal-plugin
1112
- ./plugins/hls-call-hierarchy-plugin
1213
- ./plugins/hls-class-plugin
1314
- ./plugins/hls-haddock-comments-plugin

stack.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ packages:
88
- ./hls-plugin-api
99
- ./hls-test-utils
1010
- ./shake-bench
11+
- ./plugins/hls-cabal-plugin
1112
- ./plugins/hls-call-hierarchy-plugin
1213
- ./plugins/hls-class-plugin
1314
# - ./plugins/hls-haddock-comments-plugin

0 commit comments

Comments
 (0)