@@ -5,7 +5,7 @@ module Curry.LanguageServer.Handlers.TextDocument.Completion (completionHandler)
5
5
import qualified Curry.Syntax as CS
6
6
import qualified Base.Types as CT
7
7
8
- import Control.Lens ((^.) )
8
+ import Control.Lens ((^.) , (.~) )
9
9
import Control.Monad (join , guard )
10
10
import Control.Monad.IO.Class (MonadIO )
11
11
import Control.Monad.Trans (lift )
@@ -72,17 +72,23 @@ fetchCompletions opts entry store query
72
72
73
73
pragmaCompletions :: MonadIO m => CompletionOptions -> VFS. PosPrefixInfo -> m [J. CompletionItem ]
74
74
pragmaCompletions opts query
75
- | isLanguagePragma = return $ toMatchingCompletions opts query $ Keyword <$> knownExtensions
75
+ | isLanguagePragma = return $ toMatchingCompletions opts query knownExtensions
76
76
| 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 ])
86
92
87
93
importCompletions :: (MonadIO m , MonadLsp c m ) => CompletionOptions -> I. IndexStore -> VFS. PosPrefixInfo -> m [J. CompletionItem ]
88
94
importCompletions opts store query = do
@@ -115,6 +121,8 @@ newtype Keyword = Keyword T.Text
115
121
116
122
data Local = Local T. Text (Maybe CT. PredType )
117
123
124
+ data Tagged a = Tagged [J. CompletionItemTag ] a
125
+
118
126
data CompletionSymbol = CompletionSymbol
119
127
{ -- The index symbol
120
128
cmsSymbol :: I. Symbol
@@ -199,6 +207,9 @@ instance CompletionQueryFilter Keyword where
199
207
instance CompletionQueryFilter Local where
200
208
matchesCompletionQuery query (Local i _) = VFS. prefixText query `T.isPrefixOf` i
201
209
210
+ instance CompletionQueryFilter a => CompletionQueryFilter (Tagged a ) where
211
+ matchesCompletionQuery query (Tagged _ x) = matchesCompletionQuery query x
212
+
202
213
instance CompletionQueryFilter CompletionSymbol where
203
214
matchesCompletionQuery query cms = fullPrefix query `T.isPrefixOf` fullName cms
204
215
@@ -269,6 +280,9 @@ instance ToCompletionItems T.Text where
269
280
insertTextFormat = Just J. PlainText
270
281
edits = Nothing
271
282
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
+
272
286
-- | Creates a snippet with VSCode-style syntax.
273
287
makeSnippet :: T. Text -> [T. Text ] -> T. Text
274
288
makeSnippet name ts = T. intercalate " " $ name : ((\ (i, t) -> " ${" <> T. pack (show (i :: Int )) <> " :" <> t <> " }" ) <$> zip [1 .. ] ts)
0 commit comments