Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
Merged
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 .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
# url = https://github.com/bubba/ghc-mod.git
url = https://github.com/alanz/ghc-mod.git

[submodule "submodules/haskell-lsp"]
path = submodules/haskell-lsp
url = https://github.com/alanz/haskell-lsp.git
[submodule "submodules/lsp-test"]
path = submodules/lsp-test
url = https://github.com/alanz/lsp-test.git
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ packages:
./submodules/ghc-mod/
./submodules/ghc-mod/core/
./submodules/ghc-mod/ghc-project-types
./submodules/haskell-lsp
./submodules/haskell-lsp/haskell-lsp-types
./submodules/lsp-test

tests: true
10 changes: 5 additions & 5 deletions haskell-ide-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ library
, gitrev >= 1.1
, haddock-api
, haddock-library
, haskell-lsp == 0.11.*
, haskell-lsp-types == 0.11.*
, haskell-lsp == 0.12.*
, haskell-lsp-types == 0.12.*
, haskell-src-exts
, hie-plugin-api
, hlint >= 2.0.11
Expand All @@ -86,6 +86,7 @@ library
, optparse-simple >= 0.0.3
, parsec
, process
, rope-utf16-splay >= 0.3.1.0
, safe
, sorted-list >= 0.2.1.0
, stm
Expand All @@ -95,7 +96,6 @@ library
, unordered-containers
, vector
, yaml >= 0.8.31
, yi-rope
ghc-options: -Wall -Wredundant-constraints
if flag(pedantic)
ghc-options: -Werror
Expand Down Expand Up @@ -278,8 +278,8 @@ test-suite func-test
, filepath
, lsp-test >= 0.5.2
, haskell-ide-engine
, haskell-lsp-types == 0.11.*
, haskell-lsp == 0.11.*
, haskell-lsp-types == 0.12.*
, haskell-lsp == 0.12.*
, hie-test-utils
, hie-plugin-api
, hspec
Expand Down
11 changes: 3 additions & 8 deletions hie-plugin-api/Haskell/Ide/Engine/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import Prelude hiding (log)
import SrcLoc
import System.Directory
import System.FilePath
import qualified Yi.Rope as Yi
import qualified Data.Rope.UTF16 as Rope

-- ---------------------------------------------------------------------

Expand Down Expand Up @@ -275,7 +275,7 @@ readVFS :: (MonadIde m, MonadIO m) => Uri -> m (Maybe T.Text)
readVFS uri = do
mvf <- getVirtualFile uri
case mvf of
Just (VirtualFile _ txt) -> return $ Just (Yi.toText txt)
Just (VirtualFile _ txt _) -> return $ Just (Rope.toText txt)
Nothing -> return Nothing

getRangeFromVFS :: (MonadIde m, MonadIO m) => Uri -> Range -> m (Maybe T.Text)
Expand All @@ -285,9 +285,4 @@ getRangeFromVFS uri rg = do
Just vfs -> return $ Just $ rangeLinesFromVfs vfs rg
Nothing -> return Nothing

rangeLinesFromVfs :: VirtualFile -> Range -> T.Text
rangeLinesFromVfs (VirtualFile _ yitext) (Range (Position lf _cf) (Position lt _ct)) = r
where
(_ ,s1) = Yi.splitAtLine lf yitext
(s2, _) = Yi.splitAtLine (lt - lf) s1
r = Yi.toText s2
-- ---------------------------------------------------------------------
4 changes: 2 additions & 2 deletions hie-plugin-api/hie-plugin-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ library
, ghc
, ghc-mod-core >= 5.9.0.0
, ghc-project-types >= 5.9.0.0
, haskell-lsp == 0.11.*
, haskell-lsp == 0.12.*
, hslogger
, monad-control
, mtl
, rope-utf16-splay >= 0.3.1.0
, stm
, syb
, text
, transformers
, unordered-containers
, yi-rope
if os(windows)
build-depends: Win32
else
Expand Down
27 changes: 5 additions & 22 deletions src/Haskell/Ide/Engine/Support/HieExtras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Haskell.Ide.Engine.Support.HieExtras
, findTypeDef
, showName
, safeTyThingId
, PosPrefixInfo(..)
, VFS.PosPrefixInfo(..)
, HarePoint(..)
, customOptions
, runGhcModCommand
Expand Down Expand Up @@ -65,6 +65,7 @@ import qualified Haskell.Ide.Engine.Support.Fuzzy as Fuzzy
import HscTypes
import qualified Language.Haskell.LSP.Types as J
import qualified Language.Haskell.LSP.Types.Lens as J
import qualified Language.Haskell.LSP.VFS as VFS
import Language.Haskell.Refact.API (showGhc)
import Language.Haskell.Refact.Utils.MonadFunctions
import Name
Expand Down Expand Up @@ -188,24 +189,6 @@ safeTyThingId _ = Nothing
-- Associates a module's qualifier with its members
type QualCompls = Map.Map T.Text [CompItem]

