This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 208
[WIP] stylish-haskell plugin #1618
Open
lukasz-golebiewski
wants to merge
21
commits into
haskell:master
Choose a base branch
from
lukasz-golebiewski:stylish-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
39afabc
First draft of the Stylish (Haskell) plugin
lukasz-golebiewski 577519f
Add stylish formatter provider to HSImportSpec (failing)
EncodePanda 50f0a65
Extract formatLspConfig in FormatSpec
EncodePanda 4566617
Add first working draft of the stylish plugin
lukasz-golebiewski e631aa9
Update stack.yaml
lukasz-golebiewski a64db52
Update stack.yaml
lukasz-golebiewski 3bb0de8
Add stylish-haskell version to *.cabal
lukasz-golebiewski 9754065
Add stylish-haskell to stack*.yaml
lukasz-golebiewski 87ca5fd
Force HsYaml versions
lukasz-golebiewski ea10da5
Add HsYaml to .cabal
lukasz-golebiewski 1ef9650
Update cabal index snapshot
Avi-D-coder c0e5559
Merge branch 'master' into stylish-support
Avi-D-coder d143052
Add stylish with deps to stack yaml 8.8.2
lukasz-golebiewski 9e59e29
Add cabal-3.0.0.0
lukasz-golebiewski d8f274c
Merge branch 'master' of github.com:haskell/haskell-ide-engine into s…
lukasz-golebiewski 26f9e87
Revert "Add cabal-3.0.0.0"
lukasz-golebiewski 6f91f83
Add dependency on vector to stack-8.4.4
lukasz-golebiewski a1a6f75
Add dependency on Cabal-3.0.0.0
lukasz-golebiewski 15e816d
Set cabal to 2.4.1.0
lukasz-golebiewski 5988529
Downgrade cabal to 2.2.0.1
lukasz-golebiewski df7cce7
Merge branch 'master' of github.com:haskell/haskell-ide-engine into s…
lukasz-golebiewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You'll likely also need to add these to each
stack.yaml
and tohaskell-ide-engine.cabal
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 doesn't seem to be working :-(
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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
haskell-ide-engine
orstylish-haskell
, those remain BSD3-licensed. However, the compiled binary must adhere to the GPL license (which seems fine in this case). This is similar to e.g. the fact that GHC links againstlibgmp
by default.But, if this worries you, I am happy to add a flag to
stylish-haskell
that makes it pick the C-basedyaml
as a dependency rather thanHsYAML
?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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Assuming this is correct, this sounds totally reasonable.