Skip to content

Commit 5c3d374

Browse files
committed
Fix & make fields of file change options optional
1 parent a1be3f3 commit 5c3d374

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

lsp-types/src/Language/LSP/Types/WorkspaceEdit.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ instance FromJSON FileResourceChangeKind where
6363
data CreateFileOptions =
6464
CreateFileOptions
6565
{ -- | Overwrite existing file. Overwrite wins over `ignoreIfExists`
66-
_overwrite :: Bool
66+
_overwrite :: Maybe Bool
6767
-- | Ignore if exists.
68-
, _ignoreIfExists :: Bool
68+
, _ignoreIfExists :: Maybe Bool
6969
} deriving (Show, Read, Eq)
7070

7171
deriveJSON lspOptions ''CreateFileOptions
@@ -86,9 +86,9 @@ deriveJSON lspOptions ''CreateFile
8686
data RenameFileOptions =
8787
RenameFileOptions
8888
{ -- | Overwrite target if existing. Overwrite wins over `ignoreIfExists`
89-
_overwrite :: Bool
89+
_overwrite :: Maybe Bool
9090
-- | Ignores if target exists.
91-
, _ignoreIfExists :: Bool
91+
, _ignoreIfExists :: Maybe Bool
9292
} deriving (Show, Read, Eq)
9393

9494
deriveJSON lspOptions ''RenameFileOptions
@@ -111,9 +111,9 @@ deriveJSON lspOptions ''RenameFile
111111
data DeleteFileOptions =
112112
DeleteFileOptions
113113
{ -- | Delete the content recursively if a folder is denoted.
114-
_recursive :: Bool
114+
_recursive :: Maybe Bool
115115
-- | Ignore the operation if the file doesn't exist.
116-
, _ignoreIfNotExists :: Bool
116+
, _ignoreIfNotExists :: Maybe Bool
117117
} deriving (Show, Read, Eq)
118118

119119
deriveJSON lspOptions ''DeleteFileOptions

lsp-types/src/Language/LSP/VFS.hs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,16 @@ applyCreateFile (J.CreateFile _ uri options) =
138138
where
139139
shouldOverwrite :: Bool
140140
shouldOverwrite = case options of
141-
Just (J.CreateFileOptions True _) -> True -- `overwrite` is True
142-
Just (J.CreateFileOptions False _) -> False -- `overwrite` wins over `ignoreIfExists`
143-
Nothing -> False
141+
Nothing -> False -- default
142+
Just (J.CreateFileOptions Nothing Nothing ) -> False -- default
143+
Just (J.CreateFileOptions Nothing (Just True) ) -> False -- `ignoreIfExists` is True
144+
Just (J.CreateFileOptions Nothing (Just False)) -> True -- `ignoreIfExists` is False
145+
Just (J.CreateFileOptions (Just True) Nothing ) -> True -- `overwrite` is True
146+
Just (J.CreateFileOptions (Just True) (Just True) ) -> True -- `overwrite` wins over `ignoreIfExists`
147+
Just (J.CreateFileOptions (Just True) (Just False)) -> True -- `overwrite` is True
148+
Just (J.CreateFileOptions (Just False) Nothing ) -> False -- `overwrite` is False
149+
Just (J.CreateFileOptions (Just False) (Just True) ) -> False -- `overwrite` is False
150+
Just (J.CreateFileOptions (Just False) (Just False)) -> False -- `overwrite` wins over `ignoreIfExists`
144151

145152
applyRenameFile :: J.RenameFile -> VFS -> VFS
146153
applyRenameFile (J.RenameFile _ oldUri' newUri' options) vfs =
@@ -158,9 +165,16 @@ applyRenameFile (J.RenameFile _ oldUri' newUri' options) vfs =
158165
where
159166
shouldOverwrite :: Bool
160167
shouldOverwrite = case options of
161-
Just (J.RenameFileOptions True _) -> True -- `overwrite` is True
162-
Just (J.RenameFileOptions False _) -> False -- `overwrite` wins over `ignoreIfExists`
163-
Nothing -> False
168+
Nothing -> False -- default
169+
Just (J.RenameFileOptions Nothing Nothing ) -> False -- default
170+
Just (J.RenameFileOptions Nothing (Just True) ) -> False -- `ignoreIfExists` is True
171+
Just (J.RenameFileOptions Nothing (Just False)) -> True -- `ignoreIfExists` is False
172+
Just (J.RenameFileOptions (Just True) Nothing ) -> True -- `overwrite` is True
173+
Just (J.RenameFileOptions (Just True) (Just True) ) -> True -- `overwrite` wins over `ignoreIfExists`
174+
Just (J.RenameFileOptions (Just True) (Just False)) -> True -- `overwrite` is True
175+
Just (J.RenameFileOptions (Just False) Nothing ) -> False -- `overwrite` is False
176+
Just (J.RenameFileOptions (Just False) (Just True) ) -> False -- `overwrite` is False
177+
Just (J.RenameFileOptions (Just False) (Just False)) -> False -- `overwrite` wins over `ignoreIfExists`
164178

165179
-- NOTE: we are ignoring the `recursive` option here because we don't know which file is a directory
166180
applyDeleteFile :: J.DeleteFile -> VFS -> VFS

0 commit comments

Comments
 (0)