Skip to content

Commit 19b7425

Browse files
authored
Merge branch 'master' into helper-functions
2 parents c4cddba + 5158e0b commit 19b7425

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
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
@@ -129,6 +129,7 @@ library
129129
Language.LSP.Protocol.Types.Singletons
130130
Language.LSP.Protocol.Types.Uri
131131
Language.LSP.Protocol.Types.Uri.OsPath
132+
Language.LSP.Protocol.Types.WatchKinds
132133

133134
-- The generated modules
134135
-- In principle these could be in a separate component,

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

Lines changed: 4 additions & 1 deletion
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
-- ** Orphan instances for the generated types
@@ -37,4 +39,5 @@ import Language.LSP.Protocol.Types.Singletons as Singletons
3739
import Language.LSP.Protocol.Types.Uri as Uri
3840
import Language.LSP.Protocol.Types.Uri.OsPath as Uri
3941
import Language.LSP.Protocol.Types.Edit as Edits
40-
import Language.LSP.Protocol.Types.Orphans as Orphans
42+
import Language.LSP.Protocol.Types.Orphans as Orphans
43+
import Language.LSP.Protocol.Types.WatchKinds as WatchKinds
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
-- WatchKind is better represented as a Set than as enum. As the lsp spec
8+
-- defines them as an enum, these helper functions help bridge the difference.
9+
10+
-- |Tests whether `WatchKind_Create` is contained in the provided WatchKind enum
11+
containsCreate :: WatchKind -> Bool
12+
containsCreate WatchKind_Create = True
13+
containsCreate (WatchKind_Custom 3) = True
14+
containsCreate (WatchKind_Custom 5) = True
15+
containsCreate (WatchKind_Custom 7) = True
16+
containsCreate _ = False
17+
18+
-- |Tests whether `WatchKind_Change` is contained in the provided WatchKind enum
19+
containsChange :: WatchKind -> Bool
20+
containsChange WatchKind_Change = True
21+
containsChange (WatchKind_Custom 3) = True
22+
containsChange (WatchKind_Custom 6) = True
23+
containsChange (WatchKind_Custom 7) = True
24+
containsChange _ = False
25+
26+
-- |Tests whether `WatchKind_Delete` is contained in the provided WatchKind enum
27+
containsDelete :: WatchKind -> Bool
28+
containsDelete WatchKind_Delete = True
29+
containsDelete (WatchKind_Custom 5) = True
30+
containsDelete (WatchKind_Custom 6) = True
31+
containsDelete (WatchKind_Custom 7) = True
32+
containsDelete _ = False
33+
34+
-- |Combine a set of WatchKind types into a new WatchKind type that accurately
35+
-- represents the set
36+
combineWatchKinds :: Set WatchKind -> WatchKind
37+
combineWatchKinds s = fromOpenEnumBaseType $ sum $ toEnumBaseType <$> toList s

0 commit comments

Comments
 (0)