Skip to content

Commit db18100

Browse files
authored
Merge branch 'master' into batch-load-multi-read
2 parents de6eb9c + 664931b commit db18100

File tree

15 files changed

+66
-35
lines changed

15 files changed

+66
-35
lines changed

.github/actions/setup-build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ inputs:
77
cabal:
88
description: "Cabal version"
99
required: false
10-
default: "3.10.2.0"
10+
default: "3.14.2.0"
1111
os:
1212
description: "Operating system: Linux, Windows or macOS"
1313
required: true

.github/workflows/bench.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
matrix:
124124
ghc: ['9.8', '9.10']
125125
os: [ubuntu-latest]
126-
cabal: ['3.10']
126+
cabal: ['3.14']
127127
example: ['cabal', 'lsp-types']
128128

129129
steps:

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ packages:
88
./hls-test-utils
99

1010

11-
index-state: 2025-04-26T07:34:07Z
11+
index-state: 2025-05-06T13:26:29Z
1212

1313
tests: True
1414
test-show-details: direct

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ This option obviously would not make sense for language servers for other langua
4141
Here is a list of the additional settings currently supported by `haskell-language-server`, along with their setting key (you may not need to know this) and default:
4242

4343
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, or `stylish-haskell`.
44+
- Cabal formatting provider (`haskell.cabalFormattingProvider`, default `cabal-gild`): what formatter to use for cabal files; one of `cabal-gild` or `cabal-fmt`.
4445
- Max completions (`haskell.maxCompletions`, default 40): maximum number of completions sent to the LSP client.
4546
- Check project (`haskell.checkProject`, default true): whether to typecheck the entire project on initial load. As it is activated by default could drive to bad performance in large projects.
4647
- Check parents (`haskell.checkParents`, default `CheckOnSave`): when to typecheck reverse dependencies of a file; one of `NeverCheck`, `CheckOnSave` (means dependent/parent modules will only be checked when you save), or `AlwaysCheck` (means re-typechecking them on every change).
48+
- Session loading preference (`haskell.sessionLoading`, default `singleComponent`): how to load sessions; one of `singleComponent` (means always loading only a single component when a new component is discovered) or `multipleComponents` (means always preferring loading multiple components in the cradle at once). `multipleComponents` might not be always possible, if the tool doesn't support multiple components loading. The cradle can decide how to handle these situations, and whether to honour the preference at all.
4749

4850
#### Generic plugin configuration
4951

docs/features.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,17 @@ Known limitations:
411411

