@@ -63,6 +63,7 @@ main = defaultMain $ testGroup "HIE"
63 , unitTests
63 , unitTests
64 , haddockTests
64 , haddockTests
65 , positionMappingTests
65 , positionMappingTests
68initializeResponseTests :: TestTree
69initializeResponseTests :: TestTree
@@ -99,7 +100,7 @@ initializeResponseTests = withResource acquire release tests where
99 , chk "NO color" _colorProvider (Just $ ColorOptionsStatic False)
100 , chk "NO color" _colorProvider (Just $ ColorOptionsStatic False)
100 , chk "NO folding range" _foldingRangeProvider (Just $ FoldingRangeOptionsStatic False)
101 , chk "NO folding range" _foldingRangeProvider (Just $ FoldingRangeOptionsStatic False)
101 , chk " execute command" _executeCommandProvider (Just $ ExecuteCommandOptions $ List ["typesignature.add"])
102 , 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 )}))
103 , chk "NO experimental" _experimental Nothing
104 , chk "NO experimental" _experimental Nothing
@@ -110,8 +111,6 @@ initializeResponseTests = withResource acquire release tests where
110 , _willSaveWaitUntil = Nothing
111 , _willSaveWaitUntil = Nothing
111 , _save = Just (SaveOptions {_includeText = Nothing})}))
112 , _save = Just (SaveOptions {_includeText = Nothing})}))
113− nothingWorkspace = Just (WorkspaceOptions {_workspaceFolders = Nothing})
115 chk :: (Eq a, Show a) => TestName -> (InitializeResponseCapabilitiesInner -> a) -> a -> TestTree
114 chk :: (Eq a, Show a) => TestName -> (InitializeResponseCapabilitiesInner -> a) -> a -> TestTree
116 chk title getActual expected =
115 chk title getActual expected =
117 testCase title $ getInitializeResponse >>= \ir -> expected @=? (getActual . innerCaps) ir
116 testCase title $ getInitializeResponse >>= \ir -> expected @=? (getActual . innerCaps) ir
@@ -243,6 +242,16 @@ diagnosticTests = testGroup "diagnostics"
243 let contentA = T.unlines [ "module ModuleA where" ]
242 let contentA = T.unlines [ "module ModuleA where" ]
244 _ <- openDoc' "ModuleA.hs" "haskell" contentA
243 _ <- openDoc' "ModuleA.hs" "haskell" contentA
245 expectDiagnostics [("ModuleB.hs", [])]
244 expectDiagnostics [("ModuleB.hs", [])]
245+ , testSessionWait "add missing module (non workspace)" $ do
246+ let contentB = T.unlines
247+ [ "module ModuleB where"
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", [])]
246 , testSessionWait "cyclic module dependency" $ do
255 , testSessionWait "cyclic module dependency" $ do
247 let contentA = T.unlines
256 let contentA = T.unlines
248 [ "module ModuleA where"
257 [ "module ModuleA where"
@@ -415,6 +424,26 @@ codeLensesTests = testGroup "code lenses"
415 [ addSigLensesTests
424 [ addSigLensesTests
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 =
440+ | Just (RequestMessage{_params = RegistrationParams (List regs)}) <- msgs
441+ , Registration _id WorkspaceDidChangeWatchedFiles args <- regs
443+ liftIO $ watchedFileRegs @?= []
444+ -- TODO add a test for didChangeWorkspaceFolder
418renameActionTests :: TestTree
447renameActionTests :: TestTree
419renameActionTests = testGroup "rename actions"
448renameActionTests = testGroup "rename actions"
420 [ testSession "change to local variable name" $ do
449 [ testSession "change to local variable name" $ do
@@ -1812,9 +1841,16 @@ unitTests = do
1812openDoc' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier
1841openDoc' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier
1813openDoc' fp name contents = do
1842openDoc' fp name contents = do
1814 res@(TextDocumentIdentifier uri) <- LSPTest.openDoc' fp name contents
1843 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
1815 sendNotification WorkspaceDidChangeWatchedFiles (DidChangeWatchedFilesParams $ List [FileEvent uri FcCreated])
1845 sendNotification WorkspaceDidChangeWatchedFiles (DidChangeWatchedFilesParams $ List [FileEvent uri FcCreated])
1816 return res
1846 return res
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'
1818positionMappingTests :: TestTree
1854positionMappingTests :: TestTree
1819positionMappingTests =
1855positionMappingTests =
1820 testGroup "position mapping"
1856 testGroup "position mapping"