Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Rope.getLine #4303

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ test-options: -j1
package *
ghc-options: -haddock

source-repository-package
type:git
location: https://github.com/jhrcek/text-rope.git
tag: 37e808b26c8e8c862a04c985663fefd7c64335e2

constraints:
-- C++ is hard to distribute, especially on older GHCs
-- See https://github.com/haskell/haskell-language-server/issues/3822
Expand All @@ -41,3 +46,4 @@ constraints:
-- We want to be able to benefit from the performance optimisations
-- in the future, thus: TODO: remove this flag.
bitvec -simd

7 changes: 3 additions & 4 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import qualified Language.LSP.VFS as VFS
import Text.Fuzzy.Parallel (Scored (score),
original)

import qualified Data.Text.Utf16.Rope.Mixed as Rope
import qualified Data.Text.Mixed.Rope as Rope
import Development.IDE hiding (line)

import Development.IDE.Spans.AtPoint (pointCommand)
Expand Down Expand Up @@ -907,9 +907,8 @@ getCompletionPrefixFromRope pos@(Position l c) ropetext =
lastMaybe = headMaybe . reverse

-- grab the entire line the cursor is at
curLine <- headMaybe $ Rope.lines
$ fst $ Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (fromIntegral l) ropetext
let beforePos = T.take (fromIntegral c) curLine
curLine = Rope.getLine (fromIntegral l) ropetext
beforePos = T.take (fromIntegral c) curLine
-- the word getting typed, after previous space and before cursor
curWord <-
if | T.null beforePos -> Just ""
Expand Down
1 change: 0 additions & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,6 @@ test-suite hls-notes-plugin-tests
main-is: NotesTest.hs
build-depends:
, base
, directory
, filepath
, haskell-language-server:hls-notes-plugin
, hls-test-utils == 2.8.0.0
Expand Down
5 changes: 2 additions & 3 deletions plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Maybe (catMaybes, listToMaybe,
mapMaybe)
import Data.Text (Text, intercalate)
import qualified Data.Text as T
import qualified Data.Text.Utf16.Rope.Mixed as Rope
import qualified Data.Text.Mixed.Rope as Rope
import Development.IDE hiding (line)
import Development.IDE.Core.PluginUtils (runActionE, useE)
import Development.IDE.Core.Shake (toKnownFiles)
Expand Down Expand Up @@ -82,8 +82,7 @@ jumpToNote state _ param
let Position l c = param ^. L.position
contents <- fmap _file_text . err "Error getting file contents"
=<< lift (LSP.getVirtualFile uriOrig)
line <- err "Line not found in file" (listToMaybe $ Rope.lines $ fst
(Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (fromIntegral l) contents))
let line = Rope.getLine (fromIntegral l) contents
let noteOpt = listToMaybe $ mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line
case noteOpt of
Nothing -> pure (InR (InR Null))
Expand Down
Loading