Skip to content

Commit 8e95471

Browse files
authored
Merge branch 'master' into optionalProgressReporting
2 parents 5e9ec29 + 6fbc602 commit 8e95471

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+515
-200
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,9 @@ jobs:
135135
if: ${{ matrix.test }}
136136
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"
137137

138+
- name: Test brittany plugin
139+
if: ${{ matrix.test }}
140+
env:
141+
HLS_TEST_EXE: hls
142+
HLS_WRAPPER_TEST_EXE: hls-wrapper
143+
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ For example, `haskell-language-server` allows you to choose the formatting provi
301301
This option obviously would not make sense for language servers for other languages, or even for other Haskell language servers (which need not even support formatting).
302302

303303
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:
304-
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, `stylish-haskell`, or `brittany` (if compiled with AGPL)
304+
- Formatting provider (`haskell.formattingProvider`, default `ormolu`): what formatter to use; one of `floskell`, `ormolu`, `fourmolu`, `stylish-haskell`, or `brittany` (if compiled with the brittany plugin)
305305
- Format on imports (`haskell.formatOnImportOn`, default true): whether to format after adding an import
306306
- Maximum number of problems to report (`haskell.maxNumberOfProblems`, default 100): the maximum number of problems the server will send to the client
307307
- Diagnostics on change (`haskell.diagnosticsOnChange`, default true): (currently unused)
@@ -648,7 +648,7 @@ This issue should be fixed in Stack versions >= 2.5.
648648
#### Problems with dynamic linking
649649

650650
As haskell-language-server prebuilt binaries are statically linked, they don't play well with projects using dynamic linking.
651-
An usual symptom is the presence of errors containing `unknown symbol` and it is typical in arch linux, where a dynamically linked version of ghc is used.
651+
An usual symptom is the presence of errors containing `unknown symbol` and it is typical in arch linux, where a dynamically linked version of ghc is used.
652652

653653
The workaround is to use a version of haskell-language-server compiled from source with `-dynamic` enabled`. See more details [here](https://github.com/haskell/haskell-language-server/issues/1160#issuecomment-756566273).
654654

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ packages:
55
./ghcide
66
./hls-plugin-api
77
./plugins/hls-tactics-plugin
8+
./plugins/hls-brittany-plugin
89
./plugins/hls-class-plugin
910
./plugins/hls-eval-plugin
1011
./plugins/hls-explicit-imports-plugin

docs/plugin-tutorial.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ idePlugins = pluginDescToIdePlugins allPlugins
9696
, Ormolu.descriptor "ormolu"
9797
, StylishHaskell.descriptor "stylish-haskell"
9898
, Retrie.descriptor "retrie"
99-
#if AGPL
10099
, Brittany.descriptor "brittany"
101-
#endif
102100
, Eval.descriptor "eval"
103101
]
104102
```

exe/Plugins.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Ide.Plugin.Ormolu as Ormolu
7171
import Ide.Plugin.StylishHaskell as StylishHaskell
7272
#endif
7373

74-
#if AGPL && brittany
74+
#if brittany
7575
import Ide.Plugin.Brittany as Brittany
7676
#endif
7777

ghcide/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ main = do
8888
Typecheck x | not argLSP -> Just x
8989
_ -> Nothing
9090

91-
,Main.argsLogger = logger
91+
,Main.argsLogger = pure logger
9292

9393
,Main.argsRules = do
9494
-- install the main and ghcide-plugin rules

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cabal-version: 2.2
22
build-type: Simple
33
category: Development
44
name: ghcide
5-
version: 1.0.0.0
5+
version: 1.1.0.0
66
license: Apache-2.0
77
license-file: LICENSE
88
author: Digital Asset and Ghcide contributors

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
395395
lfp <- flip makeRelative cfp <$> getCurrentDirectory
396396
logInfo logger $ T.pack ("Consulting the cradle for " <> show lfp)
397397

398-
when (isNothing hieYaml) $ mRunLspT lspEnv $
399-
sendNotification SWindowShowMessage $ notifyUserImplicitCradle lfp
398+
when (isNothing hieYaml) $
399+
logWarning logger $ implicitCradleWarning lfp
400400

