Skip to content

Commit 2baa0c9

Browse files
committed
fix hls
1 parent 543b270 commit 2baa0c9

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,16 @@ runLanguageServer recorder options inH outH defaultConfig parseConfig onConfigCh
125125

126126
setupLSP ::
127127
forall config err.
128-
Recorder (WithPriority Log)
128+
FilePath -- ^ root directory
129+
-> Recorder (WithPriority Log)
129130
-> (FilePath -> IO FilePath) -- ^ Map root paths to the location of the hiedb for the project
130131
-> LSP.Handlers (ServerM config)
131132
-> (LSP.LanguageContextEnv config -> FilePath -> WithHieDb -> IndexQueue -> IO IdeState)
132133
-> MVar ()
133134
-> IO (LSP.LanguageContextEnv config -> TRequestMessage Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState)),
134135
LSP.Handlers (ServerM config),
135136
(LanguageContextEnv config, IdeState) -> ServerM config <~> IO)
136-
setupLSP recorder getHieDbLoc userHandlers getIdeState clientMsgVar = do
137+
setupLSP root recorder getHieDbLoc userHandlers getIdeState clientMsgVar = do
137138
-- Send everything over a channel, since you need to wait until after initialise before
138139
-- LspFuncs is available
139140
clientMsgChan :: Chan ReactorMessage <- newChan
@@ -176,15 +177,16 @@ setupLSP recorder getHieDbLoc userHandlers getIdeState clientMsgVar = do
176177
-- Cancel requests are special since they need to be handled
177178
-- out of order to be useful. Existing handlers are run afterwards.
178179

179-
let doInitialize = handleInit recorder getHieDbLoc getIdeState reactorLifetime exit clearReqId waitForCancel clientMsgChan
180+
let doInitialize = handleInit root recorder getHieDbLoc getIdeState reactorLifetime exit clearReqId waitForCancel clientMsgChan
180181

181182
let interpretHandler (env, st) = LSP.Iso (LSP.runLspT env . flip (runReaderT . unServerM) (clientMsgChan,st)) liftIO
182183

183184
pure (doInitialize, asyncHandlers, interpretHandler)
184185

185186

186187
handleInit
187-
:: Recorder (WithPriority Log)
188+
:: FilePath
189+
-> Recorder (WithPriority Log)
188190
-> (FilePath -> IO FilePath)
189191
-> (LSP.LanguageContextEnv config -> FilePath -> WithHieDb -> IndexQueue -> IO IdeState)
190192
-> MVar ()
@@ -193,11 +195,9 @@ handleInit
193195
-> (SomeLspId -> IO ())
194196
-> Chan ReactorMessage
195197
-> LSP.LanguageContextEnv config -> TRequestMessage Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState))
196-
handleInit recorder getHieDbLoc getIdeState lifetime exitClientMsg clearReqId waitForCancel clientMsgChan env (TRequestMessage _ _ m params) = otTracedHandler "Initialize" (show m) $ \sp -> do
198+
handleInit rootDir recorder getHieDbLoc getIdeState lifetime exitClientMsg clearReqId waitForCancel clientMsgChan env (TRequestMessage _ _ m params) = otTracedHandler "Initialize" (show m) $ \sp -> do
197199
traceWithSpan sp params
198-
let root = LSP.resRootPath env
199-
dir <- maybe (error "No root directory") pure root
200-
dbLoc <- getHieDbLoc dir
200+
dbLoc <- getHieDbLoc rootDir
201201
let initConfig = parseConfiguration params
202202
logWith recorder Info $ LogRegisteringIdeConfig initConfig
203203
dbMVar <- newEmptyMVar
@@ -240,7 +240,7 @@ handleInit recorder getHieDbLoc getIdeState lifetime exitClientMsg clearReqId wa
240240
logWith recorder Info LogReactorThreadStopped
241241

242242
(WithHieDbShield withHieDb,hieChan) <- takeMVar dbMVar
243-
ide <- getIdeState env dir withHieDb hieChan
243+
ide <- getIdeState env rootDir withHieDb hieChan
244244
registerIdeConfiguration (shakeExtras ide) initConfig
245245
pure $ Right (env,ide)
246246

ghcide/src/Development/IDE/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
357357
putMVar ideStateVar ide
358358
pure ide
359359

360-
let setup = setupLSP (cmapWithPrio LogLanguageServer recorder) argsGetHieDbLoc (pluginHandlers plugins) getIdeState
360+
let setup = setupLSP argsProjectRoot (cmapWithPrio LogLanguageServer recorder) argsGetHieDbLoc (pluginHandlers plugins) getIdeState
361361
-- See Note [Client configuration in Rules]
362362
onConfigChange cfg = do
363363
-- TODO: this is nuts, we're converting back to JSON just to get a fingerprint

