Skip to content

Commit c8ac730

Browse files
committed
Merge branch 'master' of github.com:haskell/haskell-language-server
2 parents 5a896aa + 2a58af8 commit c8ac730

18 files changed

+195
-119
lines changed

cabal.project

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ source-repository-package
1010
source-repository-package
1111
type: git
1212
location: https://github.com/fendor/hie-bios.git
13-
tag: d5b7fc9bb3025b1d4d2ac9c48b588faf18dfce99
13+
tag: 89d28817716a1c8df7e191f3a43c4504bc6379eb
1414

15+
source-repository-package
16+
type: git
17+
location: https://github.com/mpickering/shake
18+
tag: 4d56fe9f09bd3bd63ead541c571c756995da490a
1519

1620
tests: true
1721
documentation: false
@@ -24,4 +28,4 @@ package ghcide
2428

2529
write-ghc-environment-files: never
2630

27-
index-state: 2020-03-24T21:15:10Z
31+
index-state: 2020-04-24T21:15:10Z

exe/Main.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ import Development.IDE.Types.Diagnostics
4949
import Development.IDE.Types.Location
5050
import Development.IDE.Types.Logger
5151
import Development.IDE.Types.Options
52-
import Development.Shake (Action, action)
52+
import Development.Shake (Action)
5353
import DynFlags (gopt_set, gopt_unset,
5454
updOptLevel)
5555
import DynFlags (PackageFlag(..), PackageArg(..))
5656
import GHC hiding (def)
5757
import GHC.Check (runTimeVersion, compileTimeVersionFromLibdir)
5858
-- import GhcMonad
5959
import HIE.Bios.Cradle
60-
import HIE.Bios.Environment (addCmdOpts)
60+
import HIE.Bios.Environment (addCmdOpts, makeDynFlagsAbsolute)
6161
import HIE.Bios.Types
6262
import HscTypes (HscEnv(..), ic_dflags)
6363
import qualified Language.Haskell.LSP.Core as LSP
@@ -195,7 +195,7 @@ main = do
195195
, optInterfaceLoadingDiagnostics = argsTesting
196196
}
197197
debouncer <- newAsyncDebouncer
198-
initialise caps (mainRule >> pluginRules plugins >> action kick)
198+
initialise caps (mainRule >> pluginRules plugins)
199199
getLspId event hlsLogger debouncer options vfs
200200
else do
201201
-- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
@@ -218,13 +218,12 @@ main = do
218218
putStrLn $ "Found " ++ show n ++ " cradle" ++ ['s' | n /= 1]
219219
putStrLn "\nStep 3/6: Initializing the IDE"
220220
vfs <- makeVFSHandle
221-
222221
debouncer <- newAsyncDebouncer
223222
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) debouncer (defaultIdeOptions $ loadSession dir) vfs
224223

