Skip to content

Commit 239737b

Browse files
authored
Merge branch 'master' into master
2 parents bf764a1 + cda1325 commit 239737b

File tree

9 files changed

+83
-47
lines changed

9 files changed

+83
-47
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ package *
5656

5757
write-ghc-environment-files: never
5858

59-
index-state: 2023-03-30T00:00:00Z
59+
index-state: 2023-04-19T12:00:00Z
6060

6161
constraints:
6262
-- For GHC 9.4, older versions of entropy fail to build on Windows

configuration-ghc-96.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let
4242
ptr-poker = hself.callCabal2nix "ptr-poker" inputs.ptr-poker { };
4343

4444
ormolu = hself.ormolu_0_5_3_0;
45+
fourmolu = hself.callCabal2nix "fourmolu" inputs.fourmolu-012 { };
4546

4647
stylish-haskell = appendConfigureFlag hsuper.stylish-haskell "-fghc-lib";
4748

flake.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
url = "github:alanz/ghc-exactprint/ghc-9.6";
6060
flake = false;
6161
};
62+
63+
fourmolu-012 = {
64+
url = "https://hackage.haskell.org/package/fourmolu-0.12.0.0/fourmolu-0.12.0.0.tar.gz";
65+
flake = false;
66+
};
6267
};
6368
outputs =
6469
inputs@{ self, nixpkgs, flake-compat, flake-utils, gitignore, ... }:

haskell-language-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ common floskell
344344
cpp-options: -Dhls_floskell
345345

346346
common fourmolu
347-
if flag(fourmolu) && impl(ghc < 9.5)
347+
if flag(fourmolu)
348348
build-depends: hls-fourmolu-plugin ^>= 1.1
349349
cpp-options: -Dhls_fourmolu
350350

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ source-repository head
2323
location: git://github.com/haskell/haskell-language-server.git
2424

2525
library
26-
if impl(ghc >= 9.5)
27-
buildable: False
26+
buildable: True
2827
exposed-modules:
2928
Ide.Plugin.Fourmolu
3029
, Ide.Plugin.Fourmolu.Shim
@@ -33,7 +32,7 @@ library
3332
build-depends:
3433
, base >=4.12 && <5
3534
, filepath
36-
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11
35+
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11 || ^>= 0.12
3736
, ghc
3837
, ghc-boot-th
3938
, ghcide ^>= 1.9 || ^>= 1.10
@@ -49,8 +48,7 @@ library
4948
default-language: Haskell2010
5049

5150
test-suite tests
52-
if impl(ghc >= 9.5)
53-
buildable: False
51+
buildable: True
5452
type: exitcode-stdio-1.0
5553
default-language: Haskell2010
5654
hs-source-dirs: test

plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,53 @@ module Ide.Plugin.ModuleName (
1717
Log,
1818
) where
1919

