From 7c43cd957415344bdcfca2bd383755a4d935c5d2 Mon Sep 17 00:00:00 2001 From: Anton Myasnikov Date: Tue, 25 Aug 2020 19:15:02 +0300 Subject: [PATCH] [LIGO-40] Move LSP request handlers to Capabilities directory --- tools/lsp/squirrel/src/AST.hs | 4 +--- tools/lsp/squirrel/src/AST/Capabilities.hs | 7 +++++++ .../src/AST/{ => Capabilities}/Completion.hs | 16 +++++++++++----- .../squirrel/src/AST/{ => Capabilities}/Find.hs | 2 +- .../src/AST/{ => Capabilities}/Folding.hs | 2 +- tools/lsp/squirrel/src/AST/Capabilities/Hover.hs | 4 ++-- 6 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 tools/lsp/squirrel/src/AST/Capabilities.hs rename tools/lsp/squirrel/src/AST/{ => Capabilities}/Completion.hs (90%) rename tools/lsp/squirrel/src/AST/{ => Capabilities}/Find.hs (97%) rename tools/lsp/squirrel/src/AST/{ => Capabilities}/Folding.hs (96%) diff --git a/tools/lsp/squirrel/src/AST.hs b/tools/lsp/squirrel/src/AST.hs index 566315291..258764066 100644 --- a/tools/lsp/squirrel/src/AST.hs +++ b/tools/lsp/squirrel/src/AST.hs @@ -1,9 +1,7 @@ -- | The "all things AST"-module. module AST (module M) where -import AST.Completion as M -import AST.Find as M -import AST.Folding as M +import AST.Capabilities as M import AST.Parser as M import AST.Scope as M import AST.Skeleton as M diff --git a/tools/lsp/squirrel/src/AST/Capabilities.hs b/tools/lsp/squirrel/src/AST/Capabilities.hs new file mode 100644 index 000000000..137014aae --- /dev/null +++ b/tools/lsp/squirrel/src/AST/Capabilities.hs @@ -0,0 +1,7 @@ +-- | Module that exports all capabilities. +module AST.Capabilities (module Exports) where + +import AST.Capabilities.Completion as Exports +import AST.Capabilities.Find as Exports +import AST.Capabilities.Folding as Exports +import AST.Capabilities.Hover as Exports diff --git a/tools/lsp/squirrel/src/AST/Completion.hs b/tools/lsp/squirrel/src/AST/Capabilities/Completion.hs similarity index 90% rename from tools/lsp/squirrel/src/AST/Completion.hs rename to tools/lsp/squirrel/src/AST/Capabilities/Completion.hs index 1a64915f9..2ed29ca74 100644 --- a/tools/lsp/squirrel/src/AST/Completion.hs +++ b/tools/lsp/squirrel/src/AST/Capabilities/Completion.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE RecordWildCards #-} - -module AST.Completion where +module AST.Capabilities.Completion where import Language.Haskell.LSP.Types (CompletionDoc (..), CompletionItem (..), CompletionItemKind (..)) @@ -49,7 +47,11 @@ complete r tree = do $ scope toCompletionItem :: Completion -> CompletionItem -toCompletionItem c@Completion{..} = CompletionItem +toCompletionItem c@Completion + { cName = cName + , cType = cType + , cDoc = _cDoc + } = CompletionItem { _label = cName , _kind = Just $ CiFunction -- TODO , _detail = Just $ ":: " <> cType -- TODO: more elaborate info @@ -68,7 +70,11 @@ toCompletionItem c@Completion{..} = CompletionItem } mkDoc :: Completion -> CompletionDoc -mkDoc Completion {..} = CompletionDocString $ +mkDoc Completion + { cName = cName + , cType = cType + , cDoc = cDoc + } = CompletionDocString $ cName <> " is of type " <> cType <> ". " <> cDoc asCompletion :: ScopedDecl -> Completion diff --git a/tools/lsp/squirrel/src/AST/Find.hs b/tools/lsp/squirrel/src/AST/Capabilities/Find.hs similarity index 97% rename from tools/lsp/squirrel/src/AST/Find.hs rename to tools/lsp/squirrel/src/AST/Capabilities/Find.hs index 2024f3ce3..0c5c1180c 100644 --- a/tools/lsp/squirrel/src/AST/Find.hs +++ b/tools/lsp/squirrel/src/AST/Capabilities/Find.hs @@ -1,5 +1,5 @@ -module AST.Find where +module AST.Capabilities.Find where import Control.Monad diff --git a/tools/lsp/squirrel/src/AST/Folding.hs b/tools/lsp/squirrel/src/AST/Capabilities/Folding.hs similarity index 96% rename from tools/lsp/squirrel/src/AST/Folding.hs rename to tools/lsp/squirrel/src/AST/Capabilities/Folding.hs index c7d52fb6b..b647463e0 100644 --- a/tools/lsp/squirrel/src/AST/Folding.hs +++ b/tools/lsp/squirrel/src/AST/Capabilities/Folding.hs @@ -2,7 +2,7 @@ -- | Code folding utilities -module AST.Folding where +module AST.Capabilities.Folding where import qualified Language.Haskell.LSP.Types as J diff --git a/tools/lsp/squirrel/src/AST/Capabilities/Hover.hs b/tools/lsp/squirrel/src/AST/Capabilities/Hover.hs index c5560d3f3..86fa7588b 100644 --- a/tools/lsp/squirrel/src/AST/Capabilities/Hover.hs +++ b/tools/lsp/squirrel/src/AST/Capabilities/Hover.hs @@ -13,7 +13,7 @@ import AST.Skeleton import Duplo.Pretty import Product import Range -import Data.Text (intercalate) +import Data.Text (pack, intercalate) hoverDecl :: CanSearch xs @@ -32,7 +32,7 @@ mkContents ScopedDecl { _sdType = ppToText -> _sdType , _sdName = ppToText -> _sdName , _sdDoc = ppToText -> _sdDoc - , _sdOrigin = ppToText -> _sdOrigin + , _sdOrigin = pack . show -> _sdOrigin -- TODO: more documentation } = LSP.HoverContents $ LSP.MarkupContent { _kind = LSP.MkMarkdown