@@ -21,6 +21,7 @@ import Data.Hashable
2121import Data.HashMap.Strict (HashMap )
2222import qualified Data.HashMap.Strict as HashMap
2323import qualified Data.List.NonEmpty as NE
24+ import qualified Data.Text as T
2425import qualified Data.Text.Encoding as Encoding
2526import qualified Data.Text.Utf16.Rope as Rope
2627import Data.Typeable
@@ -44,9 +45,6 @@ import qualified Language.LSP.Types as LSP
4445import qualified Language.LSP.Types.Lens as JL
4546import Language.LSP.VFS (VirtualFile )
4647import qualified Language.LSP.VFS as VFS
47- import Debug.Trace (traceShowId )
48-
49-
5048data Log
5149 = LogModificationTime NormalizedFilePath FileVersion
5250 | LogShake Shake. Log
@@ -150,7 +148,8 @@ cabalRules recorder = do
150148 (t, mCabalSource) <- use_ GetFileContents file
151149 log' Debug $ LogModificationTime file t
152150 contents <- case mCabalSource of
153- Just sources -> pure $ Encoding. encodeUtf8 sources
151+ Just sources ->
152+ pure $ Encoding. encodeUtf8 sources
154153 Nothing -> do
155154 liftIO $ BS. readFile $ fromNormalizedFilePath file
156155
@@ -286,11 +285,16 @@ completion _ide _ complParams = do
286285 result (Just pfix) fp cnts
287286 | Just ctx <- context = do
288287 let completer = contextToCompleter " " ctx
289- completions <- completer $ VFS. prefixText $ (traceShowId pfix)
290- genPkgDesc <- readGenericPackageDescription silent fp
291- pure $ J. List $ makeCompletionItems pfix genPkgDesc completions
288+ completions <- completer filePathPfix
289+ -- genPkgDesc <- readGenericPackageDescription silent fp
290+ pure $ J. List $ makeCompletionItems editRange completions
292291 | otherwise = pure $ J. List []
293292 where
294- pos = VFS. cursorPos pfix
295- context = getContext pos (Rope. lines $ cnts ^. VFS. file_text)
293+ (Position linePos charPos) = VFS. cursorPos pfix
294+ context = getContext (Position linePos charPos) (Rope. lines $ cnts ^. VFS. file_text)
295+ filePathPfix = getFilePathCursorPrefix pfix
296+ editRange =
297+ Range
298+ (Position linePos (fromIntegral charPos - fromIntegral (T. length filePathPfix)))
299+ (Position linePos charPos)
296300
0 commit comments