225224
putStrLn "\nStep 4/6: Type checking the files"
226225
setFilesOfInterest ide $ HashSet.fromList $ map toNormalizedFilePath' files
227-
_ <- runActionSync ide $ uses TypeCheck (map toNormalizedFilePath' files)
226+
_ <- runActionSync "TypecheckTest" ide $ uses TypeCheck (map toNormalizedFilePath' files)
228227
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "src/Development/IDE/Core/Rules.hs"
229228
-- results <- runActionSync ide $ use TypeCheck $ toNormalizedFilePath' "exe/Main.hs"
230229
return ()
@@ -241,11 +240,13 @@ expandFiles = concatMapM $ \x -> do
241240
fail $ "Couldn't find any .hs/.lhs files inside directory: " ++ x
242241
return files
243242

244-
243+
-- Running this every hover is too expensive, 0.2s on GHC for example
244+
{-
245245
kick :: Action ()
246246
kick = do
247247
files <- getFilesOfInterest
248248
void $ uses TypeCheck $ HashSet.toList files
249+
-}
249250

250251
-- | Print an LSP event.
251252
showEvent :: Lock -> FromServerMessage -> IO ()
@@ -525,7 +526,8 @@ memoIO op = do
525526
setOptions :: GhcMonad m => ComponentOptions -> DynFlags -> m (DynFlags, [Target])
526527
setOptions (ComponentOptions theOpts compRoot _) dflags = do
527528
cacheDir <- liftIO $ getCacheDir theOpts
528-
(dflags', targets) <- addCmdOpts compRoot theOpts dflags
529+
(dflags_, targets) <- addCmdOpts theOpts dflags
530+
let dflags' = makeDynFlagsAbsolute compRoot dflags_
529531
let dflags'' =
530532
-- disabled, generated directly by ghcide instead
531533
flip gopt_unset Opt_WriteInterface $

haskell-language-server.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ library
4949
Ide.Plugin.Pragmas
5050
Ide.Plugin.Floskell
5151
Ide.Plugin.Formatter
52+
Ide.PluginUtils
5253
Ide.Types
5354
Ide.Version
5455
other-modules:
5556
Paths_haskell_language_server
5657
hs-source-dirs:
5758
src
5859
build-depends:
59-
base >=4.7 && <5
60+
base >=4.12 && <5
6061
, aeson
6162
, binary
6263
, bytestring
@@ -65,6 +66,7 @@ library
6566
, containers
6667
, data-default
6768
, deepseq
69+
, Diff
6870
, directory
6971
, extra
7072
, filepath
@@ -77,6 +79,7 @@ library
7779
, hie-bios >= 0.4
7880
, hslogger
7981
, lens
82+
, ormolu ^>= 0.0.5.0
8083
, optparse-simple
8184
, process
8285
, regex-tdfa >= 1.3.1.0
@@ -94,9 +97,6 @@ library
9497
exposed-modules:
9598
Ide.Plugin.Brittany
9699

97-
if impl(ghc >= 8.6)
98-
build-depends: ormolu >= 0.0.3.1
99-
100100
ghc-options:
101101
-Wall
102102
-Wredundant-constraints
@@ -152,7 +152,7 @@ executable haskell-language-server
152152
-- which works for now.
153153
, ghc
154154
--------------------------------------------------------------
155-
, ghc-check
155+
, ghc-check ^>= 0.1
156156
, ghc-paths
157157
, ghcide
158158
, gitrev

src/Ide/Plugin/Brittany.hs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Language.Haskell.Brittany
1212
import Language.Haskell.LSP.Types as J
1313
import qualified Language.Haskell.LSP.Types.Lens as J
1414
import Ide.Plugin.Formatter
15+
import Ide.PluginUtils
1516
import Ide.Types
1617

1718
import System.FilePath
@@ -36,7 +37,7 @@ descriptor plId = PluginDescriptor
3637
-- If the provider fails an error is returned that can be displayed to the user.
3738
provider
3839
:: FormattingProvider IO
39-
provider _ideState typ contents fp opts = do
40+
provider _lf _ideState typ contents fp opts = do
4041
-- text uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \fp -> do
4142
confFile <- liftIO $ getConfFile fp
4243
let (range, selectedContents) = case typ of
@@ -61,11 +62,6 @@ formatText confFile opts text =
6162
liftIO $ runBrittany tabSize confFile text
6263
where tabSize = opts ^. J.tabSize
6364

64-
-- | Extend to the line below and above to replace newline character.
65-
normalize :: Range -> Range
66-
normalize (Range (Position sl _) (Position el _)) =
67-
Range (Position sl 0) (Position (el + 1) 0)
68-
6965
-- | Recursively search in every directory of the given filepath for brittany.yaml.
7066
-- If no such file has been found, return Nothing.
7167
getConfFile :: NormalizedFilePath -> IO (Maybe FilePath)

src/Ide/Plugin/Example.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
125125
logInfo (ideLogger ideState) "Example.codeLens entered (ideLogger)" -- AZ
126126
case uriToFilePath' uri of
127127
Just (toNormalizedFilePath -> filePath) -> do
128-
_ <- runAction ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runAction "Example.codeLens" ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let
@@ -190,7 +190,7 @@ logAndRunRequest label getResults ide pos path = do
190190
logInfo (ideLogger ide) $
191191
label <> " request at position " <> T.pack (showPosition pos) <>
192192
" in file: " <> T.pack path
193-
runAction ide $ getResults filePath pos
193+
runAction "Example" ide $ getResults filePath pos
194194

195195
-- ---------------------------------------------------------------------
196196

src/Ide/Plugin/Example2.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier u
125125
logInfo (ideLogger ideState) "Example2.codeLens entered (ideLogger)" -- AZ
126126
case uriToFilePath' uri of
127127
Just (toNormalizedFilePath -> filePath) -> do
128-
_ <- runAction ideState $ runMaybeT $ useE TypeCheck filePath
128+
_ <- runAction (fromNormalizedFilePath filePath) ideState $ runMaybeT $ useE TypeCheck filePath
129129
_diag <- getDiagnostics ideState
130130
_hDiag <- getHiddenDiagnostics ideState
131131
let
@@ -187,7 +187,7 @@ logAndRunRequest label getResults ide pos path = do
187187
logInfo (ideLogger ide) $
188188
label <> " request at position " <> T.pack (showPosition pos) <>
189189
" in file: " <> T.pack path
190-
runAction ide $ getResults filePath pos
190+
runAction "Example2" ide $ getResults filePath pos
191191

192192
-- ---------------------------------------------------------------------
193193

src/Ide/Plugin/Floskell.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE RecordWildCards #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE ScopedTypeVariables #-}
54
{-# LANGUAGE TypeApplications #-}
@@ -45,7 +44,7 @@ descriptor plId = PluginDescriptor
4544
-- Formats the given source in either a given Range or the whole Document.
4645
-- If the provider fails an error is returned that can be displayed to the user.
4746
provider :: FormattingProvider IO
48-
provider _ideState typ contents fp _ = do
47+
provider _lf _ideState typ contents fp _ = do
4948
let file = fromNormalizedFilePath fp
5049
config <- findConfigOrDefault file
5150
let (range, selectedContents) = case typ of

src/Ide/Plugin/Formatter.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE RecordWildCards #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE ScopedTypeVariables #-}
54
{-# LANGUAGE TypeApplications #-}
@@ -65,20 +64,20 @@ doFormatting lf providers ideState ft uri params = do
6564
Just provider ->
6665
case uriToFilePath uri of
6766
Just (toNormalizedFilePath -> fp) -> do
68-
(_, mb_contents) <- runAction ideState $ getFileContents fp
67+
(_, mb_contents) <- runAction "Formatter" ideState $ getFileContents fp
6968
case mb_contents of
7069
Just contents -> do
7170
logDebug (ideLogger ideState) $ T.pack $
7271
"Formatter.doFormatting: contents=" ++ show contents -- AZ
73-
provider ideState ft contents fp params
72+
provider lf ideState ft contents fp params
7473
Nothing -> return $ Left $ responseError $ T.pack $ "Formatter plugin: could not get file contents for " ++ show uri
7574
Nothing -> return $ Left $ responseError $ T.pack $ "Formatter plugin: uriToFilePath failed for: " ++ show uri
7675
Nothing -> return $ Left $ responseError $ T.pack $ "Formatter plugin: no formatter found for:[" ++ T.unpack mf ++ "]"
7776

7877
-- ---------------------------------------------------------------------
7978

8079
noneProvider :: FormattingProvider IO
81-
noneProvider _ _ _ _ _ = return $ Right (List [])
80+
noneProvider _ _ _ _ _ _ = return $ Right (List [])
8281

8382
-- ---------------------------------------------------------------------
8483

src/Ide/Plugin/Ormolu.hs

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE RecordWildCards #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE ScopedTypeVariables #-}
54
{-# LANGUAGE TypeApplications #-}
@@ -13,10 +12,6 @@ module Ide.Plugin.Ormolu
1312
where
1413

1514
import Control.Exception
16-
import Control.Monad
17-
import Data.Char
18-
import Data.List
19-
import Data.Maybe
2015
import qualified Data.Text as T
2116
import Development.IDE.Core.Rules
2217
import Development.IDE.Types.Diagnostics as D
@@ -25,7 +20,7 @@ import qualified DynFlags as D
2520
import qualified EnumSet as S
2621
import GHC
2722
import Ide.Types
28-
import qualified HIE.Bios as BIOS
23+
import Ide.PluginUtils
2924
import Ide.Plugin.Formatter
3025
import Language.Haskell.LSP.Types
3126
import Ormolu
@@ -50,19 +45,7 @@ descriptor plId = PluginDescriptor
5045
-- ---------------------------------------------------------------------
5146

5247
provider :: FormattingProvider IO
53-
#if __GLASGOW_HASKELL__ >= 806
54-
provider ideState typ contents fp _ = do
55-
let
56-
exop s =
57-
"-X" `isPrefixOf` s || "-fplugin=" `isPrefixOf` s || "-pgmF=" `isPrefixOf` s
58-
opts <- lookupBiosComponentOptions fp
59-
let cradleOpts =
60-
map DynOption
61-
$ filter exop
62-
$ join
63-
$ maybeToList
64-
$ BIOS.componentOptions
65-
<$> opts
48+
provider _lf ideState typ contents fp _ = do
6649
let
6750
fromDyn :: ParsedModule -> IO [DynOption]
6851
fromDyn pmod =
@@ -76,62 +59,28 @@ provider ideState typ contents fp _ = do
7659
in
7760
return $ map DynOption $ pp <> pm <> ex
7861

79-
m_parsed <- runAction ideState $ getParsedModule fp
62+
m_parsed <- runAction "Ormolu" ideState $ getParsedModule fp
8063
fileOpts <- case m_parsed of
8164
Nothing -> return []
8265
Just pm -> fromDyn pm
8366

8467
let
85-
conf o = Config o False False True False
86-
fmt :: T.Text -> [DynOption] -> IO (Either OrmoluException T.Text)
87-
fmt cont o =
88-
try @OrmoluException (ormolu (conf o) (fromNormalizedFilePath fp) $ T.unpack cont)
68+
fullRegion = RegionIndices Nothing Nothing
69+
rangeRegion s e = RegionIndices (Just s) (Just e)
70+
mkConf o region = defaultConfig { cfgDynOptions = o, cfgRegion = region }
71+
fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text)
72+
fmt cont conf =
73+
try @OrmoluException (ormolu conf (fromNormalizedFilePath fp) $ T.unpack cont)
8974

9075
case typ of
91-
FormatText -> ret (fullRange contents) <$> fmt contents cradleOpts
76+
FormatText -> ret <$> fmt contents (mkConf fileOpts fullRegion)
9277
FormatRange r ->
9378
let
94-
txt = T.lines $ extractRange r contents
95-
lineRange (Range (Position sl _) (Position el _)) =
96-
Range (Position sl 0) $ Position el $ T.length $ last txt
97-
hIsSpace (h : _) = T.all isSpace h
98-
hIsSpace _ = True
99-
fixS t = if hIsSpace txt && (not $ hIsSpace t) then "" : t else t
100-
fixE t = if T.all isSpace $ last txt then t else T.init t
101-
unStrip :: T.Text -> T.Text -> T.Text
102-
unStrip ws new =
103-
fixE $ T.unlines $ map (ws `T.append`) $ fixS $ T.lines new
104-
mStrip :: Maybe (T.Text, T.Text)
105-
mStrip = case txt of
106-
(l : _) ->
107-
let ws = fst $ T.span isSpace l
108-
in (,) ws . T.unlines <$> traverse (T.stripPrefix ws) txt
109-
_ -> Nothing
110-
err :: IO (Either ResponseError (List TextEdit))
111-
err = return $ Left $ responseError
112-
$ T.pack "You must format a whole block of code. Ormolu does not support arbitrary ranges."
113-
fmt' :: (T.Text, T.Text) -> IO (Either ResponseError (List TextEdit))
114-
fmt' (ws, striped) =
115-
ret (lineRange r) <$> (fmap (unStrip ws) <$> fmt striped fileOpts)
79+
Range (Position sl _) (Position el _) = normalize r
11680
in
117-
maybe err fmt' mStrip
81+
ret <$> fmt contents (mkConf fileOpts (rangeRegion sl el))
11882
where
119-
ret :: Range -> Either OrmoluException T.Text -> Either ResponseError (List TextEdit)
120-
ret _ (Left err) = Left
83+
ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit)
84+
ret (Left err) = Left
12185
(responseError (T.pack $ "ormoluCmd: " ++ show err) )
122-
ret r (Right new) = Right (List [TextEdit r new])
123-
124-
#else
125-
provider _ _ _ _ = return $ Right [] -- NOP formatter
126-
#endif
127-
128-
-- ---------------------------------------------------------------------
129-
130-
-- | Find the cradle wide 'ComponentOptions' that apply to a 'FilePath'
131-
lookupBiosComponentOptions :: (Monad m) => NormalizedFilePath -> m (Maybe BIOS.ComponentOptions)
132-
lookupBiosComponentOptions _fp = do
133-
-- gmc <- getModuleCache
134-
-- return $ lookupInCache fp gmc (const Just) (Just . compOpts) Nothing
135-
return Nothing
136-
137-
-- ---------------------------------------------------------------------
86+
ret (Right new) = Right (makeDiffTextEdit contents new)

0 commit comments

Comments
 (0)