From: Luke Lau Date: Tue, 12 Nov 2019 18:50:23 +0000 (+0000) Subject: Merge pull request #58 from alanz/wip/vfs X-Git-Tag: 0.8.1.0~1 X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=6d352ac93d32f520a36c530bc42c86f05fd449b7;hp=3d53fc1067997390a65614e2a7a6bb14923fe940 Merge pull request #58 from alanz/wip/vfs Match haskell-lsp updates for VFS race condition fixes --- diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 22091c3..a6612e2 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -188,7 +188,7 @@ runSessionWithConfig config serverExe caps rootDir session = do documentContents :: TextDocumentIdentifier -> Session T.Text documentContents doc = do vfs <- vfs <$> get - let file = vfs Map.! toNormalizedUri (doc ^. uri) + let file = vfsMap vfs Map.! toNormalizedUri (doc ^. uri) return $ Rope.toText $ Language.Haskell.LSP.VFS._text file -- | Parses an ApplyEditRequest, checks that it is for the passed document @@ -273,7 +273,7 @@ sendNotification TextDocumentDidOpen params = do n :: DidOpenTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidOpen params' oldVFS <- vfs <$> get - newVFS <- liftIO $ openVFS oldVFS n + let (newVFS,_) = openVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -283,7 +283,7 @@ sendNotification TextDocumentDidClose params = do n :: DidCloseTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidClose params' oldVFS <- vfs <$> get - newVFS <- liftIO $ closeVFS oldVFS n + let (newVFS,_) = closeVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -292,7 +292,7 @@ sendNotification TextDocumentDidChange params = do n :: DidChangeTextDocumentNotification n = NotificationMessage "2.0" TextDocumentDidChange params' oldVFS <- vfs <$> get - newVFS <- liftIO $ changeFromClientVFS oldVFS n + let (newVFS,_) = changeFromClientVFS oldVFS n modify (\s -> s { vfs = newVFS }) sendMessage n @@ -449,10 +449,10 @@ executeCodeAction action = do -- | Adds the current version to the document, as tracked by the session. getVersionedDoc :: TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier getVersionedDoc (TextDocumentIdentifier uri) = do - fs <- vfs <$> get + fs <- vfsMap . vfs <$> get let ver = case fs Map.!? toNormalizedUri uri of - Just (VirtualFile v _ _) -> Just v + Just (VirtualFile v _) -> Just v _ -> Nothing return (VersionedTextDocumentIdentifier uri ver) diff --git a/src/Language/Haskell/LSP/Test/Session.hs b/src/Language/Haskell/LSP/Test/Session.hs index b8dbe2a..67e4ae6 100644 --- a/src/Language/Haskell/LSP/Test/Session.hs +++ b/src/Language/Haskell/LSP/Test/Session.hs @@ -220,8 +220,9 @@ runSessionWithHandles serverIn serverOut serverProc serverHandler config caps ro mainThreadId <- myThreadId let context = SessionContext serverIn absRootDir messageChan reqMap initRsp config caps - initState = SessionState (IdInt 0) mempty mempty 0 False Nothing - runSession' = runSession context initState + initState vfs = SessionState (IdInt 0) vfs + mempty 0 False Nothing + runSession' ses = initVFS $ \vfs -> runSession context (initState vfs) ses errorHandler = throwTo mainThreadId :: SessionException -> IO() serverListenerLauncher = @@ -280,8 +281,8 @@ updateState (ReqApplyWorkspaceEdit r) = do forM_ bumpedVersions $ \(VersionedTextDocumentIdentifier uri v) -> modify $ \s -> let oldVFS = vfs s - update (VirtualFile oldV t mf) = VirtualFile (fromMaybe oldV v) t mf - newVFS = Map.adjust update (toNormalizedUri uri) oldVFS + update (VirtualFile oldV t) = VirtualFile (fromMaybe oldV v) t + newVFS = updateVFS (Map.adjust update (toNormalizedUri uri)) oldVFS in s { vfs = newVFS } where checkIfNeedsOpened uri = do @@ -289,7 +290,7 @@ updateState (ReqApplyWorkspaceEdit r) = do ctx <- ask -- if its not open, open it - unless (toNormalizedUri uri `Map.member` oldVFS) $ do + unless (toNormalizedUri uri `Map.member` (vfsMap oldVFS)) $ do let fp = fromJust $ uriToFilePath uri contents <- liftIO $ T.readFile fp let item = TextDocumentItem (filePathToUri fp) "" 0 contents @@ -297,7 +298,7 @@ updateState (ReqApplyWorkspaceEdit r) = do liftIO $ B.hPut (serverIn ctx) $ addHeader (encode msg) modifyM $ \s -> do - newVFS <- liftIO $ openVFS (vfs s) msg + let (newVFS,_) = openVFS (vfs s) msg return $ s { vfs = newVFS } getParams (TextDocumentEdit docId (List edits)) =