This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Invert the dependency with hls-plugin-api #963
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
module Development.IDE.Plugin.Formatter | ||
( | ||
formatting | ||
, rangeFormatting | ||
) | ||
where | ||
|
||
import qualified Data.Map as Map | ||
import qualified Data.Text as T | ||
import Development.IDE | ||
import Ide.PluginUtils | ||
import Ide.Types | ||
import Ide.Plugin.Config | ||
import qualified Language.Haskell.LSP.Core as LSP | ||
import Language.Haskell.LSP.Types | ||
import Text.Regex.TDFA.Text() | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
formatting :: Map.Map PluginId (FormattingProvider IdeState IO) | ||
-> LSP.LspFuncs Config -> IdeState -> DocumentFormattingParams | ||
-> IO (Either ResponseError (List TextEdit)) | ||
formatting providers lf ideState | ||
(DocumentFormattingParams (TextDocumentIdentifier uri) params _mprogress) | ||
= doFormatting lf providers ideState FormatText uri params | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
rangeFormatting :: Map.Map PluginId (FormattingProvider IdeState IO) | ||
-> LSP.LspFuncs Config -> IdeState -> DocumentRangeFormattingParams | ||
-> IO (Either ResponseError (List TextEdit)) | ||
rangeFormatting providers lf ideState | ||
(DocumentRangeFormattingParams (TextDocumentIdentifier uri) range params _mprogress) | ||
= doFormatting lf providers ideState (FormatRange range) uri params | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
doFormatting :: LSP.LspFuncs Config -> Map.Map PluginId (FormattingProvider IdeState IO) | ||
-> IdeState -> FormattingType -> Uri -> FormattingOptions | ||
-> IO (Either ResponseError (List TextEdit)) | ||
doFormatting lf providers ideState ft uri params = do | ||
mc <- LSP.config lf | ||
let mf = maybe "none" formattingProvider mc | ||
case Map.lookup (PluginId mf) providers of | ||
Just provider -> | ||
case uriToFilePath uri of | ||
Just (toNormalizedFilePath -> fp) -> do | ||
(_, mb_contents) <- runAction "Formatter" ideState $ getFileContents fp | ||
case mb_contents of | ||
Just contents -> do | ||
logDebug (ideLogger ideState) $ T.pack $ | ||
"Formatter.doFormatting: contents=" ++ show contents -- AZ | ||
provider lf ideState ft contents fp params | ||
Nothing -> return $ Left $ responseError $ T.pack $ "Formatter plugin: could not get file contents for " ++ show uri | ||
Nothing -> return $ Left $ responseError $ T.pack $ "Formatter plugin: uriToFilePath failed for: " ++ show uri | ||
Nothing -> return $ Left $ responseError $ mconcat | ||
[ "Formatter plugin: no formatter found for:[" | ||
, mf | ||
, "]" | ||
, if mf == "brittany" | ||
then T.unlines | ||
[ "\nThe haskell-language-server must be compiled with the agpl flag to provide Brittany." | ||
, "Stack users add 'agpl: true' in the flags section of the 'stack.yaml' file." | ||
, "The 'haskell-language-server.cabal' file already has this flag enabled by default." | ||
, "For more information see: https://github.com/haskell/haskell-language-server/issues/269" | ||
] | ||
else "" | ||
] | ||
|
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,65 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Development.IDE.Plugin.GhcIde | ||
( | ||
descriptor | ||
) where | ||
|
||
import Data.Aeson | ||
import Development.IDE | ||
import Development.IDE.Plugin.Completions | ||
import Development.IDE.Plugin.CodeAction | ||
import Development.IDE.LSP.HoverDefinition | ||
import Development.IDE.LSP.Outline | ||
import Ide.PluginUtils | ||
import Ide.Types | ||
import Language.Haskell.LSP.Types | ||
import Text.Regex.TDFA.Text() | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
descriptor :: PluginId -> PluginDescriptor IdeState | ||
descriptor plId = (defaultPluginDescriptor plId) | ||
{ pluginCommands = [PluginCommand (CommandId "typesignature.add") "adds a signature" commandAddSignature] | ||
, pluginCodeActionProvider = Just codeAction' | ||
, pluginCodeLensProvider = Just codeLens' | ||
, pluginHoverProvider = Just hover' | ||
, pluginSymbolsProvider = Just symbolsProvider | ||
, pluginCompletionProvider = Just getCompletionsLSP | ||
} | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
hover' :: HoverProvider IdeState | ||
hover' ideState params = do | ||
logInfo (ideLogger ideState) "GhcIde.hover entered (ideLogger)" -- AZ | ||
hover ideState params | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
commandAddSignature :: CommandFunction IdeState WorkspaceEdit | ||
commandAddSignature lf ide params | ||
= commandHandler lf ide (ExecuteCommandParams "typesignature.add" (Just (List [toJSON params])) Nothing) | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
codeAction' :: CodeActionProvider IdeState | ||
codeAction' lf ide _ doc range context = fmap List <$> codeAction lf ide doc range context | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
codeLens' :: CodeLensProvider IdeState | ||
codeLens' lf ide _ params = codeLens lf ide params | ||
|
||
-- --------------------------------------------------------------------- | ||
|
||
symbolsProvider :: SymbolsProvider IdeState | ||
symbolsProvider ls ide params = do | ||
ds <- moduleOutline ls ide params | ||
case ds of | ||
Right (DSDocumentSymbols (List ls)) -> return $ Right ls | ||
Right (DSSymbolInformation (List _si)) -> | ||
return $ Left $ responseError "GhcIde.symbolsProvider: DSSymbolInformation deprecated" | ||
Left err -> return $ Left err | ||
|
||
-- --------------------------------------------------------------------- |
Oops, something went wrong.
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.
Why do these end up in Ghcide? I guess they leave in a future diff?
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.
Formatter
contains machinery needed to convert an HLSFormattingProvider
into aPartialHandler
for ghcide