Skip to content

Commit f890cd0

Browse files
committed
Add WatchKind helpers and fix a bug with createDoc
1 parent fe75575 commit f890cd0

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

lsp-test/src/Language/LSP/Test.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ createDoc file languageId contents = do
418418
watchHits :: FileSystemWatcher -> Bool
419419
watchHits (FileSystemWatcher (GlobPattern (InL (Pattern pattern))) kind) =
420420
-- If WatchKind is excluded, defaults to all true as per spec
421-
fileMatches (T.unpack pattern) && createHits (fromMaybe WatchKind_Create kind)
421+
fileMatches (T.unpack pattern) && containsCreate (fromMaybe WatchKind_Create kind)
422422
-- TODO: Relative patterns
423423
watchHits _ = False
424424

@@ -428,9 +428,6 @@ createDoc file languageId contents = do
428428
| isAbsolute pattern = absFile
429429
| otherwise = file
430430

431-
createHits WatchKind_Create = True
432-
createHits _ = False
433-
434431
regHits :: TRegistration Method_WorkspaceDidChangeWatchedFiles -> Bool
435432
regHits reg = foldl' (\acc w -> acc || watchHits w) False (reg ^. L.registerOptions . _Just . L.watchers)
436433

lsp-types/lsp-types.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ library
126126
Language.LSP.Protocol.Types.Singletons
127127
Language.LSP.Protocol.Types.Uri
128128
Language.LSP.Protocol.Types.Uri.OsPath
129+
Language.LSP.Protocol.Types.WatchKinds
129130

130131
-- The generated modules
131132
-- In principle these could be in a separate component,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Language.LSP.Protocol.Types (
2020
, module Progress
2121
-- ** Semantic tokens
2222
, module SemanticTokens
23+
-- ** WatchKinds
24+
, module WatchKinds
2325
-- * Main LSP types and functions
2426
, module Generated
2527
) where
@@ -35,3 +37,4 @@ import Language.LSP.Protocol.Types.Singletons as Singletons
3537
import Language.LSP.Protocol.Types.Uri as Uri
3638
import Language.LSP.Protocol.Types.Uri.OsPath as Uri
3739
import Language.LSP.Protocol.Types.Edit as Edits
40+
import Language.LSP.Protocol.Types.WatchKinds as WatchKinds
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Language.LSP.Protocol.Types.WatchKinds where
2+
3+
import Language.LSP.Protocol.Internal.Types (WatchKind(..))
4+
import Language.LSP.Protocol.Types.LspEnum (toEnumBaseType, fromOpenEnumBaseType)
5+
import Data.Set (toList, Set)
6+
7+
containsCreate :: WatchKind -> Bool
8+
containsCreate WatchKind_Create = True
9+
containsCreate (WatchKind_Custom 3) = True
10+
containsCreate (WatchKind_Custom 5) = True
11+
containsCreate _ = False
12+
13+
containsChange :: WatchKind -> Bool
14+
containsChange WatchKind_Change = True
15+
containsChange (WatchKind_Custom 3) = True
16+
containsChange (WatchKind_Custom 6) = True
17+
containsChange _ = False
18+
19+
containsDelete :: WatchKind -> Bool
20+
containsDelete WatchKind_Delete = True
21+
containsDelete (WatchKind_Custom 5) = True
22+
containsDelete (WatchKind_Custom 6) = True
23+
containsDelete _ = False
24+
25+
combineWatchKinds :: Set WatchKind -> WatchKind
26+
combineWatchKinds s = fromOpenEnumBaseType $ sum $ toEnumBaseType <$> toList s

0 commit comments

Comments
 (0)