Skip to content

Commit acfbf32

Browse files
authored
Merge branch 'master' into improve-hls-runtime-keep-async-only-databse-keys-downsweep-skip-non-dirties
2 parents ee53cd7 + 88ccebe commit acfbf32

File tree

7 files changed

+58
-44
lines changed

7 files changed

+58
-44
lines changed

docs/support/plugin-support.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ For example, a plugin to provide a formatter which has itself been abandoned has
5656
| `hls-explicit-record-fields-plugin` | 2 | |
5757
| `hls-fourmolu-plugin` | 2 | |
5858
| `hls-gadt-plugin` | 2 | |
59-
| `hls-hlint-plugin` | 2 | |
59+
| `hls-hlint-plugin` | 2 | 9.10 [1] |
6060
| `hls-module-name-plugin` | 2 | |
6161
| `hls-notes-plugin` | 2 | |
6262
| `hls-qualify-imported-names-plugin` | 2 | |
@@ -69,3 +69,5 @@ For example, a plugin to provide a formatter which has itself been abandoned has
6969
| `hls-stan-plugin` | 3 | 9.12.2 |
7070
| `hls-retrie-plugin` | 3 | 9.10.1, 9.12.2 |
7171
| `hls-splice-plugin` | 3 | 9.10.1, 9.12.2 |
72+
73+
[1]: HLint is incompatible with GHC 9.10 series. See the issue [#4674](https://github.com/haskell/haskell-language-server/issues/4674) for discussion and explanation.

ghcide/ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ library
8989
, optparse-applicative
9090
, os-string
9191
, parallel
92+
, process
9293
, prettyprinter >=1.7
9394
, prettyprinter-ansi-terminal
9495
, random

ghcide/src/Development/IDE/Main.hs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Control.Concurrent.Extra (withNumCapabilities)
1515
import Control.Concurrent.MVar (MVar, newEmptyMVar,
1616
putMVar, tryReadMVar)
1717
import Control.Concurrent.STM.Stats (dumpSTMStats)
18+
import Control.Exception.Safe as Safe
1819
import Control.Monad.Extra (concatMapM, unless,
1920
when)
2021
import Control.Monad.IO.Class (liftIO)
@@ -115,16 +116,17 @@ import qualified Language.LSP.Server as LSP
115116
import Numeric.Natural (Natural)
116117
import Options.Applicative hiding (action)
117118
import qualified System.Directory.Extra as IO
118-
import System.Exit (ExitCode (ExitFailure),
119+
import System.Exit (ExitCode (ExitFailure, ExitSuccess),
119120
exitWith)
120121
import System.FilePath (takeExtension,
121-
takeFileName)
122+
takeFileName, (</>))
122123
import System.IO (BufferMode (LineBuffering, NoBuffering),
123124
Handle, hFlush,
124125
hPutStrLn,
125126
hSetBuffering,
126127
hSetEncoding, stderr,
127128
stdin, stdout, utf8)
129+
import System.Process (readProcessWithExitCode)
128130
import System.Random (newStdGen)
129131
import System.Time.Extra (Seconds, offsetTime,
130132
showDuration)
@@ -142,6 +144,7 @@ data Log
142144
| LogSession Session.Log
143145
| LogPluginHLS PluginHLS.Log
144146
| LogRules Rules.Log
147+
| LogUsingGit
145148
deriving Show
146149

147150
instance Pretty Log where
@@ -165,6 +168,7 @@ instance Pretty Log where
165168
LogSession msg -> pretty msg
166169
LogPluginHLS msg -> pretty msg
167170
LogRules msg -> pretty msg
171+
LogUsingGit -> "Using git to list file, relying on .gitignore"
168172

169173
data Command
170174
= Check [FilePath] -- ^ Typecheck some paths and print diagnostics. Exit code is the number of failures
@@ -388,7 +392,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
388392
putStrLn "Report bugs at https://github.com/haskell/haskell-language-server/issues"
389393

390394
putStrLn $ "\nStep 1/4: Finding files to test in " ++ dir
391-
files <- expandFiles (argFiles ++ ["." | null argFiles])
395+
files <- expandFiles recorder (argFiles ++ ["." | null argFiles])
392396
-- LSP works with absolute file paths, so try and behave similarly
393397
absoluteFiles <- nubOrd <$> mapM IO.canonicalizePath files
394398
putStrLn $ "Found " ++ show (length absoluteFiles) ++ " files"
@@ -453,16 +457,45 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
453457
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
454458
c ide
455459

456-
expandFiles :: [FilePath] -> IO [FilePath]
457-
expandFiles = concatMapM $ \x -> do
460+
-- | List the haskell files given some paths
461+
--
462+
-- It will rely on git if possible to filter-out ignored files.
463+
expandFiles :: Recorder (WithPriority Log) -> [FilePath] -> IO [FilePath]
464+
expandFiles recorder paths = do
465+
let haskellFind x =
466+
let recurse "." = True
467+
recurse y | "." `isPrefixOf` takeFileName y = False -- skip .git etc
468+
recurse y = takeFileName y `notElem` ["dist", "dist-newstyle"] -- cabal directories
469+
in filter (\y -> takeExtension y `elem` [".hs", ".lhs"]) <$> IO.listFilesInside (return . recurse) x
470+
git args = do
471+
mResult <- (Just <$> readProcessWithExitCode "git" args "") `Safe.catchAny`const (pure Nothing)
472+
pure $
473+
case mResult of
474+
Just (ExitSuccess, gitStdout, _) -> Just gitStdout
475+
_ -> Nothing
476+
mHasGit <- git ["status"]
477+
when (isJust mHasGit) $ logWith recorder Info LogUsingGit
478+
let findFiles =
479+
case mHasGit of
480+
Just _ -> \path -> do
481+
let lookups =
482+
if takeExtension path `elem` [".hs", ".lhs"]
483+
then [path]
484+
else [path </> "*.hs", path </> "*.lhs"]
485+
gitLines args = fmap lines <$> git args
486+
mTracked <- gitLines ("ls-files":lookups)
487+
mUntracked <- gitLines ("ls-files":"-o":lookups)
488+
case mTracked <> mUntracked of
489+
Nothing -> haskellFind path
490+
Just files -> pure files
491+
_ -> haskellFind
492+
493+
flip concatMapM paths $ \x -> do
458494
b <- IO.doesFileExist x
459495
if b
460496
then return [x]
461497
else do
462-
let recurse "." = True
463-
recurse y | "." `isPrefixOf` takeFileName y = False -- skip .git etc
464-
recurse y = takeFileName y `notElem` ["dist", "dist-newstyle"] -- cabal directories
465-
files <- filter (\y -> takeExtension y `elem` [".hs", ".lhs"]) <$> IO.listFilesInside (return . recurse) x
498+
files <- findFiles x
466499
when (null files) $
467500
fail $ "Couldn't find any .hs/.lhs files inside directory: " ++ x
468501
return files

haskell-language-server.cabal

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,19 @@ flag hlint
709709
manual: True
710710

711711
common hlint
712-
if flag(hlint)
712+
-- Hlint isn't compatible with GHC 9.10, and crashes in subtle ways.
713+
-- See https://github.com/haskell/haskell-language-server/issues/4674
714+
-- for its wake of destruction.
715+
if flag(hlint) && !impl(ghc ==9.10.*)
713716
build-depends: haskell-language-server:hls-hlint-plugin
714717
cpp-options: -Dhls_hlint
715718

716719
library hls-hlint-plugin
717720
import: defaults, pedantic, warnings
718-
-- https://github.com/ndmitchell/hlint/pull/1594
719-
if !flag(hlint)
721+
-- Hlint isn't compatible with GHC 9.10, and crashes in subtle ways.
722+
-- See https://github.com/haskell/haskell-language-server/issues/4674
723+
-- for its wake of destruction.
724+
if !flag(hlint) || impl(ghc ==9.10.*)
720725
buildable: False
721726
exposed-modules: Ide.Plugin.Hlint
722727
hs-source-dirs: plugins/hls-hlint-plugin/src
@@ -763,7 +768,10 @@ library hls-hlint-plugin
763768

764769
test-suite hls-hlint-plugin-tests
765770
import: defaults, pedantic, test-defaults, warnings
766-
if !flag(hlint)
771+
-- Hlint isn't compatible with GHC 9.10, and crashes in subtle ways.
772+
-- See https://github.com/haskell/haskell-language-server/issues/4674
773+
-- for its wake of destruction.
774+
if !flag(hlint) || impl(ghc ==9.10.*)
767775
buildable: False
768776
type: exitcode-stdio-1.0
769777
hs-source-dirs: plugins/hls-hlint-plugin/test

test/testdata/schema/ghc910/default-config.golden.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@
9191
},
9292
"globalOn": true
9393
},
94-
"hlint": {
95-
"codeActionsOn": true,
96-
"config": {
97-
"flags": []
98-
},
99-
"diagnosticsOn": true
100-
},
10194
"importLens": {
10295
"codeActionsOn": true,
10396
"codeLensOn": true,

test/testdata/schema/ghc910/markdown-reference.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
## hlint
2-
| Property | Description | Default | Allowed values |
3-
| --- | --- | --- | --- |
4-
| `flags` | Flags used by hlint | `TODO: Array values` | &nbsp; |
5-
61
## cabal-fmt
72
| Property | Description | Default | Allowed values |
83
| --- | --- | --- | --- |

test/testdata/schema/ghc910/vscode-extension-schema.golden.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,6 @@
213213
"scope": "resource",
214214
"type": "boolean"
215215
},
216-
"haskell.plugin.hlint.codeActionsOn": {
217-
"default": true,
218-
"description": "Enables hlint code actions",
219-
"scope": "resource",
220-
"type": "boolean"
221-
},
222-
"haskell.plugin.hlint.config.flags": {
223-
"default": [],
224-
"markdownDescription": "Flags used by hlint",
225-
"scope": "resource",
226-
"type": "array"
227-
},
228-
"haskell.plugin.hlint.diagnosticsOn": {
229-
"default": true,
230-
"description": "Enables hlint diagnostics",
231-
"scope": "resource",
232-
"type": "boolean"
233-
},
234216
"haskell.plugin.importLens.codeActionsOn": {
235217
"default": true,
236218
"description": "Enables importLens code actions",

0 commit comments

Comments
 (0)