401401
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
402402

@@ -820,8 +820,8 @@ getCacheDirsDefault prefix opts = do
820820
cacheDir :: String
821821
cacheDir = "ghcide"
822822

823-
notifyUserImplicitCradle:: FilePath -> ShowMessageParams
824-
notifyUserImplicitCradle fp =ShowMessageParams MtWarning $
823+
implicitCradleWarning :: FilePath -> T.Text
824+
implicitCradleWarning fp =
825825
"No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for "
826826
<> T.pack fp <>
827827
".\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).\n"<>

ghcide/src/Development/IDE/Core/FileExists.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ modifyFileExists state changes = do
101101
modifyVar_ var $ evaluate . HashMap.union changesMap
102102
-- See Note [Invalidating file existence results]
103103
-- flush previous values
104-
mapM_ (deleteValue state GetFileExists) (HashMap.keys changesMap)
104+
mapM_ (deleteValue (shakeExtras state) GetFileExists) (HashMap.keys changesMap)
105105

106106
fromChange :: FileChangeType -> Maybe Bool
107107
fromChange FcCreated = Just True

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module Development.IDE.Core.FileStore(
1515
makeVFSHandle,
1616
makeLSPVFSHandle,
1717
isFileOfInterestRule
18-
,resetFileStore) where
18+
,resetFileStore
19+
,resetInterfaceStore
20+
) where
1921

