Skip to content

Commit 6fbc602

Browse files
pepeiborraAilrun
andauthored
Extract an hls-brittany-plugin package (#1422)
* Extract a Brittany plugin * Add the brittany plugin to all the stack descriptors * Extract tests into a standalone testsuite * Drop AGPL flag * Change the default logger to print to stderr * add hls-brittany-plugin test suite to CI * Add strict version bounds These are completely unnecessary, but it's the approach that we seem to be taking * includes breaking API change: bump ghcide version number Co-authored-by: Junyoung/Clare Jang <[email protected]>
1 parent a05a842 commit 6fbc602

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+473
-185
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,9 @@ jobs:
135135
if: ${{ matrix.test }}
136136
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"
137137

138+
- name: Test brittany plugin
139+
if: ${{ matrix.test }}
140+
env:
141+
HLS_TEST_EXE: hls
142+
HLS_WRAPPER_TEST_EXE: hls-wrapper
143+
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ For example, `haskell-language-server` allows you to choose the formatting provi
301301
This option obviously would not make sense for language servers for other languages, or even for other Haskell language servers (which need not even support formatting).
302302

303303
Here is a list of the additional settings currently supported by `haskell-language-server`, along with their setting key (you may not need to know this) and default:
304-
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, `stylish-haskell`, or `brittany` (if compiled with AGPL)
304+
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, `stylish-haskell`, or `brittany` (if compiled with the brittany plugin)
305305
- Format on imports (`haskell.formatOnImportOn`, default true): whether to format after adding an import
306306
- Maximum number of problems to report (`haskell.maxNumberOfProblems`, default 100): the maximum number of problems the server will send to the client
307307
- Diagnostics on change (`haskell.diagnosticsOnChange`, default true): (currently unused)
@@ -648,7 +648,7 @@ This issue should be fixed in Stack versions >= 2.5.
648648
#### Problems with dynamic linking
649649

650650
As haskell-language-server prebuilt binaries are statically linked, they don't play well with projects using dynamic linking.
651-
An usual symptom is the presence of errors containing `unknown symbol` and it is typical in arch linux, where a dynamically linked version of ghc is used.
651+
An usual symptom is the presence of errors containing `unknown symbol` and it is typical in arch linux, where a dynamically linked version of ghc is used.
652652

653653
The workaround is to use a version of haskell-language-server compiled from source with `-dynamic` enabled`. See more details [here](https://github.com/haskell/haskell-language-server/issues/1160#issuecomment-756566273).
654654

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ packages:
55
./ghcide
66
./hls-plugin-api
77
./plugins/hls-tactics-plugin
8+
./plugins/hls-brittany-plugin
89
./plugins/hls-class-plugin
910
./plugins/hls-eval-plugin
1011
./plugins/hls-explicit-imports-plugin

docs/plugin-tutorial.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ idePlugins = pluginDescToIdePlugins allPlugins
9696
, Ormolu.descriptor "ormolu"
9797
, StylishHaskell.descriptor "stylish-haskell"
9898
, Retrie.descriptor "retrie"
99-
#if AGPL
10099
, Brittany.descriptor "brittany"
101-
#endif
102100
, Eval.descriptor "eval"
103101
]
104102
```

exe/Plugins.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Ide.Plugin.Ormolu as Ormolu
7171
import Ide.Plugin.StylishHaskell as StylishHaskell
7272
#endif
7373

74-
#if AGPL && brittany
74+
#if brittany
7575
import Ide.Plugin.Brittany as Brittany
7676
#endif
7777

ghcide/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ main = do
8888
Typecheck x | not argLSP -> Just x
8989
_ -> Nothing
9090

91-
,Main.argsLogger = logger
91+
,Main.argsLogger = pure logger
9292

9393
,Main.argsRules = do
9494
-- install the main and ghcide-plugin rules

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cabal-version: 2.2
22
build-type: Simple
33
category: Development
44
name: ghcide
5-
version: 1.0.0.0
5+
version: 1.1.0.0
66
license: Apache-2.0
77
license-file: LICENSE
88
author: Digital Asset and Ghcide contributors

ghcide/src/Development/IDE/Main.hs

Lines changed: 88 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,83 @@
11
module Development.IDE.Main (Arguments(..), defaultMain) where
2-
import Control.Concurrent.Extra (readVar)
3-
import Control.Exception.Safe (Exception (displayException),
4-
catchAny)
5-
import Control.Monad.Extra (concatMapM, unless, when)
6-
import Data.Default (Default (def))
7-
import qualified Data.HashMap.Strict as HashMap
8-
import Data.List.Extra (intercalate, isPrefixOf,
9-
nub, nubOrd, partition)
10-
import Data.Maybe (catMaybes, fromMaybe,
11-
isJust)
12-
import qualified Data.Text as T
13-
import Development.IDE (Action, Rules, noLogging)
14-
import Development.IDE.Core.Debouncer (newAsyncDebouncer)
15-
import Development.IDE.Core.FileStore (makeVFSHandle)
16-
import Development.IDE.Core.OfInterest (FileOfInterestStatus (OnDisk),
17-
kick, setFilesOfInterest)
18-
import Development.IDE.Core.RuleTypes (GenerateCore (GenerateCore),
19-
GetHieAst (GetHieAst),
20-
GhcSession (GhcSession),
21-
GhcSessionDeps (GhcSessionDeps),
22-
TypeCheck (TypeCheck))
23-
import Development.IDE.Core.Rules (GhcSessionIO (GhcSessionIO),
24-
mainRule)
25-
import Development.IDE.Core.Service (initialise, runAction)
26-
import Development.IDE.Core.Shake (IdeState (shakeExtras),
27-
ShakeExtras (state), uses)
28-
import Development.IDE.Core.Tracing (measureMemory)
29-
import Development.IDE.Core.IdeConfiguration (registerIdeConfiguration, IdeConfiguration(..))
30-
import Development.IDE.LSP.LanguageServer (runLanguageServer)
31-
import Development.IDE.Plugin (Plugin (pluginHandlers, pluginRules))
32-
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
33-
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
34-
import Development.IDE.Session (SessionLoadingOptions,
35-
getHieDbLoc,
36-
loadSessionWithOptions,
37-
runWithDb,
38-
setInitialDynFlags)
39-
import Development.IDE.Types.Location (toNormalizedFilePath')
40-
import Development.IDE.Types.Logger (Logger)
41-
import Development.IDE.Types.Options (IdeGhcSession,
42-
IdeOptions (optCheckParents, optCheckProject, optReportProgress),
43-
clientSupportsProgress,
44-
defaultIdeOptions)
45-
import Development.IDE.Types.Shake (Key (Key))
46-
import Development.Shake (action)
47-
import HIE.Bios.Cradle (findCradle)
48-
import Ide.Plugin.Config (CheckParents (NeverCheck),
49-
Config,
50-
getConfigFromNotification)
51-
import Ide.PluginUtils (allLspCmdIds',
52-
getProcessID,
53-
pluginDescToIdePlugins)
54-
import Ide.Types (IdePlugins)
55-
import qualified Language.LSP.Server as LSP
56-
import qualified System.Directory.Extra as IO
57-
import System.Exit (ExitCode (ExitFailure),
58-
exitWith)
59-
import System.FilePath (takeExtension,
60-
takeFileName)
61-
import System.IO (hPutStrLn, hSetEncoding,
62-
stderr, stdout, utf8)
63-
import System.Time.Extra (offsetTime, showDuration)
64-
import Text.Printf (printf)
65-
import Data.Hashable (hashed)
2+
import Control.Concurrent.Extra (newLock, readVar,
3+
withLock)
4+
import Control.Exception.Safe (Exception (displayException),
5+
catchAny)
6+
import Control.Monad.Extra (concatMapM, unless,
7+
when)
8+
import Data.Default (Default (def))
9+
import qualified Data.HashMap.Strict as HashMap
10+
import Data.Hashable (hashed)
11+
import Data.List.Extra (intercalate, isPrefixOf,
12+
nub, nubOrd, partition)
13+
import Data.Maybe (catMaybes, fromMaybe,
14+
isJust)
15+
import qualified Data.Text as T
16+
import qualified Data.Text.IO as T
17+
import Development.IDE (Action, Rules)
18+
import Development.IDE.Core.Debouncer (newAsyncDebouncer)
19+
import Development.IDE.Core.FileStore (makeVFSHandle)
20+
import Development.IDE.Core.IdeConfiguration (IdeConfiguration (..),
21+
registerIdeConfiguration)
22+
import Development.IDE.Core.OfInterest (FileOfInterestStatus (OnDisk),
23+
kick,
24+
setFilesOfInterest)
25+
import Development.IDE.Core.RuleTypes (GenerateCore (GenerateCore),
26+
GetHieAst (GetHieAst),
27+
GhcSession (GhcSession),
28+
GhcSessionDeps (GhcSessionDeps),
29+
TypeCheck (TypeCheck))
30+
import Development.IDE.Core.Rules (GhcSessionIO (GhcSessionIO),
31+
mainRule)
32+
import Development.IDE.Core.Service (initialise, runAction)
33+
import Development.IDE.Core.Shake (IdeState (shakeExtras),
34+
ShakeExtras (state),
35+
uses)
36+
import Development.IDE.Core.Tracing (measureMemory)
37+
import Development.IDE.LSP.LanguageServer (runLanguageServer)
38+
import Development.IDE.Plugin (Plugin (pluginHandlers, pluginRules))
39+
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
40+
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
41+
import Development.IDE.Session (SessionLoadingOptions,
42+
getHieDbLoc,
43+
loadSessionWithOptions,
44+
runWithDb,
45+
setInitialDynFlags)
46+
import Development.IDE.Types.Location (toNormalizedFilePath')
47+
import Development.IDE.Types.Logger (Logger (Logger))
48+
import Development.IDE.Types.Options (IdeGhcSession,
49+
IdeOptions (optCheckParents, optCheckProject, optReportProgress),
50+
clientSupportsProgress,
51+
defaultIdeOptions)
52+
import Development.IDE.Types.Shake (Key (Key))
53+
import Development.Shake (action)
54+
import HIE.Bios.Cradle (findCradle)
55+
import Ide.Plugin.Config (CheckParents (NeverCheck),
56+
Config,
57+
getConfigFromNotification)
58+
import Ide.PluginUtils (allLspCmdIds',
59+
getProcessID,
60+
pluginDescToIdePlugins)
61+
import Ide.Types (IdePlugins)
62+
import qualified Language.LSP.Server as LSP
63+
import qualified System.Directory.Extra as IO
64+
import System.Exit (ExitCode (ExitFailure),
65+
exitWith)
66+
import System.FilePath (takeExtension,
67+
takeFileName)
68+
import System.IO (BufferMode (LineBuffering),
69+
hPutStrLn,
70+
hSetBuffering,
71+
hSetEncoding, stderr,
72+
stdout, utf8)
73+
import System.Time.Extra (offsetTime,
74+
showDuration)
75+
import Text.Printf (printf)
6676

6777
data Arguments = Arguments
6878
{ argsOTMemoryProfiling :: Bool
6979
, argFiles :: Maybe [FilePath] -- ^ Nothing: lsp server ; Just: typecheck and exit
70-
, argsLogger :: Logger
80+
, argsLogger :: IO Logger
7181
, argsRules :: Rules ()
7282
, argsHlsPlugins :: IdePlugins IdeState
7383
, argsGhcidePlugin :: Plugin Config -- ^ Deprecated
@@ -82,7 +92,7 @@ instance Default Arguments where
8292
def = Arguments
8393
{ argsOTMemoryProfiling = False
8494
, argFiles = Nothing
85-
, argsLogger = noLogging
95+
, argsLogger = stderrLogger
8696
, argsRules = mainRule >> action kick
8797
, argsGhcidePlugin = mempty
8898
, argsHlsPlugins = pluginDescToIdePlugins Ghcide.descriptors
@@ -93,9 +103,18 @@ instance Default Arguments where
93103
, argsGetHieDbLoc = getHieDbLoc
94104
}
95105

106+
-- | Cheap stderr logger that relies on LineBuffering
107+
stderrLogger :: IO Logger
108+
stderrLogger = do
109+
lock <- newLock
110+
return $ Logger $ \p m -> withLock lock $
111+
T.hPutStrLn stderr $ "[" <> T.pack (show p) <> "] " <> m
112+
96113
defaultMain :: Arguments -> IO ()
97114
defaultMain Arguments{..} = do
98115
pid <- T.pack . show <$> getProcessID
116+
logger <- argsLogger
117+
hSetBuffering stderr LineBuffering
99118

100119
let hlsPlugin = asGhcIdePlugin argsDefaultHlsConfig argsHlsPlugins
101120
hlsCommands = allLspCmdIds' pid argsHlsPlugins
@@ -134,7 +153,7 @@ defaultMain Arguments{..} = do
134153
argsDefaultHlsConfig
135154
rules
136155
(Just env)
137-
argsLogger
156+
logger
138157
debouncer
139158
options
140159
vfs
@@ -171,7 +190,7 @@ defaultMain Arguments{..} = do
171190
{ optCheckParents = pure NeverCheck
172191
, optCheckProject = pure False
173192
}
174-
ide <- initialise argsDefaultHlsConfig rules Nothing argsLogger debouncer options vfs hiedb hieChan
193+
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
175194
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
176195

177196
putStrLn "\nStep 4/4: Type checking the files"
@@ -199,7 +218,7 @@ defaultMain Arguments{..} = do
199218
Key GhcSessionDeps :
200219
[k | (_, k) <- HashMap.keys values, k /= Key GhcSessionIO]
201220
++ [Key GhcSessionIO]
202-
measureMemory argsLogger [keys] consoleObserver valuesRef
221+
measureMemory logger [keys] consoleObserver valuesRef
203222

204223
unless (null failed) (exitWith $ ExitFailure (length failed))
205224
{-# ANN defaultMain ("HLint: ignore Use nubOrd" :: String) #-}

haskell-language-server.cabal

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ extra-source-files:
2020
ChangeLog.md
2121
include/ghc-api-version.h
2222

23-
flag agpl
24-
description: Enable AGPL dependencies
25-
default: True
26-
manual: True
27-
2823
flag pedantic
2924
description: Enable -Werror
3025
default: False
@@ -34,10 +29,6 @@ source-repository head
3429
type: git
3530
location: https://github.com/haskell/haskell-language-server
3631

37-
common agpl
38-
if flag(agpl)
39-
cpp-options: -DAGPL
40-
4132
common common-deps
4233
build-depends:
4334
, base >=4.12 && <5
@@ -47,7 +38,7 @@ common common-deps
4738
, text
4839

4940
library
50-
import: agpl, common-deps
41+
import: common-deps
5142
exposed-modules:
5243
Ide.Arguments
5344
Ide.Main
@@ -64,7 +55,7 @@ library
6455
, cryptohash-sha1
6556
, data-default
6657
, ghc
67-
, ghcide ^>= 1.0.0.0
58+
, ghcide ^>= 1.1.0.0
6859
, gitrev
6960
, lsp
7061
, hie-bios
@@ -269,15 +260,11 @@ common stylishHaskell
269260
cpp-options: -DstylishHaskell
270261

271262
common brittany
272-
if (flag(brittany) || flag(all-formatters)) && flag(agpl)
273-
hs-source-dirs: plugins/default/src
274-
other-modules: Ide.Plugin.Brittany
275-
build-depends: brittany >= 0.13.1.0
276-
cpp-options: -Dbrittany
263+
if (flag(brittany) || flag(all-formatters))
264+
build-depends: hls-brittany-plugin ^>= 1.0.0.0
277265

278266
executable haskell-language-server
279-
import: agpl
280-
, common-deps
267+
import: common-deps
281268
-- plugins
282269
, example-plugins
283270
, class
@@ -349,7 +336,7 @@ executable haskell-language-server
349336
default-extensions: DataKinds, TypeOperators
350337

351338
executable haskell-language-server-wrapper
352-
import: agpl, common-deps
339+
import: common-deps
353340
main-is: Wrapper.hs
354341
hs-source-dirs: exe
355342
other-modules: Paths_haskell_language_server
@@ -382,7 +369,7 @@ executable haskell-language-server-wrapper
382369
-- We removed it due to issues with stack when loading the project using a stack based hie.yaml
383370
-- See https://github.com/haskell/haskell-language-server/issues/114
384371
common hls-test-utils
385-
import: agpl, common-deps
372+
import: common-deps
386373
hs-source-dirs: test/utils
387374
other-modules: Test.Hls.Util
388375
build-depends:
@@ -414,7 +401,7 @@ common hls-test-utils
414401
default-language: Haskell2010
415402

416403
test-suite func-test
417-
import: agpl, common-deps, hls-test-utils
404+
import: common-deps, hls-test-utils
418405
type: exitcode-stdio-1.0
419406
default-language: Haskell2010
420407
build-tool-depends:
@@ -471,7 +458,7 @@ test-suite func-test
471458
ghc-options: -Werror -Wredundant-constraints
472459

473460
test-suite wrapper-test
474-
import: agpl, hls-test-utils
461+
import: hls-test-utils
475462
type: exitcode-stdio-1.0
476463
build-tool-depends:
477464
haskell-language-server:haskell-language-server-wrapper -any

nix/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let
2121
shake-bench = gitignoreSource ../shake-bench;
2222
hie-compat = gitignoreSource ../hie-compat;
2323
hls-plugin-api = gitignoreSource ../hls-plugin-api;
24+
hls-brittany-plugin = gitignoreSource ../plugins/hls-brittany-plugin;
2425
hls-class-plugin = gitignoreSource ../plugins/hls-class-plugin;
2526
hls-haddock-comments-plugin = gitignoreSource ../plugins/hls-haddock-comments-plugin;
2627
hls-eval-plugin = gitignoreSource ../plugins/hls-eval-plugin;

0 commit comments

Comments
 (0)