Skip to content

Commit 2bba471

Browse files
authored
Remove getCompletionPrefix (#552)
* Remove getCompletionPrefix * Format
1 parent 99002c0 commit 2bba471

File tree

3 files changed

+3
-84
lines changed

3 files changed

+3
-84
lines changed

lsp/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
support for client-initiated progress or not.
1111
- The server now dynamically registers for `workspace/didChangeConfiguration`
1212
notifications, to ensure that newer clients continue to send them.
13+
- Removed `getCompletionPrefix` from the `VFS` module. This is specific to completing
14+
Haskell identifiers and doesn't belong here. It has already been moved to `ghcide`
15+
some time ago.
1316

1417
## 2.3.0.0
1518

lsp/src/Language/LSP/VFS.hs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ module Language.LSP.VFS (
5050

5151
-- * manipulating the file contents
5252
rangeLinesFromVfs,
53-
PosPrefixInfo (..),
54-
getCompletionPrefix,
5553

5654
-- * for tests
5755
applyChanges,
@@ -63,19 +61,16 @@ import Colog.Core (LogAction (..), Severity (..), WithSeverity (..), (<&))
6361
import Control.Lens hiding (parts, (<.>))
6462
import Control.Monad
6563
import Control.Monad.State
66-
import Data.Char (isAlphaNum, isUpper)
6764
import Data.Foldable (traverse_)
6865
import Data.Hashable
6966
import Data.Int (Int32)
7067
import Data.List
7168
import Data.Map.Strict qualified as Map
72-
import Data.Maybe
7369
import Data.Ord
7470
import Data.Row
7571
import Data.Text (Text)
7672
import Data.Text qualified as T
7773
import Data.Text.IO qualified as T
78-
import Data.Text.Lines as Char (Position (..))
7974
import Data.Text.Prettyprint.Doc hiding (line)
8075
import Data.Text.Utf16.Lines as Utf16 (Position (..))
8176
import Data.Text.Utf16.Rope.Mixed (Rope)
@@ -471,64 +466,9 @@ rangeToCodePointRange :: VirtualFile -> J.Range -> Maybe CodePointRange
471466
rangeToCodePointRange vFile (J.Range b e) =
472467
CodePointRange <$> positionToCodePointPosition vFile b <*> positionToCodePointPosition vFile e
473468

474-
-- ---------------------------------------------------------------------
475-
476-
-- TODO:AZ:move this to somewhere sane
477-
478-
-- | Describes the line at the current cursor position
479-
data PosPrefixInfo = PosPrefixInfo
480-
{ fullLine :: !T.Text
481-
-- ^ The full contents of the line the cursor is at
482-
, prefixModule :: !T.Text
483-
-- ^ If any, the module name that was typed right before the cursor position.
484-
-- For example, if the user has typed "Data.Maybe.from", then this property
485-
-- will be "Data.Maybe"
486-
, prefixText :: !T.Text
487-
-- ^ The word right before the cursor position, after removing the module part.
488-
-- For example if the user has typed "Data.Maybe.from",
489-
-- then this property will be "from"
490-
, cursorPos :: !J.Position
491-
-- ^ The cursor position
492-
}
493-
deriving (Show, Eq)
494-
495-
getCompletionPrefix :: (Monad m) => J.Position -> VirtualFile -> m (Maybe PosPrefixInfo)
496-
getCompletionPrefix pos@(J.Position l c) (VirtualFile _ _ ropetext) =
497-
return $ Just $ fromMaybe (PosPrefixInfo "" "" "" pos) $ do
498-
-- Maybe monad
499-
let lastMaybe [] = Nothing
500-
lastMaybe xs = Just $ last xs
501-
502-
let curRope = fst $ Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (fromIntegral l) ropetext
503-
beforePos <- Rope.toText . fst <$> Rope.utf16SplitAt (fromIntegral c) curRope
504-
curWord <-
505-
if
506-
| T.null beforePos -> Just ""
507-
| T.last beforePos == ' ' -> Just "" -- don't count abc as the curword in 'abc '
508-
| otherwise -> lastMaybe (T.words beforePos)
509-
510-
let parts =
511-
T.split (== '.') $
512-
T.takeWhileEnd (\x -> isAlphaNum x || x `elem` ("._'" :: String)) curWord
513-
case reverse parts of
514-
[] -> Nothing
515-
(x : xs) -> do
516-
let modParts =
517-
dropWhile (not . isUpper . T.head) $
518-
reverse $
519-
filter (not . T.null) xs
520-
modName = T.intercalate "." modParts
521-
-- curRope is already a single line, but it may include an enclosing '\n'
522-
let curLine = T.dropWhileEnd (== '\n') $ Rope.toText curRope
523-
return $ PosPrefixInfo curLine modName x pos
524-
525-
-- ---------------------------------------------------------------------
526-
527469
rangeLinesFromVfs :: VirtualFile -> J.Range -> T.Text
528470
rangeLinesFromVfs (VirtualFile _ _ ropetext) (J.Range (J.Position lf _cf) (J.Position lt _ct)) = r
529471
where
530472
(_, s1) = Rope.splitAtLine (fromIntegral lf) ropetext
531473
(s2, _) = Rope.splitAtLine (fromIntegral (lt - lf)) s1
532474
r = Rope.toText s2
533-
534-
-- ---------------------------------------------------------------------

lsp/test/VspSpec.hs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,3 @@ vspSpec = do
278278
codePointPositionToPosition vfile (CodePointPosition 2 1) `shouldBe` Nothing
279279
-- Greater line than max line
280280
codePointPositionToPosition vfile (CodePointPosition 3 0) `shouldBe` Nothing
281-
282-
-- ---------------------------------
283-
284-
it "getCompletionPrefix" $ do
285-
let
286-
orig =
287-
T.unlines
288-
[ "{-# ings #-}"
289-
, "import Data.List"
290-
]
291-
pp4 <- getCompletionPrefix (J.Position 0 4) (vfsFromText orig)
292-
pp4 `shouldBe` Just (PosPrefixInfo "{-# ings #-}" "" "" (J.Position 0 4))
293-
294-
pp5 <- getCompletionPrefix (J.Position 0 5) (vfsFromText orig)
295-
pp5 `shouldBe` Just (PosPrefixInfo "{-# ings #-}" "" "i" (J.Position 0 5))
296-
297-
pp6 <- getCompletionPrefix (J.Position 0 6) (vfsFromText orig)
298-
pp6 `shouldBe` Just (PosPrefixInfo "{-# ings #-}" "" "in" (J.Position 0 6))
299-
300-
pp14 <- getCompletionPrefix (J.Position 1 14) (vfsFromText orig)
301-
pp14 `shouldBe` Just (PosPrefixInfo "import Data.List" "Data" "Li" (J.Position 1 14))
302-
303-
pp00 <- getCompletionPrefix (J.Position 0 0) (vfsFromText orig)
304-
pp00 `shouldBe` Just (PosPrefixInfo "{-# ings #-}" "" "" (J.Position 0 0))

0 commit comments

Comments
 (0)