-- | Describes the line at the current cursor position
data PosPrefixInfo = PosPrefixInfo
{ fullLine :: T.Text
-- ^ The full contents of the line the cursor is at

, prefixModule :: T.Text
-- ^ If any, the module name that was typed right before the cursor position.
-- For example, if the user has typed "Data.Maybe.from", then this property
-- will be "Data.Maybe"

, prefixText :: T.Text
-- ^ The word right before the cursor position, after removing the module part.
-- For example if the user has typed "Data.Maybe.from",
-- then this property will be "from"
, cursorPos :: J.Position
-- ^ The cursor position
}

data CachedCompletions = CC
{ allModNamesAsNS :: [T.Text]
, unqualCompls :: [CompItem]
Expand Down Expand Up @@ -338,7 +321,7 @@ instance ModuleCache CachedCompletions where
newtype WithSnippets = WithSnippets Bool

-- | Returns the cached completions for the given module and position.
getCompletions :: Uri -> PosPrefixInfo -> WithSnippets -> IdeM (IdeResult [J.CompletionItem])
getCompletions :: Uri -> VFS.PosPrefixInfo -> WithSnippets -> IdeM (IdeResult [J.CompletionItem])
getCompletions uri prefixInfo (WithSnippets withSnippets) =
pluginGetFile "getCompletions: " uri $ \file -> do
let snippetLens = (^? J.textDocument
Expand All @@ -356,7 +339,7 @@ getCompletions uri prefixInfo (WithSnippets withSnippets) =
, J._insertText = Nothing
}

PosPrefixInfo { fullLine, prefixModule, prefixText } = prefixInfo
VFS.PosPrefixInfo { VFS.fullLine, VFS.prefixModule, VFS.prefixText } = prefixInfo
debugm $ "got prefix" ++ show (prefixModule, prefixText)
let enteredQual = if T.null prefixModule then "" else prefixModule <> "."
fullPrefix = enteredQual <> prefixText
Expand All @@ -373,7 +356,7 @@ getCompletions uri prefixInfo (WithSnippets withSnippets) =
^
-}
pos =
let newPos = cursorPos prefixInfo
let newPos = VFS.cursorPos prefixInfo
Position l c = fromMaybe newPos (newPosToOld newPos)
typeStuff = [isSpace, (`elem` (">-." :: String))]
stripTypeStuff = T.dropWhileEnd (\x -> any (\f -> f x) typeStuff)
Expand Down
34 changes: 7 additions & 27 deletions src/Haskell/Ide/Engine/Transport/LspStdio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Control.Monad.STM
import Data.Aeson ( (.=) )
import qualified Data.Aeson as J
import qualified Data.ByteString.Lazy as BL
import Data.Char (isUpper, isAlphaNum)
import Data.Coerce (coerce)
import Data.Default
import Data.Foldable
Expand Down Expand Up @@ -65,8 +64,8 @@ import qualified Language.Haskell.LSP.Types.Lens as J
import qualified Language.Haskell.LSP.Utility as U
import qualified Language.Haskell.LSP.VFS as VFS
import System.Exit
import qualified System.Log.Logger as L
import qualified Yi.Rope as Yi
import qualified System.Log.Logger as L
import qualified Data.Rope.UTF16 as Rope

