0 | module Language.LSP.Message.DocumentFormatting
3 | import Language.LSP.Message.Derive
4 | import Language.LSP.Message.Location
5 | import Language.LSP.Message.Progress
6 | import Language.LSP.Message.TextDocument
7 | import Language.LSP.Message.Utils
8 | import Language.Reflection
10 | %language ElabReflection
15 | record DocumentFormattingClientCapabilities where
16 | constructor MkDocumentFormattingClientCapabilities
17 | dynamicRegistration : Maybe Bool
18 | %runElab deriveJSON defaultOpts `{DocumentFormattingClientCapabilities
}
22 | record DocumentFormattingOptions where
23 | constructor MkDocumentFormattingOptions
24 | workDoneProgress : Maybe Bool
25 | %runElab deriveJSON defaultOpts `{DocumentFormattingOptions
}
29 | record DocumentFormattingRegistrationOptions where
30 | constructor MkDocumentFormattingRegistrationOptions
31 | workDoneProgress : Maybe Bool
32 | documentSelector : OneOf [DocumentSelector, Null]
33 | %runElab deriveJSON defaultOpts `{DocumentFormattingRegistrationOptions
}
37 | record FormattingOptions where
38 | constructor MkFormattingOptions
41 | trimTrailingWhitespace : Maybe Bool
42 | insertFinalNewline : Maybe Bool
43 | trimFinalNewlines : Maybe Bool
44 | other : List (String, OneOf [Bool, Int, String])
47 | ToJSON FormattingOptions where
49 | JObject ((catMaybes [ Just ("tabSize", toJSON opts.tabSize)
50 | , Just ("insertSpaces", toJSON opts.insertSpaces)
51 | , ("trimTrailingWhitespace",) . toJSON <$> opts.trimTrailingWhitespace
52 | , ("insertFinalNewline",) . toJSON <$> opts.insertFinalNewline
53 | , ("trimFinalNewlines",) . toJSON <$> opts.trimFinalNewlines
54 | ]) ++ (mapSnd toJSON <$> opts.other))
57 | FromJSON FormattingOptions where
58 | fromJSON (JObject arg) =
59 | pure MkFormattingOptions <*> (lookup "tabSize" arg >>= fromJSON)
60 | <*> (lookup "insertSpaces" arg >>= fromJSON)
61 | <*> (pure $
lookup "trimTrailingWhitespace" arg >>= fromJSON)
62 | <*> (pure $
lookup "insertFinalNewline" arg >>= fromJSON)
63 | <*> (pure $
lookup "trimFinalNewlines" arg >>= fromJSON)
64 | <*> (pure $
catMaybes $
map sequence $
map (mapSnd fromJSON) $
filter (\(k, _) => not $
k `elem` fields) $
toList arg)
66 | fields : List String
67 | fields = ["tabSize", "insertSpaces", "trimTrailingWhitespace", "insertFinalNewline", "trimFinalNewlines"]
68 | fromJSON _ = neutral
72 | record DocumentFormattingParams where
73 | constructor MkDocumentFormattingParams
74 | workDoneToken : Maybe ProgressToken
75 | textDocument : TextDocumentIdentifier
76 | options : FormattingOptions
77 | %runElab deriveJSON defaultOpts `{DocumentFormattingParams
}
81 | record DocumentRangeFormattingClientCapabilities where
82 | constructor MkDocumentRangeFormattingClientCapabilities
83 | dynamicRegistration : Maybe Bool
84 | %runElab deriveJSON defaultOpts `{DocumentRangeFormattingClientCapabilities
}
88 | record DocumentRangeFormattingOptions where
89 | constructor MkDocumentRangeFormattingOptions
90 | workDoneProgress : Maybe Bool
91 | %runElab deriveJSON defaultOpts `{DocumentRangeFormattingOptions
}
95 | record DocumentRangeFormattingRegistrationOptions where
96 | constructor MkDocumentRangeFormattingRegistrationOptions
97 | workDoneProgress : Maybe Bool
98 | documentSelector : OneOf [DocumentSelector, Null]
99 | %runElab deriveJSON defaultOpts `{DocumentRangeFormattingRegistrationOptions
}
103 | record DocumentRangeFormattingParams where
104 | constructor MkDocumentRangeFormattingParams
105 | workDoneToken : Maybe ProgressToken
106 | textDocument : TextDocumentIdentifier
108 | options : FormattingOptions
109 | %runElab deriveJSON defaultOpts `{DocumentRangeFormattingParams
}
113 | record DocumentOnTypeFormattingClientCapabilities where
114 | constructor MkDocumentOnTypeFormattingClientCapabilities
115 | dynamicRegistration : Maybe Bool
116 | %runElab deriveJSON defaultOpts `{DocumentOnTypeFormattingClientCapabilities
}
120 | record DocumentOnTypeFormattingOptions where
121 | constructor MkDocumentOnTypeFormattingOptions
122 | firstTriggerCharacter : Char
123 | moreTriggerCharacter : Maybe (List Char)
124 | %runElab deriveJSON defaultOpts `{DocumentOnTypeFormattingOptions
}
128 | record DocumentOnTypeFormattingRegistrationOptions where
129 | constructor MkDocumentOnTypeFormattingRegistrationOptions
130 | firstTriggerCharacter : Char
131 | moreTriggerCharacter : Maybe (List Char)
132 | documentSelector : OneOf [DocumentSelector, Null]
133 | %runElab deriveJSON defaultOpts `{DocumentOnTypeFormattingRegistrationOptions
}
137 | record DocumentOnTypeFormattingParams where
138 | constructor MkDocumentOnTypeFormattingParams
139 | textDocument : TextDocumentIdentifier
141 | options : FormattingOptions
142 | %runElab deriveJSON defaultOpts `{DocumentOnTypeFormattingParams
}