lsp-2.7.0.1: Haskell library for the Microsoft Language Server Protocol

Safe Haskell | None
Language | GHC2021

Language.LSP.VFS

Contents

- Managing the VFS
- Positions and transformations
- manipulating the file contents
- for tests

Description

Handles the Language.LSP.Types.TextDocumentDidChange / Language.LSP.Types.TextDocumentDidOpen / Language.LSP.Types.TextDocumentDidClose messages to keep an in-memory `filesystem` of the current client workspace. The server can access and edit files in the client workspace by operating on the VFS in LspFuncs.

Synopsis

- data VFS = VFS {
  - _vfsMap :: !(Map NormalizedUri VirtualFile)
  }
- vfsMap :: HasVfsMap s a => Lens' s a
- data VirtualFile = VirtualFile {
  - _lsp_version :: !Int32
  - _file_version :: !Int
  - _file_text :: !Rope
  }
- lsp_version :: HasLsp_version s a => Lens' s a
- file_version :: HasFile_version s a => Lens' s a
- file_text :: HasFile_text s a => Lens' s a
- virtualFileText :: VirtualFile -> Text
- virtualFileVersion :: VirtualFile -> Int32
- data VfsLog
  - = SplitInsideCodePoint Position Rope
  - | URINotFound NormalizedUri
  - | Opening NormalizedUri
  - | Closing NormalizedUri
  - | PersistingFile NormalizedUri FilePath
  - | CantRecursiveDelete NormalizedUri
  - | DeleteNonExistent NormalizedUri
- emptyVFS :: VFS
- openVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidOpen -> m ()
- changeFromClientVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidChange -> m ()
- changeFromServerVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_WorkspaceApplyEdit -> m ()
- persistFileVFS :: MonadIO m => LogAction m (WithSeverity VfsLog) -> FilePath -> VFS -> NormalizedUri -> Maybe (FilePath, m ())
- closeVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidClose -> m ()
- data CodePointPosition = CodePointPosition {
  - _line :: UInt
  - _character :: UInt
  }
- line :: HasLine s a => Lens' s a
- character :: HasCharacter s a => Lens' s a
- codePointPositionToPosition :: VirtualFile -> CodePointPosition -> Maybe Position
- positionToCodePointPosition :: VirtualFile -> Position -> Maybe CodePointPosition
- data CodePointRange = CodePointRange {
  - _start :: CodePointPosition
  - _end :: CodePointPosition
  }
- start :: HasStart s a => Lens' s a
- end :: HasEnd s a => Lens' s a
- codePointRangeToRange :: VirtualFile -> CodePointRange -> Maybe Range
- rangeToCodePointRange :: VirtualFile -> Range -> Maybe CodePointRange
- rangeLinesFromVfs :: VirtualFile -> Range -> Text
- applyChanges :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> [TextDocumentContentChangeEvent] -> m Rope
- applyChange :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> TextDocumentContentChangeEvent -> m Rope
- changeChars :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> Position -> Position -> Text -> m Rope

# Documentation

data VFS #

Constructors

VFS |
Fields _vfsMap :: !(Map NormalizedUri VirtualFile)

#### Instances

Instances details

Show VFS # |
Instance details Defined in Language.LSP.VFS Methods showsPrec :: Int -> VFS -> ShowS # show :: VFS -> String # showList :: [VFS] -> ShowS #

vfsMap :: HasVfsMap s a => Lens' s a #

data VirtualFile #

Constructors

VirtualFile |
Fields _lsp_version :: !Int32 The LSP version of the document _file_version :: !Int This number is only incremented whilst the file remains in the map. _file_text :: !Rope The full contents of the document

#### Instances

Instances details

Show VirtualFile # |
Instance details Defined in Language.LSP.VFS Methods showsPrec :: Int -> VirtualFile -> ShowS # show :: VirtualFile -> String # showList :: [VirtualFile] -> ShowS #

lsp_version :: HasLsp_version s a => Lens' s a #

file_version :: HasFile_version s a => Lens' s a #

file_text :: HasFile_text s a => Lens' s a #

virtualFileText :: VirtualFile -> Text #

virtualFileVersion :: VirtualFile -> Int32 #

data VfsLog #

Constructors

SplitInsideCodePoint Position Rope |
URINotFound NormalizedUri |
Opening NormalizedUri |
Closing NormalizedUri |
PersistingFile NormalizedUri FilePath |
CantRecursiveDelete NormalizedUri |
DeleteNonExistent NormalizedUri |

#### Instances

Instances details

Show VfsLog # |
Instance details Defined in Language.LSP.VFS Methods showsPrec :: Int -> VfsLog -> ShowS # show :: VfsLog -> String # showList :: [VfsLog] -> ShowS #
Pretty VfsLog # |
Instance details Defined in Language.LSP.VFS Methods pretty :: VfsLog -> Doc ann # prettyList :: [VfsLog] -> Doc ann #

# Managing the VFS

emptyVFS :: VFS #

openVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidOpen -> m () #

Applies the changes from a `DidOpenTextDocument` to the `VFS`

changeFromClientVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidChange -> m () #

Applies a `DidChangeTextDocumentNotification` to the `VFS`

changeFromServerVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_WorkspaceApplyEdit -> m () #

Applies the changes from a `ApplyWorkspaceEditRequest` to the `VFS`

persistFileVFS :: MonadIO m => LogAction m (WithSeverity VfsLog) -> FilePath -> VFS -> NormalizedUri -> Maybe (FilePath, m ()) #