-- ---------------------------------------------------------------------
{-# ANN module ("hlint: ignore Eta reduce" :: String) #-}
Expand Down Expand Up @@ -200,29 +199,10 @@ configVal field = field <$> getClientConfig

getPrefixAtPos :: (MonadIO m, MonadReader REnv m)
=> Uri -> Position -> m (Maybe Hie.PosPrefixInfo)
getPrefixAtPos uri pos@(Position l c) = do
getPrefixAtPos uri pos = do
mvf <- liftIO =<< asksLspFuncs Core.getVirtualFileFunc <*> pure uri
case mvf of
Just (VFS.VirtualFile _ yitext) ->
return $ Just $ fromMaybe (Hie.PosPrefixInfo "" "" "" pos) $ do
let headMaybe [] = Nothing
headMaybe (x:_) = Just x
lastMaybe [] = Nothing
lastMaybe xs = Just $ last xs
curLine <- headMaybe $ Yi.lines $ snd $ Yi.splitAtLine l yitext
let beforePos = Yi.take c curLine
curWord <- case Yi.last beforePos of
Just ' ' -> Just "" -- don't count abc as the curword in 'abc '
_ -> Yi.toText <$> lastMaybe (Yi.words beforePos)
let parts = T.split (=='.')
$ T.takeWhileEnd (\x -> isAlphaNum x || x `elem` ("._'"::String)) curWord
case reverse parts of
[] -> Nothing
(x:xs) -> do
let modParts = dropWhile (not . isUpper . T.head)
$ reverse $ filter (not .T.null) xs
modName = T.intercalate "." modParts
return $ Hie.PosPrefixInfo (Yi.toText curLine) modName x pos
Just vf -> VFS.getCompletionPrefix pos vf
Nothing -> return Nothing

-- ---------------------------------------------------------------------
Expand All @@ -237,8 +217,8 @@ mapFileFromVfs tn vtdi = do
vfsFunc <- asksLspFuncs Core.getVirtualFileFunc
mvf <- liftIO $ vfsFunc uri
case (mvf, uriToFilePath uri) of
(Just (VFS.VirtualFile _ yitext), Just fp) -> do
let text' = Yi.toString yitext
(Just (VFS.VirtualFile _ yitext _), Just fp) -> do
let text' = Rope.toString yitext
-- text = "{-# LINE 1 \"" ++ fp ++ "\"#-}\n" <> text'
let req = GReq tn (Just uri) Nothing Nothing (const $ return ())
$ IdeResultOk <$> do
Expand Down Expand Up @@ -826,7 +806,7 @@ withDocumentContents reqId uri f = do
(J.responseId reqId)
J.InvalidRequest
"Document was not open"
Just (VFS.VirtualFile _ txt) -> f (Yi.toText txt)
Just (VFS.VirtualFile _ txt _) -> f (Rope.toText txt)

-- | Get the currently configured formatter provider.
-- The currently configured formatter provider is defined in @Config@ by PluginId.
Expand Down
10 changes: 7 additions & 3 deletions stack-8.2.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extra-deps:
- ./submodules/ghc-mod
- ./submodules/ghc-mod/core
- ./submodules/ghc-mod/ghc-project-types
- ./submodules/haskell-lsp
- ./submodules/haskell-lsp/haskell-lsp-types
- ./submodules/lsp-test

# - brittany-0.11.0.0
- butcher-1.3.1.1
Expand All @@ -20,14 +23,15 @@ extra-deps:
- ghc-exactprint-0.5.8.2
- haddock-api-2.18.1
- haddock-library-1.4.4
- haskell-lsp-0.11.0.0
- haskell-lsp-types-0.11.0.0
# - haskell-lsp-0.12.1.0
# - haskell-lsp-types-0.12.1.0
- hlint-2.0.11
- hsimport-0.8.8
- lsp-test-0.5.2.0
# - lsp-test-0.5.2.1
- monad-dijkstra-0.1.1.2
- mtl-2.2.2
- pretty-show-1.8.2
- rope-utf16-splay-0.3.1.0
- sorted-list-0.2.1.0
- syz-0.2.0.0
- yaml-0.8.32
Expand Down
10 changes: 7 additions & 3 deletions stack-8.2.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extra-deps:
- ./submodules/ghc-mod
- ./submodules/ghc-mod/core
- ./submodules/ghc-mod/ghc-project-types
- ./submodules/haskell-lsp
- ./submodules/haskell-lsp/haskell-lsp-types
- ./submodules/lsp-test

# - brittany-0.11.0.0
- butcher-1.3.1.1
Expand All @@ -21,16 +24,17 @@ extra-deps:
- ghc-exactprint-0.5.8.2
- haddock-api-2.18.1
- haddock-library-1.4.4
- haskell-lsp-0.11.0.0
- haskell-lsp-types-0.11.0.0
# - haskell-lsp-0.12.1.0
# - haskell-lsp-types-0.12.1.0
- haskell-src-exts-1.21.0
- haskell-src-exts-util-0.2.5
- hlint-2.1.17
- hoogle-5.0.17.6
- hsimport-0.8.8
- lsp-test-0.5.2.0
# - lsp-test-0.5.2.1
- monad-dijkstra-0.1.1.2
- pretty-show-1.8.2
- rope-utf16-splay-0.3.1.0
- sorted-list-0.2.1.0
- syz-0.2.0.0

Expand Down
10 changes: 7 additions & 3 deletions stack-8.4.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extra-deps:
- ./submodules/ghc-mod
- ./submodules/ghc-mod/core
- ./submodules/ghc-mod/ghc-project-types
- ./submodules/haskell-lsp
- ./submodules/haskell-lsp/haskell-lsp-types
- ./submodules/lsp-test

# - brittany-0.11.0.0
- base-compat-0.9.3
Expand All @@ -19,16 +22,17 @@ extra-deps:
- ghc-exactprint-0.5.8.2
- haddock-api-2.20.0
- haddock-library-1.6.0
- haskell-lsp-0.11.0.0
- haskell-lsp-types-0.11.0.0
# - haskell-lsp-0.12.1.0
# - haskell-lsp-types-0.12.1.0
- haskell-src-exts-1.21.0
- haskell-src-exts-util-0.2.5
- hlint-2.1.17
- hoogle-5.0.17.6
- hsimport-0.8.8
- lsp-test-0.5.2.0
# - lsp-test-0.5.2.1
- monad-dijkstra-0.1.1.2
- pretty-show-1.8.2
- rope-utf16-splay-0.3.1.0
- syz-0.2.0.0
- temporary-1.2.1.1
- windns-0.1.0.0
Expand Down
10 changes: 7 additions & 3 deletions stack-8.4.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extra-deps:
- ./submodules/ghc-mod
- ./submodules/ghc-mod/core
- ./submodules/ghc-mod/ghc-project-types
- ./submodules/haskell-lsp
- ./submodules/haskell-lsp/haskell-lsp-types
- ./submodules/lsp-test

- base-compat-0.9.3
- cabal-plan-0.3.0.0
Expand All @@ -18,16 +21,17 @@ extra-deps:
- ghc-exactprint-0.5.8.2
- haddock-api-2.20.0
- haddock-library-1.6.0
- haskell-lsp-0.11.0.0
- haskell-lsp-types-0.11.0.0
# - haskell-lsp-0.12.1.0
# - haskell-lsp-types-0.12.1.0
- haskell-src-exts-1.21.0
- haskell-src-exts-util-0.2.5
- hlint-2.1.17
- hoogle-5.0.17.6
- hsimport-0.8.8
- lsp-test-0.5.2.0
# - lsp-test-0.5.2.1
- monad-dijkstra-0.1.1.2
- pretty-show-1.8.2
- rope-utf16-splay-0.3.1.0
- syz-0.2.0.0
- temporary-1.2.1.1

Expand Down
10 changes: 7 additions & 3 deletions stack-8.4.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extra-deps:
- ./submodules/ghc-mod
- ./submodules/ghc-mod/core
- ./submodules/ghc-mod/ghc-project-types
- ./submodules/haskell-lsp
- ./submodules/haskell-lsp/haskell-lsp-types
- ./submodules/lsp-test

# - brittany-0.11.0.0
- cabal-plan-0.4.0.0
Expand All @@ -18,17 +21,18 @@ extra-deps:
- ghc-exactprint-0.5.8.2
- haddock-api-2.20.0
- haddock-library-1.6.0
- haskell-lsp-0.11.0.0
- haskell-lsp-types-0.11.0.0
# - haskell-lsp-0.12.1.0
# - haskell-lsp-types-0.12.1.0
- haskell-src-exts-1.21.0
- haskell-src-exts-util-0.2.5
- hlint-2.1.17
- hoogle-5.0.17.6
- hsimport-0.8.8
- lsp-test-0.5.2.0
# - lsp-test-0.5.2.1
- monad-dijkstra-0.1.1.2
- optparse-simple-0.1.0
- pretty-show-1.9.5
- rope-utf16-splay-0.3.1.0
- syz-0.2.0.0
- temporary-1.2.1.1

Expand Down
Loading