@@ -23,6 +23,7 @@ module Language.LSP.VFS (
23
23
file_text ,
24
24
virtualFileText ,
25
25
virtualFileVersion ,
26
+ virtualFileLanguageKind ,
26
27
VfsLog (.. ),
27
28
28
29
-- * Managing the VFS
@@ -92,6 +93,12 @@ data VirtualFile = VirtualFile
92
93
-- remains in the map.
93
94
, _file_text :: ! Rope
94
95
-- ^ 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.
95
102
}
96
103
deriving (Show )
97
104
@@ -132,6 +139,9 @@ virtualFileText vf = Rope.toText (_file_text vf)
132
139
virtualFileVersion :: VirtualFile -> Int32
133
140
virtualFileVersion vf = _lsp_version vf
134
141
142
+ virtualFileLanguageKind :: VirtualFile -> Maybe J. LanguageKind
143
+ virtualFileLanguageKind vf = _language_id vf
144
+
135
145
---
136
146
137
147
emptyVFS :: VFS
@@ -142,8 +152,8 @@ emptyVFS = VFS mempty
142
152
-- | Applies the changes from a 'J.DidOpenTextDocument' to the 'VFS'
143
153
openVFS :: (MonadState VFS m ) => LogAction m (WithSeverity VfsLog ) -> J. TMessage 'J.Method_TextDocumentDidOpen -> m ()
144
154
openVFS 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)
147
157
logger <& Opening uri `WithSeverity ` Debug
148
158
vfsMap . at uri .= Just vfile
149
159
@@ -158,9 +168,9 @@ changeFromClientVFS logger msg = do
158
168
J. VersionedTextDocumentIdentifier (J. toNormalizedUri -> uri) version = vid
159
169
vfs <- get
160
170
case vfs ^. vfsMap . at uri of
161
- Just (VirtualFile _ file_ver contents) -> do
171
+ Just (VirtualFile _ file_ver contents kind ) -> do
162
172
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 )
164
174
Nothing -> logger <& URINotFound uri `WithSeverity ` Warning
165
175
166
176
-- ---------------------------------------------------------------------
@@ -171,7 +181,7 @@ applyCreateFile (J.CreateFile _ann _kind (J.toNormalizedUri -> uri) options) =
171
181
%= Map. insertWith
172
182
(\ new old -> if shouldOverwrite then new else old)
173
183
uri
174
- (VirtualFile 0 0 mempty )
184
+ (VirtualFile 0 0 mempty Nothing )
175
185
where
176
186
shouldOverwrite :: Bool
177
187
shouldOverwrite = case options of
@@ -281,7 +291,7 @@ changeFromServerVFS logger msg = do
281
291
282
292
-- ---------------------------------------------------------------------
283
293
virtualFileName :: FilePath -> J. NormalizedUri -> VirtualFile -> FilePath
284
- virtualFileName prefix uri (VirtualFile _ file_ver _) =
294
+ virtualFileName prefix uri (VirtualFile _ file_ver _ _ ) =
285
295
let uri_raw = J. fromNormalizedUri uri
286
296
basename = maybe " " takeFileName (J. uriToFilePath uri_raw)
287
297
-- Given a length and a version number, pad the version number to
@@ -463,7 +473,7 @@ rangeToCodePointRange vFile (J.Range b e) =
463
473
CodePointRange <$> positionToCodePointPosition vFile b <*> positionToCodePointPosition vFile e
464
474
465
475
rangeLinesFromVfs :: 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
467
477
where
468
478
(_, s1) = Rope. splitAtLine (fromIntegral lf) ropetext
469
479
(s2, _) = Rope. splitAtLine (fromIntegral (lt - lf)) s1
0 commit comments