412412
- Cross-module renaming requires all components to be indexed, which sometimes causes [partial renames in multi-component projects](https://github.com/haskell/haskell-language-server/issues/2193).
413413

414+
To eagerly load all components, you need to
415+
416+
- set `haskell.sessionLoading` to `multipleComponents`,
417+
- set `hie.yaml` to load all components (currently only cabal supports this),
418+
```yaml
419+
cradle:
420+
cabal:
421+
component: all
422+
```
423+
- and enable tests and benchmarks in `cabal.project` with `tests: True` and `benchmarks: True`.
424+
414425
## Semantic tokens
415426

416427
Provided by: `hls-semantic-tokens-plugin`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cabal-version: 2.4
2+
name: reload
3+
version: 0.1.0.0
4+
author: Lin Jian
5+
maintainer: [email protected]
6+
build-type: Simple
7+
8+
library
9+
exposed-modules: MyLib
10+
build-depends: base
11+
hs-source-dirs: src
12+
default-language: Haskell2010
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module MyLib (someFunc) where
2+
3+
import Data.List.Split
4+
5+
someFunc :: IO ()
6+
someFunc = putStrLn "someFunc"

ghcide-test/exe/WatchedFileTests.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
module WatchedFileTests (tests) where
55

6-
import Config (testWithDummyPluginEmpty')
6+
import Config (mkIdeTestFs,
7+
testWithDummyPlugin',
8+
testWithDummyPluginEmpty')
79
import Control.Applicative.Combinators
810
import Control.Monad.IO.Class (liftIO)
911
import qualified Data.Aeson as A
1012
import qualified Data.Text as T
13+
import qualified Data.Text.IO as T
1114
import Development.IDE.Test (expectDiagnostics)
1215
import Language.LSP.Protocol.Message
1316
import Language.LSP.Protocol.Types hiding
@@ -18,6 +21,7 @@ import Language.LSP.Protocol.Types hiding
1821
import Language.LSP.Test
1922
import System.Directory
2023
import System.FilePath
24+
import Test.Hls.FileSystem
2125
import Test.Tasty
2226
import Test.Tasty.HUnit
2327

@@ -69,6 +73,17 @@ tests = testGroup "watched files"
6973
sendNotification SMethod_WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams
7074
[FileEvent (filePathToUri $ sessionDir </> "B.hs") FileChangeType_Changed ]
7175
expectDiagnostics [("A.hs", [(DiagnosticSeverity_Error, (3, 4), "Couldn't match expected type '()' with actual type 'Int'", Just "GHC-83865")])]
76+
, testWithDummyPlugin' "reload HLS after .cabal file changes" (mkIdeTestFs [copyDir ("watched-files" </> "reload")]) $ \sessionDir -> do
77+
let hsFile = "src" </> "MyLib.hs"
78+
_ <- openDoc hsFile "haskell"
79+
expectDiagnostics [(hsFile, [(DiagnosticSeverity_Error, (2, 7), "Could not load module \8216Data.List.Split\8217", Nothing)])]
80+
let cabalFile = "reload.cabal"
81+
cabalContent <- liftIO $ T.readFile cabalFile
82+
let fix = T.replace "build-depends: base" "build-depends: base, split"
83+
liftIO $ T.writeFile cabalFile (fix cabalContent)
84+
sendNotification SMethod_WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams
85+
[ FileEvent (filePathToUri $ sessionDir </> cabalFile) FileChangeType_Changed ]
86+
expectDiagnostics [(hsFile, [])]
7287
]
7388
]
7489

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,18 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
893893
checkInCache ncfp = runMaybeT $ do
894894
cachedHieYamlLocation <- MaybeT $ STM.lookup ncfp (filesMap sessionState)
895895
m <- MaybeT $ STM.lookup cachedHieYamlLocation (fileToFlags sessionState)
896-
MaybeT $ pure $ HM.lookup ncfp m
896+
-- Each one of deps will be registered as a FileSystemWatcher in the GhcSession action
897+
-- so that we can get a workspace/didChangeWatchedFiles notification when a dep changes.
898+
-- The GlobPattern of a FileSystemWatcher can be absolute or relative.
899+
-- We use the absolute one because it is supported by more LSP clients.
900+
-- Here we make sure deps are absolute and later we use those absolute deps as GlobPattern.
901+
let absolutePathsCradleDeps (eq, deps) = (eq, fmap toAbsolutePath deps)
902+
MaybeT $ pure $ absolutePathsCradleDeps <$> HM.lookup ncfp m
897903

898904
-- The main function which gets options for a file. We only want one of these running
899905
-- at a time. Therefore the IORef contains the currently running cradle, if we try
900906
-- to get some more options then we wait for the currently running action to finish
901907
-- before attempting to do so.
902-
903908
let getOptionsLoop :: IO ()
904909
getOptionsLoop = do
905910
-- Get the next file to load

ghcide/session-loader/Development/IDE/Session/Diagnostics.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ data CradleErrorDetails =
2828
Depicts the cradle error in a user-friendly way.
2929
-}
3030
renderCradleError :: CradleError -> Cradle a -> NormalizedFilePath -> FileDiagnostic
31-
renderCradleError (CradleError deps _ec ms _attemptToLoadFiles) cradle nfp =
31+
renderCradleError cradleError cradle nfp =
3232
let noDetails =
3333
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp (T.unlines $ map T.pack userFriendlyMessage) Nothing
3434
in
3535
if HieBios.isCabalCradle cradle
3636
then noDetails & fdLspDiagnosticL %~ \diag -> diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}}
3737
else noDetails
3838
where
39-
absDeps = fmap (cradleRootDir cradle </>) deps
39+
ms = cradleErrorStderr cradleError
40+
41+
absDeps = fmap (cradleRootDir cradle </>) (cradleErrorDependencies cradleError)
4042
userFriendlyMessage :: [String]
4143
userFriendlyMessage
4244
| HieBios.isCabalCradle cradle = fromMaybe ms $ fileMissingMessage <|> mkUnknownModuleMessage

0 commit comments

Comments
 (0)