Skip to content

Commit 668edfc

Browse files
authored
Merge pull request #54 from fwcd/completion-item-tags
Use completion item tags
2 parents 67bc508 + 8f5840f commit 668edfc

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/Curry/LanguageServer/Handlers/TextDocument/Completion.hs

+25-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Curry.LanguageServer.Handlers.TextDocument.Completion (completionHandler)
55
import qualified Curry.Syntax as CS
66
import qualified Base.Types as CT
77

8-
import Control.Lens ((^.))
8+
import Control.Lens ((^.), (.~))
99
import Control.Monad (join, guard)
1010
import Control.Monad.IO.Class (MonadIO)
1111
import Control.Monad.Trans (lift)
@@ -72,17 +72,23 @@ fetchCompletions opts entry store query
7272

7373
pragmaCompletions :: MonadIO m => CompletionOptions -> VFS.PosPrefixInfo -> m [J.CompletionItem]
7474
pragmaCompletions 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

8793
importCompletions :: (MonadIO m, MonadLsp c m) => CompletionOptions -> I.IndexStore -> VFS.PosPrefixInfo -> m [J.CompletionItem]
8894
importCompletions opts store query = do
@@ -115,6 +121,8 @@ newtype Keyword = Keyword T.Text
115121

116122
data Local = Local T.Text (Maybe CT.PredType)
117123

124+
data Tagged a = Tagged [J.CompletionItemTag] a
125+
118126
data CompletionSymbol = CompletionSymbol
119127
{ -- The index symbol
120128
cmsSymbol :: I.Symbol
@@ -199,6 +207,9 @@ instance CompletionQueryFilter Keyword where
199207
instance 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+
202213
instance 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.
273287
makeSnippet :: T.Text -> [T.Text] -> T.Text
274288
makeSnippet name ts = T.intercalate " " $ name : ((\(i, t) -> "${" <> T.pack (show (i :: Int)) <> ":" <> t <> "}") <$> zip [1..] ts)

0 commit comments

Comments
 (0)