-
Notifications
You must be signed in to change notification settings - Fork 206
[WIP] stylish-haskell plugin #1618
base: master
Are you sure you want to change the base?
Changes from 19 commits
39afabc
577519f
50f0a65
4566617
e631aa9
a64db52
3bb0de8
9754065
87ca5fd
ea10da5
1ef9650
c0e5559
d143052
9e59e29
d8f274c
26f9e87
6f91f83
a1a6f75
15e816d
5988529
df7cce7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Haskell.Ide.Engine.Plugin.Stylish where | ||
|
||
import Control.Monad.IO.Class (liftIO) | ||
import Data.Aeson (Value (Null)) | ||
import Data.List (intercalate) | ||
import qualified Data.Text as T | ||
import Haskell.Ide.Engine.MonadTypes | ||
import Haskell.Ide.Engine.PluginUtils (fullRange, pluginGetFile) | ||
import Language.Haskell.Stylish (ConfigPath (..), format) | ||
|
||
|
||
stylishDescriptor :: PluginId -> PluginDescriptor | ||
stylishDescriptor plId = PluginDescriptor | ||
{ pluginId = plId | ||
, pluginName = "Stylish" | ||
, pluginDesc = "Stylish is a tool to format source code." | ||
, pluginCommands = [] | ||
, pluginCodeActionProvider = Nothing | ||
, pluginDiagnosticProvider = Nothing | ||
, pluginHoverProvider = Nothing | ||
, pluginSymbolProvider = Nothing | ||
, pluginFormattingProvider = Just provider | ||
} | ||
|
||
provider :: FormattingProvider | ||
provider contents uri typ _ = | ||
case typ of | ||
FormatRange _ -> | ||
return $ IdeResultFail (IdeError PluginError (T.pack "Selection formatting for Stylish is not currently supported.") Null) | ||
FormatText -> pluginGetFile "stylish:" uri $ \file -> do | ||
res <- liftIO $ runStylish Nothing file contents | ||
case res of | ||
Left err -> return $ IdeResultFail | ||
(IdeError PluginError | ||
(T.pack $ "stylish: " ++ err) | ||
Null | ||
) | ||
Right new -> return $ IdeResultOk [TextEdit (fullRange contents) (T.pack $ ((intercalate "\n" new) <> "\n"))] | ||
|
||
|
||
runStylish :: Maybe ConfigPath -> FilePath -> T.Text -> IO (Either String [String]) | ||
runStylish config file contents = format config (Just file) (T.unpack contents) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,12 @@ extra-deps: | |
- hlint-2.2.10 | ||
- hoogle-5.0.17.11 | ||
- hsimport-0.11.0 | ||
- HsYAML-0.2.1.0 | ||
- HsYAML-aeson-0.2.0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll likely also need to add these to each There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be working :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to note that HsYAML is using GPL and the project licensing would be affected (not sure if it already is using libs with gpl) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally i am fine with linking a gpl lib but the project will have two yaml libs and maybe we should use only one (not in this pr) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also okay with GPL, however stylish-haskell just made the switch, we could ask them to switch back haskell/stylish-haskell@498d676 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure "fine" is the right wording, since we are not GPL, we do not really have the rights to using it, right? On the other hand, I doubt, too, that someone will sue us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I wasn't aware that HsYAML was GPL-licensed. I don't think it's a problem -- it's fine for a BSD3 application to depend on a GPL-licensed library. It does not affect the code of But, if this worries you, I am happy to add a flag to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afaiu we can use it without changing our licenses files but the license for hie artifacts linking HsYaml becomes auto gpl. So anybody could issue someone who doesnt respect the gpl resdistributing hie. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IANAL, if you argue that this is indeed just fine, I have nothing to say against it :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Assuming this is correct, this sounds totally reasonable. |
||
- ilist-0.3.1.0 | ||
- monad-dijkstra-0.1.1.2 | ||
- ormolu-0.0.3.1 | ||
- stylish-haskell-0.10.0.0 | ||
- semigroups-0.18.5 | ||
- temporary-1.2.1.1 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stack recommended to set cabal version explicitly in https://circleci.com/gh/haskell/haskell-ide-engine/13311
If this is incorrect then I don't think I know how to proceed with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this compile? Because, iirc, stack snapshots are bundled with
cabal-install
andCabal
versions, iirc, setting a custom Cabal version for a snapshot may not succeed. If it compiles, everything is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, I'm slowly bisecting towards the cabal version satisfying every dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And back to stack suggesting
Cabal-3.0.0.0
. Looks like stylish0.10.0.0
can't be used here and below because of conflicting dependencies :-(