@@ -150,6 +150,9 @@ allPragmas =
150
150
151
151
-- ---------------------------------------------------------------------
152
152
153
+ flags :: [T. Text ]
154
+ flags = map (T. pack . stripLeading ' -' ) $ flagsForCompletion False
155
+
153
156
completion :: PluginMethodHandler IdeState 'J.TextDocumentCompletion
154
157
completion _ide _ complParams = do
155
158
let (J. TextDocumentIdentifier uri) = complParams ^. J. textDocument
@@ -163,9 +166,19 @@ completion _ide _ complParams = do
163
166
| " {-# LANGUAGE" `T.isPrefixOf` VFS. fullLine pfix
164
167
= J. List $ map buildCompletion
165
168
(Fuzzy. simpleFilter (VFS. prefixText pfix) allPragmas)
169
+ | " {-# options_ghc" `T.isPrefixOf` T. toLower (VFS. fullLine pfix)
170
+ = J. List $ map mkExtCompl
171
+ (Fuzzy. simpleFilter (VFS. prefixText pfix) flags)
172
+ -- if there already is a closing bracket - complete without one
173
+ | isPragmaPrefix (VFS. fullLine pfix) && " }" `T.isSuffixOf` VFS. fullLine pfix
174
+ = J. List $ map (\ (a, b, c) -> mkPragmaCompl a b c) (validPragmas Nothing )
175
+ -- if there is no closing bracket - complete with one
176
+ | isPragmaPrefix (VFS. fullLine pfix)
177
+ = J. List $ map (\ (a, b, c) -> mkPragmaCompl a b c) (validPragmas (Just " }" ))
166
178
| otherwise
167
179
= J. List []
168
180
result Nothing = J. List []
181
+ isPragmaPrefix line = " {-#" `T.isPrefixOf` line
169
182
buildCompletion p =
170
183
J. CompletionItem
171
184
{ _label = p,
@@ -187,8 +200,31 @@ completion _ide _ complParams = do
187
200
_xdata = Nothing
188
201
}
189
202
_ -> return $ J. List []
190
-
191
203
-----------------------------------------------------------------------
204
+ validPragmas :: Maybe T. Text -> [(T. Text , T. Text , T. Text )]
205
+ validPragmas mSuffix =
206
+ [ (" LANGUAGE ${1:extension} #-" <> suffix , " LANGUAGE" , " {-# LANGUAGE #-}" )
207
+ , (" OPTIONS_GHC -${1:option} #-" <> suffix , " OPTIONS_GHC" , " {-# OPTIONS_GHC #-}" )
208
+ , (" INLINE ${1:function} #-" <> suffix , " INLINE" , " {-# INLINE #-}" )
209
+ , (" NOINLINE ${1:function} #-" <> suffix , " NOINLINE" , " {-# NOINLINE #-}" )
210
+ , (" INLINABLE ${1:function} #-" <> suffix , " INLINABLE" , " {-# INLINABLE #-}" )
211
+ , (" WARNING ${1:message} #-" <> suffix , " WARNING" , " {-# WARNING #-}" )
212
+ , (" DEPRECATED ${1:message} #-" <> suffix , " DEPRECATED" , " {-# DEPRECATED #-}" )
213
+ , (" ANN ${1:annotation} #-" <> suffix , " ANN" , " {-# ANN #-}" )
214
+ , (" RULES #-" <> suffix , " RULES" , " {-# RULES #-}" )
215
+ , (" SPECIALIZE ${1:function} #-" <> suffix , " SPECIALIZE" , " {-# SPECIALIZE #-}" )
216
+ , (" SPECIALIZE INLINE ${1:function} #-" <> suffix , " SPECIALIZE INLINE" , " {-# SPECIALIZE INLINE #-}" )
217
+ ]
218
+ where suffix = case mSuffix of
219
+ (Just s) -> s
220
+ Nothing -> " "
221
+
222
+
223
+ mkPragmaCompl :: T. Text -> T. Text -> T. Text -> J. CompletionItem
224
+ mkPragmaCompl insertText label detail =
225
+ J. CompletionItem label (Just J. CiKeyword ) Nothing (Just detail)
226
+ Nothing Nothing Nothing Nothing Nothing (Just insertText) (Just J. Snippet )
227
+ Nothing Nothing Nothing Nothing Nothing Nothing
192
228
193
229
-- | Find first line after the last file header pragma
194
230
-- Defaults to line 0 if the file contains no shebang(s), OPTIONS_GHC pragma(s), or LANGUAGE pragma(s)
@@ -218,3 +254,17 @@ checkPragma name = check
218
254
check l = isPragma l && getName l == name
219
255
getName l = T. take (T. length name) $ T. dropWhile isSpace $ T. drop 3 l
220
256
isPragma = T. isPrefixOf " {-#"
257
+
258
+
259
+ stripLeading :: Char -> String -> String
260
+ stripLeading _ [] = []
261
+ stripLeading c (s: ss)
262
+ | s == c = ss
263
+ | otherwise = s: ss
264
+
265
+
266
+ mkExtCompl :: T. Text -> J. CompletionItem
267
+ mkExtCompl label =
268
+ J. CompletionItem label (Just J. CiKeyword ) Nothing Nothing
269
+ Nothing Nothing Nothing Nothing Nothing Nothing Nothing
270
+ Nothing Nothing Nothing Nothing Nothing Nothing
0 commit comments