@@ -5,7 +5,7 @@ module Curry.LanguageServer.Handlers.TextDocument.Completion (completionHandler)
55import qualified Curry.Syntax as CS
66import qualified Base.Types as CT
77
8- import Control.Lens ((^.) )
8+ import Control.Lens ((^.) , (.~) )
99import Control.Monad (join , guard )
1010import Control.Monad.IO.Class (MonadIO )
1111import Control.Monad.Trans (lift )
@@ -72,17 +72,23 @@ fetchCompletions opts entry store query
7272
7373pragmaCompletions :: MonadIO m => CompletionOptions -> VFS. PosPrefixInfo -> m [J. CompletionItem ]
7474pragmaCompletions opts query
75- | isLanguagePragma = return $ toMatchingCompletions opts query $ Keyword <$> knownExtensions
75+ | isLanguagePragma = return $ toMatchingCompletions opts query knownExtensions
7676 | isOptionPragma = return []
77- | otherwise = return $ toMatchingCompletions opts query $ Keyword <$> pragmaKinds
78- where line = VFS. fullLine query
79- languagePragma = " LANGUAGE"
80- knownTools = T. pack . show <$> ([minBound .. maxBound ] :: [CS. KnownTool ])
81- optionPragmas = (" OPTIONS_" <> ) <$> knownTools
82- isLanguagePragma = languagePragma `T.isInfixOf` line
83- isOptionPragma = any (`T.isInfixOf` line) optionPragmas
84- pragmaKinds = languagePragma : optionPragmas
85- knownExtensions = T. pack . show <$> ([minBound .. maxBound ] :: [CS. KnownExtension ])
77+ | otherwise = return $ toMatchingCompletions opts query pragmaKeywords
78+ where line = VFS. fullLine query
79+ languagePragmaName = " LANGUAGE"
80+ optionPragmaPrefix = " OPTIONS_"
81+ languagePragma = Tagged [] $ Keyword languagePragmaName
82+ knownTools = [minBound .. maxBound ] :: [CS. KnownTool ]
83+ optionPragmas = makeToolOptionKeyword <$> knownTools
84+ makeToolOptionKeyword tool = Tagged tags $ Keyword $ optionPragmaPrefix <> T. pack (show tool)
85+ where tags = case tool of
86+ CS. CYMAKE -> [J. CitDeprecated ]
87+ _ -> []
88+ isLanguagePragma = languagePragmaName `T.isInfixOf` line
89+ isOptionPragma = optionPragmaPrefix `T.isInfixOf` line
90+ pragmaKeywords = languagePragma : optionPragmas
91+ knownExtensions = Keyword . T. pack . show <$> ([minBound .. maxBound ] :: [CS. KnownExtension ])
8692
8793importCompletions :: (MonadIO m , MonadLsp c m ) => CompletionOptions -> I. IndexStore -> VFS. PosPrefixInfo -> m [J. CompletionItem ]
8894importCompletions opts store query = do
@@ -115,6 +121,8 @@ newtype Keyword = Keyword T.Text
115121
116122data Local = Local T. Text (Maybe CT. PredType )
117123
124+ data Tagged a = Tagged [J. CompletionItemTag ] a
125+
118126data CompletionSymbol = CompletionSymbol
119127 { -- The index symbol
120128 cmsSymbol :: I. Symbol
@@ -199,6 +207,9 @@ instance CompletionQueryFilter Keyword where
199207instance CompletionQueryFilter Local where
200208 matchesCompletionQuery query (Local i _) = VFS. prefixText query `T.isPrefixOf` i
201209
210+ instance CompletionQueryFilter a => CompletionQueryFilter (Tagged a ) where
211+ matchesCompletionQuery query (Tagged _ x) = matchesCompletionQuery query x
212+
202213instance CompletionQueryFilter CompletionSymbol where
203214 matchesCompletionQuery query cms = fullPrefix query `T.isPrefixOf` fullName cms
204215
@@ -269,6 +280,9 @@ instance ToCompletionItems T.Text where
269280 insertTextFormat = Just J. PlainText
270281 edits = Nothing
271282
283+ instance ToCompletionItems a => ToCompletionItems (Tagged a ) where
284+ toCompletionItems opts query (Tagged tags x) = (J. tags .~ Just (J. List tags)) <$> toCompletionItems opts query x
285+
272286-- | Creates a snippet with VSCode-style syntax.
273287makeSnippet :: T. Text -> [T. Text ] -> T. Text
274288makeSnippet name ts = T. intercalate " " $ name : ((\ (i, t) -> " ${" <> T. pack (show (i :: Int )) <> " :" <> t <> " }" ) <$> zip [1 .. ] ts)
0 commit comments