Write a virtual file to a file in the given directory if it exists in the VFS.

closeVFS :: MonadState VFS m => LogAction m (WithSeverity VfsLog) -> TMessage 'Method_TextDocumentDidClose -> m () #

# Positions and transformations

data CodePointPosition #

A position, like a `Position`, but where the offsets in the line are measured in Unicode code points instead of UTF-16 code units.

Constructors

CodePointPosition |
Fields _line :: UInt Line position in a document (zero-based). _character :: UInt Character offset on a line in a document in *code points* (zero-based).

#### Instances

Instances details

Read CodePointPosition # |
Instance details Defined in Language.LSP.VFS Methods readsPrec :: Int -> ReadS CodePointPosition # readList :: ReadS [CodePointPosition] # readPrec :: ReadPrec CodePointPosition # readListPrec :: ReadPrec [CodePointPosition] #
Show CodePointPosition # |
Instance details Defined in Language.LSP.VFS Methods showsPrec :: Int -> CodePointPosition -> ShowS # show :: CodePointPosition -> String # showList :: [CodePointPosition] -> ShowS #
Eq CodePointPosition # |
Instance details Defined in Language.LSP.VFS Methods (==) :: CodePointPosition -> CodePointPosition -> Bool # (/=) :: CodePointPosition -> CodePointPosition -> Bool #
Ord CodePointPosition # |
Instance details Defined in Language.LSP.VFS Methods compare :: CodePointPosition -> CodePointPosition -> Ordering # (<) :: CodePointPosition -> CodePointPosition -> Bool # (<=) :: CodePointPosition -> CodePointPosition -> Bool # (>) :: CodePointPosition -> CodePointPosition -> Bool # (>=) :: CodePointPosition -> CodePointPosition -> Bool # max :: CodePointPosition -> CodePointPosition -> CodePointPosition # min :: CodePointPosition -> CodePointPosition -> CodePointPosition #

line :: HasLine s a => Lens' s a #

character :: HasCharacter s a => Lens' s a #

codePointPositionToPosition :: VirtualFile -> CodePointPosition -> Maybe Position #

Given a virtual file, translate a `CodePointPosition` in that file into a `Position` in that file.

Will return `Nothing` if the requested position is out of bounds of the document.

Logarithmic in the number of lines in the document, and linear in the length of the line containing the position.

positionToCodePointPosition :: VirtualFile -> Position -> Maybe CodePointPosition #

Given a virtual file, translate a `Position` in that file into a `CodePointPosition` in that file.

Will return `Nothing` if the requested position lies inside a code point, or if it is out of bounds of the document.

Logarithmic in the number of lines in the document, and linear in the length of the line containing the position.

data CodePointRange #

A range, like a `Range`, but where the offsets in the line are measured in Unicode code points instead of UTF-16 code units.

Constructors

CodePointRange |
Fields _start :: CodePointPosition The range's start position. _end :: CodePointPosition The range's end position.

#### Instances

Instances details

Read CodePointRange # |
Instance details Defined in Language.LSP.VFS Methods readsPrec :: Int -> ReadS CodePointRange # readList :: ReadS [CodePointRange] # readPrec :: ReadPrec CodePointRange # readListPrec :: ReadPrec [CodePointRange] #
Show CodePointRange # |
Instance details Defined in Language.LSP.VFS Methods showsPrec :: Int -> CodePointRange -> ShowS # show :: CodePointRange -> String # showList :: [CodePointRange] -> ShowS #
Eq CodePointRange # |
Instance details Defined in Language.LSP.VFS Methods (==) :: CodePointRange -> CodePointRange -> Bool # (/=) :: CodePointRange -> CodePointRange -> Bool #
Ord CodePointRange # |
Instance details Defined in Language.LSP.VFS Methods compare :: CodePointRange -> CodePointRange -> Ordering # (<) :: CodePointRange -> CodePointRange -> Bool # (<=) :: CodePointRange -> CodePointRange -> Bool # (>) :: CodePointRange -> CodePointRange -> Bool # (>=) :: CodePointRange -> CodePointRange -> Bool # max :: CodePointRange -> CodePointRange -> CodePointRange # min :: CodePointRange -> CodePointRange -> CodePointRange #

start :: HasStart s a => Lens' s a #

end :: HasEnd s a => Lens' s a #

codePointRangeToRange :: VirtualFile -> CodePointRange -> Maybe Range #

Given a virtual file, translate a `CodePointRange` in that file into a `Range` in that file.

Will return `Nothing` if any of the positions are out of bounds of the document.

Logarithmic in the number of lines in the document, and linear in the length of the lines containing the positions.

rangeToCodePointRange :: VirtualFile -> Range -> Maybe CodePointRange #

Given a virtual file, translate a `Range` in that file into a `CodePointRange` in that file.

Will return `Nothing` if any of the positions are out of bounds of the document.

Logarithmic in the number of lines in the document, and linear in the length of the lines containing the positions.

# manipulating the file contents

rangeLinesFromVfs :: VirtualFile -> Range -> Text #

# for tests

applyChanges :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> [TextDocumentContentChangeEvent] -> m Rope #

Apply the list of changes. Changes should be applied in the order that they are received from the client.

applyChange :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> TextDocumentContentChangeEvent -> m Rope #

changeChars :: Monad m => LogAction m (WithSeverity VfsLog) -> Rope -> Position -> Position -> Text -> m Rope #

Given a `Rope`, start and end positions, and some new text, replace the given range with the new text. If the given positions lie within a code point then this does nothing (returns the original `Rope`) and logs.