@@ -21,12 +21,16 @@ import qualified Language.Haskell.LSP.Types.Lens as J
2121import Development.IDE as D
2222import Language.Haskell.LSP.Types
2323
24+ import qualified Language.Haskell.LSP.Core as LSP
25+ import qualified Language.Haskell.LSP.VFS as VFS
26+
2427-- ---------------------------------------------------------------------
2528
2629descriptor :: PluginId -> PluginDescriptor
2730descriptor plId = (defaultPluginDescriptor plId)
2831 { pluginCommands = commands
2932 , pluginCodeActionProvider = Just codeActionProvider
33+ , pluginCompletionProvider = Just completion
3034 }
3135
3236-- ---------------------------------------------------------------------
@@ -160,3 +164,54 @@ possiblePragmas =
160164 ]
161165
162166-- ---------------------------------------------------------------------
167+
168+ completion :: CompletionProvider
169+ completion lspFuncs _ide complParams = do
170+ let (TextDocumentIdentifier uri) = complParams ^. J. textDocument
171+ position = complParams ^. J. position
172+ putStrLn $ " Uri" ++ show uri
173+ putStrLn $ " nor uri" ++ show (toNormalizedUri uri)
174+ contents <- LSP. getVirtualFileFunc lspFuncs $ toNormalizedUri uri
175+ fmap Right $ case (contents, uriToFilePath' uri) of
176+ (Just cnts, Just _path) -> do
177+ pfix <- VFS. getCompletionPrefix position cnts
178+ putStrLn $ " pfix" ++ show pfix
179+ return $ Completions $ List [r]
180+ where
181+ r =
182+ CompletionItem
183+ label
184+ kind
185+ tags
186+ detail
187+ documentation
188+ deprecated
189+ preselect
190+ sortText
191+ filterText
192+ insertText
193+ insertTextFormat
194+ textEdit
195+ additionalTextEdits
196+ commitCharacters
197+ command
198+ 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 []
0 commit comments