20-
import Control.Monad (forM_, void)
21-
import Control.Monad.IO.Class (liftIO)
22-
import Control.Monad.Trans.Class (lift)
20+
import Control.Monad (forM_, void)
21+
import Control.Monad.IO.Class (liftIO)
22+
import Control.Monad.Trans.Class (lift)
2323
import Control.Monad.Trans.Maybe
24-
import Data.Aeson (Value (Null), toJSON)
25-
import Data.Char (isLower)
26-
import qualified Data.HashMap.Strict as HashMap
27-
import Data.List (intercalate, isPrefixOf,
28-
minimumBy)
29-
import qualified Data.List.NonEmpty as NE
30-
import Data.Maybe (maybeToList)
31-
import Data.Ord (comparing)
32-
import Data.String (IsString)
33-
import qualified Data.Text as T
34-
import Development.IDE (GetParsedModule (GetParsedModule),
35-
GhcSession (GhcSession),
36-
IdeState, Pretty,
37-
Priority (Debug), Recorder,
38-
WithPriority, colon, evalGhcEnv,
39-
hscEnvWithImportPaths, logWith,
40-
realSrcSpanToRange, runAction,
41-
uriToFilePath', use, use_, (<+>))
42-
import Development.IDE.GHC.Compat (GenLocated (L),
43-
getSessionDynFlags, hsmodName,
44-
importPaths, locA,
45-
moduleNameString,
46-
pattern RealSrcSpan,
47-
pm_parsed_source, unLoc)
48-
import Development.IDE.Types.Logger (Pretty (..))
24+
import Data.Aeson (Value (Null), toJSON)
25+
import Data.Char (isLower)
26+
import qualified Data.HashMap.Strict as HashMap
27+
import Data.List (intercalate, isPrefixOf,
28+
minimumBy)
29+
import qualified Data.List.NonEmpty as NE
30+
import Data.Maybe (fromMaybe, maybeToList)
31+
import Data.Ord (comparing)
32+
import Data.String (IsString)
33+
import qualified Data.Text as T
34+
import Development.IDE (GetParsedModule (GetParsedModule),
35+
GhcSession (GhcSession),
36+
IdeState, Pretty,
37+
Priority (Debug),
38+
Recorder, WithPriority,
39+
colon, evalGhcEnv,
40+
hscEnvWithImportPaths,
41+
logWith,
42+
realSrcSpanToRange,
43+
runAction,
44+
uriToFilePath',
45+
useWithStale,
46+
useWithStale_, (<+>))
47+
import Development.IDE.Core.PositionMapping (toCurrentRange)
48+
import Development.IDE.GHC.Compat (GenLocated (L),
49+
getSessionDynFlags,
50+
hsmodName, importPaths,
51+
locA, moduleNameString,
52+
pattern RealSrcSpan,
53+
pm_parsed_source, unLoc)
54+
import Development.IDE.Types.Logger (Pretty (..))
4955
import Ide.Types
5056
import Language.LSP.Server
51-
import Language.LSP.Types hiding
52-
(SemanticTokenAbsolute (length, line),
53-
SemanticTokenRelative (length),
54-
SemanticTokensEdit (_start))
55-
import Language.LSP.VFS (virtualFileText)
56-
import System.Directory (makeAbsolute)
57-
import System.FilePath (dropExtension, normalise,
58-
pathSeparator, splitDirectories,
59-
takeFileName)
57+
import Language.LSP.Types hiding
58+
(SemanticTokenAbsolute (length, line),
59+
SemanticTokenRelative (length),
60+
SemanticTokensEdit (_start))
61+
import Language.LSP.VFS (virtualFileText)
62+
import System.Directory (makeAbsolute)
63+
import System.FilePath (dropExtension, normalise,
64+
pathSeparator,
65+
splitDirectories,
66+
takeFileName)
6067

6168
-- |Plugin descriptor
6269
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
@@ -134,7 +141,7 @@ pathModuleNames :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath
134141
pathModuleNames recorder state normFilePath filePath
135142
| isLower . head $ takeFileName filePath = return ["Main"]
136143
| otherwise = do
137-
session <- runAction "ModuleName.ghcSession" state $ use_ GhcSession normFilePath
144+
session <- fst <$> (runAction "ModuleName.ghcSession" state $ useWithStale_ GhcSession normFilePath)
138145
srcPaths <- evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags
139146
logWith recorder Debug (SrcPaths srcPaths)
140147

@@ -160,9 +167,10 @@ pathModuleNames recorder state normFilePath filePath
160167
-- | The module name, as stated in the module
161168
codeModuleName :: IdeState -> NormalizedFilePath -> IO (Maybe (Range, T.Text))
162169
codeModuleName state nfp = runMaybeT $ do
163-
pm <- MaybeT . runAction "ModuleName.GetParsedModule" state $ use GetParsedModule nfp
170+
(pm, mp) <- MaybeT . runAction "ModuleName.GetParsedModule" state $ useWithStale GetParsedModule nfp
164171
L (locA -> (RealSrcSpan l _)) m <- MaybeT . pure . hsmodName . unLoc $ pm_parsed_source pm
165-
pure (realSrcSpanToRange l, T.pack $ moduleNameString m)
172+
range <- MaybeT . pure $ toCurrentRange mp (realSrcSpanToRange l)
173+
pure (range, T.pack $ moduleNameString m)
166174

167175
data Log =
168176
CorrectNames [T.Text]

plugins/hls-module-name-plugin/test/Main.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ tests =
4848
[CodeLens { _command = Just c }] <- getCodeLenses doc
4949
executeCommand c
5050
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
51+
, testCase "Keep stale lens even if parse failed" $ do
52+
runSessionWithServer moduleNamePlugin testDataDir $ do
53+
doc <- openDoc "Stale.hs" "haskell"
54+
oldLens <- getCodeLenses doc
55+
let edit = TextEdit (mkRange 1 0 1 0) "f ="
56+
_ <- applyEdit doc edit
57+
newLens <- getCodeLenses doc
58+
txt <- documentContents doc
59+
liftIO $ newLens @?= oldLens
60+
closeDoc doc
5161
]
5262

5363
goldenWithModuleName :: TestName -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Foo where

0 commit comments

Comments
 (0)