-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from fwcd/extensions
Add support for hover extensions
- Loading branch information
Showing
5 changed files
with
198 additions
and
14 deletions.
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,83 @@ | ||
{-# LANGUAGE OverloadedRecordDot, OverloadedStrings, RecordWildCards, TypeApplications #-} | ||
module Curry.LanguageServer.Extension | ||
( ExtensionPoint (..), ExtensionOutputFormat (..), Extension (..) | ||
) where | ||
|
||
import Data.Aeson (FromJSON (..), ToJSON (..), (.:?), (.!=), (.=), object, withObject) | ||
import Data.Default (Default (..)) | ||
import qualified Data.Text as T | ||
|
||
data ExtensionPoint = ExtensionPointHover | ||
| ExtensionPointUnknown T.Text | ||
deriving (Show, Eq) | ||
|
||
data ExtensionOutputFormat = ExtensionOutputFormatPlaintext | ||
| ExtensionOutputFormatMarkdown | ||
| ExtensionOutputFormatUnknown T.Text | ||
deriving (Show, Eq) | ||
|
||
data Extension = Extension | ||
{ name :: T.Text | ||
, extensionPoint :: ExtensionPoint | ||
, outputFormat :: ExtensionOutputFormat | ||
, showOutputOnError :: Bool | ||
, executable :: T.Text | ||
, args :: [T.Text] | ||
} | ||
deriving (Show, Eq) | ||
|
||
instance Default Extension where | ||
def = Extension | ||
{ name = "Anonymous Extension" | ||
, extensionPoint = ExtensionPointHover | ||
, outputFormat = ExtensionOutputFormatPlaintext | ||
, showOutputOnError = False | ||
, executable = "echo" | ||
, args = [] | ||
} | ||
|
||
instance FromJSON Extension where | ||
parseJSON = withObject "Extension" $ \e -> do | ||
name <- e .:? "name" .!= (def @Extension).name | ||
extensionPoint <- e .:? "extensionPoint" .!= (def @Extension).extensionPoint | ||
outputFormat <- e .:? "outputFormat" .!= (def @Extension).outputFormat | ||
showOutputOnError <- e .:? "showOutputOnError" .!= (def @Extension).showOutputOnError | ||
executable <- e .:? "executable" .!= (def @Extension).executable | ||
args <- e .:? "args" .!= (def @Extension).args | ||
return Extension {..} | ||
|
||
instance ToJSON Extension where | ||
toJSON Extension {..} = object | ||
[ "name" .= name | ||
, "extensionPoint" .= extensionPoint | ||
, "outputFormat" .= outputFormat | ||
, "showOutputOnError" .= showOutputOnError | ||
, "executable" .= executable | ||
, "args" .= args | ||
] | ||
|
||
instance FromJSON ExtensionPoint where | ||
parseJSON v = do | ||
s <- parseJSON v | ||
return $ case s :: T.Text of | ||
"hover" -> ExtensionPointHover | ||
_ -> ExtensionPointUnknown s | ||
|
||
instance ToJSON ExtensionPoint where | ||
toJSON p = toJSON @T.Text $ case p of | ||
ExtensionPointHover -> "hover" | ||
ExtensionPointUnknown s -> s | ||
|
||
instance FromJSON ExtensionOutputFormat where | ||
parseJSON v = do | ||
s <- parseJSON v | ||
return $ case s :: T.Text of | ||
"plaintext" -> ExtensionOutputFormatPlaintext | ||
"markdown" -> ExtensionOutputFormatMarkdown | ||
_ -> ExtensionOutputFormatUnknown s | ||
|
||
instance ToJSON ExtensionOutputFormat where | ||
toJSON p = toJSON @T.Text $ case p of | ||
ExtensionOutputFormatPlaintext -> "plaintext" | ||
ExtensionOutputFormatMarkdown -> "markdown" | ||
ExtensionOutputFormatUnknown s -> s |
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