Skip to content

Commit f0b0499

Browse files
committed
Initial working version of Language Pragma completions.
1 parent 1b0f64f commit f0b0499

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

plugins/default/src/Ide/Plugin/Pragmas.hs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Language.Haskell.LSP.Types
2323

2424
import qualified Language.Haskell.LSP.Core as LSP
2525
import qualified Language.Haskell.LSP.VFS as VFS
26+
import Development.IDE.Core.Shake (ShakeExtras(logger))
2627

2728
-- ---------------------------------------------------------------------
2829

@@ -165,20 +166,33 @@ possiblePragmas =
165166

166167
-- ---------------------------------------------------------------------
167168

169+
logStuff :: IdeState -> T.Text -> IO ()
170+
logStuff ide = logInfo (logger (shakeExtras ide))
171+
168172
completion :: CompletionProvider
169173
completion lspFuncs _ide complParams = do
170174
let (TextDocumentIdentifier uri) = complParams ^. J.textDocument
171175
position = complParams ^. J.position
176+
logStuff _ide (T.pack "test ---------------------.......")
172177
putStrLn $ "Uri" ++ show uri
173178
putStrLn $ "nor uri" ++ show (toNormalizedUri uri)
179+
logStuff _ide (T.pack "--------------------------------.......")
174180
contents <- LSP.getVirtualFileFunc lspFuncs $ toNormalizedUri uri
175181
fmap Right $ case (contents, uriToFilePath' uri) of
176182
(Just cnts, Just _path) -> do
177183
pfix <- VFS.getCompletionPrefix position cnts
178-
putStrLn $ "pfix" ++ show pfix
179-
return $ Completions $ List [r]
184+
logStuff _ide (T.pack "test &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.......")
185+
logStuff _ide $ "pfix" <> (T.pack. show $ pfix)
186+
logStuff _ide (T.pack "test &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.......")
187+
return $ result pfix
180188
where
181-
r =
189+
result (Just pfix)
190+
| "{-# LANGUAGE" `T.isPrefixOf` VFS.fullLine pfix
191+
= Completions $ List $ map buildCompletion possiblePragmas
192+
| otherwise
193+
= Completions $ List []
194+
result Nothing = Completions $ List []
195+
buildCompletion p =
182196
CompletionItem
183197
label
184198
kind
@@ -196,22 +210,21 @@ completion lspFuncs _ide complParams = do
196210
commitCharacters
197211
command
198212
xd
199-
label = "Example Pragma completion"
200-
kind = Nothing
201-
tags = List []
202-
detail = Nothing
203-
documentation = Nothing
204-
deprecated = Nothing
205-
preselect = Nothing
206-
sortText = Nothing
207-
filterText = Nothing
208-
insertText = Nothing
209-
insertTextFormat = Nothing
210-
textEdit = Nothing
211-
additionalTextEdits = Nothing
212-
commitCharacters = Nothing
213-
command = Nothing
214-
xd = Nothing
215-
_ -> do
216-
putStrLn $ "Need to handle this path"'
217-
return $ Completions $ List []
213+
where
214+
label = p
215+
kind = Nothing
216+
tags = List []
217+
detail = Nothing
218+
documentation = Nothing
219+
deprecated = Nothing
220+
preselect = Nothing
221+
sortText = Nothing
222+
filterText = Nothing
223+
insertText = Nothing
224+
insertTextFormat = Nothing
225+
textEdit = Nothing
226+
additionalTextEdits = Nothing
227+
commitCharacters = Nothing
228+
command = Nothing
229+
xd = Nothing
230+
_ -> return $ Completions $ List []

0 commit comments

Comments
 (0)