hls-test-utils/src/Test/Hls.hs

+29-27
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,33 @@ runSessionWithServerInTmpDir' ::
415415
Session a -> IO a
416416
runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = runSessionWithServerInTmpDirCont False plugins conf sessConf caps tree (const act)
417417

418+
runWithLockInTempDir :: VirtualFileTree -> (FileSystem -> IO a) -> IO a
419+
runWithLockInTempDir tree act = withLock lockForTempDirs $ do
420+
testRoot <- setupTestEnvironment
421+
helperRecorder <- hlsHelperTestRecorder
422+
-- Do not clean up the temporary directory if this variable is set to anything but '0'.
423+
-- Aids debugging.
424+
cleanupTempDir <- lookupEnv "HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
425+
let runTestInDir action = case cleanupTempDir of
426+
Just val | val /= "0" -> do
427+
(tempDir, _) <- newTempDirWithin testRoot
428+
a <- action tempDir
429+
logWith helperRecorder Debug LogNoCleanup
430+
pure a
431+
432+
_ -> do
433+
(tempDir, cleanup) <- newTempDirWithin testRoot
434+
a <- action tempDir `finally` cleanup
435+
logWith helperRecorder Debug LogCleanup
436+
pure a
437+
runTestInDir $ \tmpDir' -> do
438+
-- we canonicalize the path, so that we do not need to do
439+
-- cannibalization during the test when we compare two paths
440+
tmpDir <- canonicalizePath tmpDir'
441+
logWith helperRecorder Info $ LogTestDir tmpDir
442+
fs <- FS.materialiseVFT tmpDir tree
443+
act fs
444+
418445
-- | Host a server, and run a test session on it.
419446
--
420447
-- Creates a temporary directory, and materializes the VirtualFileTree
@@ -449,33 +476,8 @@ runSessionWithServerInTmpDirCont ::
449476
ClientCapabilities ->
450477
VirtualFileTree ->
451478
(FileSystem -> Session a) -> IO a
452-
runSessionWithServerInTmpDirCont disableKick plugins conf sessConf caps tree act = withLock lockForTempDirs $ do
453-
testRoot <- setupTestEnvironment
454-
helperRecorder <- hlsHelperTestRecorder
455-
456-
-- Do not clean up the temporary directory if this variable is set to anything but '0'.
457-
-- Aids debugging.
458-
cleanupTempDir <- lookupEnv "HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
459-
let runTestInDir action = case cleanupTempDir of
460-
Just val | val /= "0" -> do
461-
(tempDir, _) <- newTempDirWithin testRoot
462-
a <- action tempDir
463-
logWith helperRecorder Debug LogNoCleanup
464-
pure a
465-
466-
_ -> do
467-
(tempDir, cleanup) <- newTempDirWithin testRoot
468-
a <- action tempDir `finally` cleanup
469-
logWith helperRecorder Debug LogCleanup
470-
pure a
471-
472-
runTestInDir $ \tmpDir' -> do
473-
-- we canonicalize the path, so that we do not need to do
474-
-- cannibalization during the test when we compare two paths
475-
tmpDir <- canonicalizePath tmpDir'
476-
logWith helperRecorder Info $ LogTestDir tmpDir
477-
fs <- FS.materialiseVFT tmpDir tree
478-
runSessionWithServer' disableKick plugins conf sessConf caps tmpDir (act fs)
479+
runSessionWithServerInTmpDirCont disableKick plugins conf sessConf caps tree act =
480+
runWithLockInTempDir tree $ \fs -> runSessionWithServer' disableKick plugins conf sessConf caps (fsRoot fs) (act fs)
479481

480482
runSessionWithServer :: Pretty b => Config -> PluginTestDescriptor b -> FilePath -> Session a -> IO a
481483
runSessionWithServer config plugin fp act = do

plugins/hls-splice-plugin/test/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ goldenTestWithEdit fp expect tc line col =
8989
}
9090
waitForAllProgressDone -- cradle
9191
waitForAllProgressDone
92-
alt <- liftIO $ T.readFile (fp <.> "error.hs")
92+
alt <- liftIO $ T.readFile (testDataDir </> fp <.> "error.hs")
9393
void $ applyEdit doc $ TextEdit theRange alt
9494
changeDoc doc [TextDocumentContentChangeEvent $ InL
9595
TextDocumentContentChangePartial {_range = theRange, _rangeLength = Nothing, _text = alt}

0 commit comments

Comments
 (0)