2022
import Control.Concurrent.Extra
2123
import Control.Concurrent.STM (atomically)
@@ -67,6 +69,7 @@ import Language.LSP.Types (FileChangeType (F
6769
FileEvent (FileEvent),
6870
uriToFilePath, toNormalizedFilePath)
6971
import Language.LSP.VFS
72+
import System.FilePath
7073

7174
makeVFSHandle :: IO VFSHandle
7275
makeVFSHandle = do
@@ -111,7 +114,7 @@ getModificationTimeRule vfs isWatched =
111114
pure (Just $ BS.pack $ show ver, ([], Just $ VFSVersion ver))
112115
Nothing -> do
113116
isWF <- isWatched file
114-
unless isWF alwaysRerun
117+
unless (isWF || isInterface file) alwaysRerun
115118
liftIO $ fmap wrap (getModTime file')
116119
`catch` \(e :: IOException) -> do
117120
let err | isDoesNotExistError e = "File does not exist: " ++ file'
@@ -121,6 +124,18 @@ getModificationTimeRule vfs isWatched =
121124
then return (Nothing, ([], Nothing))
122125
else return (Nothing, ([diag], Nothing))
123126

127+
-- | Interface files cannot be watched, since they live outside the workspace.
128+
-- But interface files are private, in that only HLS writes them.
129+
-- So we implement watching ourselves, and bypass the need for alwaysRerun.
130+
isInterface :: NormalizedFilePath -> Bool
131+
isInterface f = takeExtension (fromNormalizedFilePath f) `elem` [".hi", ".hi-boot"]
132+
133+
-- | Reset the GetModificationTime state of interface files
134+
resetInterfaceStore :: ShakeExtras -> NormalizedFilePath -> IO ()
135+
resetInterfaceStore state f = do
136+
deleteValue state (GetModificationTime_ True) f
137+
deleteValue state (GetModificationTime_ False) f
138+
124139
-- | Reset the GetModificationTime state of watched files
125140
resetFileStore :: IdeState -> [FileEvent] -> IO ()
126141
resetFileStore ideState changes = mask $ \_ ->
@@ -134,8 +149,8 @@ resetFileStore ideState changes = mask $ \_ ->
134149
OfInterestVar foisVar <- getIdeGlobalExtras (shakeExtras ideState)
135150
fois <- readVar foisVar
136151
unless (HM.member (toNormalizedFilePath f) fois) $ do
137-
deleteValue ideState (GetModificationTime_ True) (toNormalizedFilePath' f)
138-
deleteValue ideState (GetModificationTime_ False) (toNormalizedFilePath' f)
152+
deleteValue (shakeExtras ideState) (GetModificationTime_ True) (toNormalizedFilePath' f)
153+
deleteValue (shakeExtras ideState) (GetModificationTime_ False) (toNormalizedFilePath' f)
139154
_ -> pure ()
140155

141156
-- Dir.getModificationTime is surprisingly slow since it performs

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import Data.Tuple.Extra
8686
import Development.IDE.Core.Compile
8787
import Development.IDE.Core.FileExists
8888
import Development.IDE.Core.FileStore (getFileContents,
89-
modificationTime)
89+
modificationTime, resetInterfaceStore)
9090
import Development.IDE.Core.OfInterest
9191
import Development.IDE.Core.PositionMapping
9292
import Development.IDE.Core.RuleTypes
@@ -922,7 +922,7 @@ getModIfaceRule = defineEarlyCutoff $ \GetModIface f -> do
922922
hiDiags <- case hiFile of
923923
Just hiFile
924924
| OnDisk <- status
925-
, not (tmrDeferedError tmr) -> liftIO $ writeHiFile hsc hiFile
925+
, not (tmrDeferedError tmr) -> writeHiFileAction hsc hiFile
926926
_ -> pure []
927927
return (fp, (diags++hiDiags, hiFile))
928928
NotFOI -> do
@@ -991,7 +991,7 @@ regenerateHiFile sess f ms compNeeded = do
991991
-- We don't write the `.hi` file if there are defered errors, since we won't get
992992
-- accurate diagnostics next time if we do
993993
hiDiags <- if not $ tmrDeferedError tmr
994-
then liftIO $ writeHiFile hsc hiFile
994+
then writeHiFileAction hsc hiFile
995995
else pure []
996996

997997
pure (hiDiags <> gDiags <> concat wDiags)
@@ -1090,6 +1090,14 @@ needsCompilationRule = defineEarlyCutoff $ \NeedsCompilation file -> do
10901090
newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (ModuleEnv UTCTime) }
10911091
instance IsIdeGlobal CompiledLinkables
10921092

1093+
writeHiFileAction :: HscEnv -> HiFileResult -> Action [FileDiagnostic]
1094+
writeHiFileAction hsc hiFile = do
1095+
extras <- getShakeExtras
1096+
let targetPath = ml_hi_file $ ms_location $ hirModSummary hiFile
1097+
liftIO $ do
1098+
resetInterfaceStore extras $ toNormalizedFilePath' targetPath
1099+
writeHiFile hsc hiFile
1100+
10931101
-- | A rule that wires per-file rules together
10941102
mainRule :: Rules ()
10951103
mainRule = do

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ setValues state key file val diags = modifyVar_ state $ \vals -> do
420420
-- | Delete the value stored for a given ide build key
421421
deleteValue
422422
:: (Typeable k, Hashable k, Eq k, Show k)
423-
=> IdeState
423+
=> ShakeExtras
424424
-> k
425425
-> NormalizedFilePath
426426
-> IO ()
427-
deleteValue IdeState{shakeExtras = ShakeExtras{state}} key file = modifyVar_ state $ \vals ->
427+
deleteValue ShakeExtras{state} key file = modifyVar_ state $ \vals ->
428428
evaluate $ HMap.delete (file, Key key) vals
429429

430430
-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.

ghcide/src/Development/IDE/LSP/LanguageServer.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ cancelHandler cancelRequest = LSP.notificationHandler SCancelRequest $ \Notifica
200200
liftIO $ cancelRequest (SomeLspId _id)
201201

202202
exitHandler :: IO () -> LSP.Handlers (ServerM c)
203-
exitHandler exit = LSP.notificationHandler SExit (const $ liftIO exit)
203+
exitHandler exit = LSP.notificationHandler SExit $ const $ do
204+
(_, ide) <- ask
205+
-- flush out the Shake session to record a Shake profile if applicable
206+
liftIO $ restartShakeSession (shakeExtras ide) []
207+
liftIO exit
204208

205209
modifyOptions :: LSP.Options -> LSP.Options
206210
modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS

0 commit comments

Comments
 (0)