@@ -63,6 +63,7 @@ main = defaultMain $ testGroup "HIE"
6363 , unitTests
6464 , haddockTests
6565 , positionMappingTests
66+ , watchedFilesTests
6667 ]
6768
6869initializeResponseTests :: TestTree
@@ -99,7 +100,7 @@ initializeResponseTests = withResource acquire release tests where
99100 , chk "NO color" _colorProvider (Just $ ColorOptionsStatic False)
100101 , chk "NO folding range" _foldingRangeProvider (Just $ FoldingRangeOptionsStatic False)
101102 , chk " execute command" _executeCommandProvider (Just $ ExecuteCommandOptions $ List ["typesignature.add"])
102− , chk "NO workspace" _workspace nothingWorkspace
103+ , chk " workspace" _workspace (Just $ WorkspaceOptions (Just WorkspaceFolderOptions{_supported = Just True, _changeNotifications = Just ( WorkspaceFolderChangeNotificationsBool True )}))
103104 , chk "NO experimental" _experimental Nothing
104105 ] where
105106
@@ -110,8 +111,6 @@ initializeResponseTests = withResource acquire release tests where
110111 , _willSaveWaitUntil = Nothing
111112 , _save = Just (SaveOptions {_includeText = Nothing})}))
112113
113− nothingWorkspace = Just (WorkspaceOptions {_workspaceFolders = Nothing})
114−
115114 chk :: (Eq a, Show a) => TestName -> (InitializeResponseCapabilitiesInner -> a) -> a -> TestTree
116115 chk title getActual expected =
117116 testCase title $ getInitializeResponse >>= \ir -> expected @=? (getActual . innerCaps) ir
@@ -243,6 +242,16 @@ diagnosticTests = testGroup "diagnostics"
243242 let contentA = T.unlines [ "module ModuleA where" ]
244243 _ <- openDoc' "ModuleA.hs" "haskell" contentA
245244 expectDiagnostics [("ModuleB.hs", [])]
245+ , testSessionWait "add missing module (non workspace)" $ do
246+ let contentB = T.unlines
247+ [ "module ModuleB where"
248+ , "import ModuleA"
249+ ]
250+ _ <- openDoc'' "/tmp/ModuleB.hs" "haskell" contentB
251+ expectDiagnostics [("/tmp/ModuleB.hs", [(DsError, (1, 7), "Could not find module")])]
252+ let contentA = T.unlines [ "module ModuleA where" ]
253+ _ <- openDoc'' "/tmp/ModuleA.hs" "haskell" contentA
254+ expectDiagnostics [("/tmp/ModuleB.hs", [])]
246255 , testSessionWait "cyclic module dependency" $ do
247256 let contentA = T.unlines
248257 [ "module ModuleA where"
@@ -415,6 +424,26 @@ codeLensesTests = testGroup "code lenses"
415424 [ addSigLensesTests
416425 ]
417426
427+watchedFilesTests :: TestTree
428+watchedFilesTests = testGroup "watched files"
429+ [ testSession "workspace file" $ do
430+ _ <- openDoc' "A.hs" "haskell" "module A where"
431+ RequestMessage{_params = RegistrationParams (List regs)} <- skipManyTill anyMessage (message @RegisterCapabilityRequest)
432+ let watchedFileRegs =
433+ [ args | Registration _id WorkspaceDidChangeWatchedFiles args <- regs ]
434+ liftIO $ assertBool "watches workspace files" $ not $ null watchedFileRegs
435+ , testSession "non workspace file" $ do
436+ _ <- openDoc' "/tmp/A.hs" "haskell" "module A where"
437+ msgs <- manyTill (Just <$> message @RegisterCapabilityRequest <|> Nothing <$ anyMessage) (message @WorkDoneProgressEndNotification)
438+ let watchedFileRegs =
439+ [ args
440+ | Just (RequestMessage{_params = RegistrationParams (List regs)}) <- msgs
441+ , Registration _id WorkspaceDidChangeWatchedFiles args <- regs
442+ ]
443+ liftIO $ watchedFileRegs @?= []
444+ -- TODO add a test for didChangeWorkspaceFolder
445+ ]
446+
418447renameActionTests :: TestTree
419448renameActionTests = testGroup "rename actions"
420449 [ testSession "change to local variable name" $ do
@@ -1812,9 +1841,16 @@ unitTests = do
18121841openDoc' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier
18131842openDoc' fp name contents = do
18141843 res@(TextDocumentIdentifier uri) <- LSPTest.openDoc' fp name contents
1844+ -- Needed as ghcide sets up and relies on WatchedFiles but lsp-test does not track them
18151845 sendNotification WorkspaceDidChangeWatchedFiles (DidChangeWatchedFilesParams $ List [FileEvent uri FcCreated])
18161846 return res
18171847
1848+-- | Version of 'LSPTest.openDoc'' that does not send WatchedFiles events for files outside the workspace
1849+openDoc'' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier
1850+-- At the moment this is just LSPTest.openDoc' but it may change in the future
1851+-- when/if lsp-test implements WatchedFiles
1852+openDoc'' = LSPTest.openDoc'
1853+
18181854positionMappingTests :: TestTree
18191855positionMappingTests =
18201856 testGroup "position mapping"