@@ -23,6 +23,7 @@ module Language.LSP.VFS (
2323 file_text ,
2424 virtualFileText ,
2525 virtualFileVersion ,
26+ virtualFileLanguageKind ,
2627 VfsLog (.. ),
2728
2829 -- * Managing the VFS
@@ -92,6 +93,12 @@ data VirtualFile = VirtualFile
9293 -- remains in the map.
9394 , _file_text :: ! Rope
9495 -- ^ The full contents of the document
96+ , _language_id :: ! (Maybe J. LanguageKind )
97+ -- ^ The text document's language identifier
98+ -- This is a Maybe, since when we use the VFS as a client
99+ -- we don't have this information, since server sends WorkspaceEdit
100+ -- notifications without a language kind.
101+ -- When using the VFS in a server, this should always be Just.
95102 }
96103 deriving (Show )
97104
@@ -132,6 +139,9 @@ virtualFileText vf = Rope.toText (_file_text vf)
132139virtualFileVersion :: VirtualFile -> Int32
133140virtualFileVersion vf = _lsp_version vf
134141
142+ virtualFileLanguageKind :: VirtualFile -> Maybe J. LanguageKind
143+ virtualFileLanguageKind vf = _language_id vf
144+
135145---
136146
137147emptyVFS :: VFS
@@ -142,8 +152,8 @@ emptyVFS = VFS mempty
142152-- | Applies the changes from a 'J.DidOpenTextDocument' to the 'VFS'
143153openVFS :: (MonadState VFS m ) => LogAction m (WithSeverity VfsLog ) -> J. TMessage 'J.Method_TextDocumentDidOpen -> m ()
144154openVFS logger msg = do
145- let J. TextDocumentItem (J. toNormalizedUri -> uri) _ version text = msg ^. J. params . J. textDocument
146- vfile = VirtualFile version 0 (Rope. fromText text)
155+ let J. TextDocumentItem (J. toNormalizedUri -> uri) languageId version text = msg ^. J. params . J. textDocument
156+ vfile = VirtualFile version 0 (Rope. fromText text) ( Just languageId)
147157 logger <& Opening uri `WithSeverity ` Debug
148158 vfsMap . at uri .= Just vfile
149159
@@ -158,9 +168,9 @@ changeFromClientVFS logger msg = do
158168 J. VersionedTextDocumentIdentifier (J. toNormalizedUri -> uri) version = vid
159169 vfs <- get
160170 case vfs ^. vfsMap . at uri of
161- Just (VirtualFile _ file_ver contents) -> do
171+ Just (VirtualFile _ file_ver contents kind ) -> do
162172 contents' <- applyChanges logger contents changes
163- vfsMap . at uri .= Just (VirtualFile version (file_ver + 1 ) contents')
173+ vfsMap . at uri .= Just (VirtualFile version (file_ver + 1 ) contents' kind )
164174 Nothing -> logger <& URINotFound uri `WithSeverity ` Warning
165175
166176-- ---------------------------------------------------------------------
@@ -171,7 +181,7 @@ applyCreateFile (J.CreateFile _ann _kind (J.toNormalizedUri -> uri) options) =
171181 %= Map. insertWith
172182 (\ new old -> if shouldOverwrite then new else old)
173183 uri
174- (VirtualFile 0 0 mempty )
184+ (VirtualFile 0 0 mempty Nothing )
175185 where
176186 shouldOverwrite :: Bool
177187 shouldOverwrite = case options of
@@ -281,7 +291,7 @@ changeFromServerVFS logger msg = do
281291
282292-- ---------------------------------------------------------------------
283293virtualFileName :: FilePath -> J. NormalizedUri -> VirtualFile -> FilePath
284- virtualFileName prefix uri (VirtualFile _ file_ver _) =
294+ virtualFileName prefix uri (VirtualFile _ file_ver _ _ ) =
285295 let uri_raw = J. fromNormalizedUri uri
286296 basename = maybe " " takeFileName (J. uriToFilePath uri_raw)
287297 -- Given a length and a version number, pad the version number to
@@ -463,7 +473,7 @@ rangeToCodePointRange vFile (J.Range b e) =
463473 CodePointRange <$> positionToCodePointPosition vFile b <*> positionToCodePointPosition vFile e
464474
465475rangeLinesFromVfs :: VirtualFile -> J. Range -> T. Text
466- rangeLinesFromVfs (VirtualFile _ _ ropetext) (J. Range (J. Position lf _cf) (J. Position lt _ct)) = r
476+ rangeLinesFromVfs (VirtualFile _ _ ropetext _ ) (J. Range (J. Position lf _cf) (J. Position lt _ct)) = r
467477 where
468478 (_, s1) = Rope. splitAtLine (fromIntegral lf) ropetext
469479 (s2, _) = Rope. splitAtLine (fromIntegral (lt - lf)) s1
0 commit comments