-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTypes.hs
More file actions
4092 lines (4090 loc) · 160 KB
/
Types.hs
File metadata and controls
4092 lines (4090 loc) · 160 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------------------
-- |
-- Module : Main
-- Copyright : (C) 2023 David M. Johnson
-- License : BSD3-style (see the file LICENSE)
-- Stability : experimental
-- Portability : non-portable
----------------------------------------------------------------------------
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
----------------------------------------------------------------------------
module DAP.Types
( -- * Message Type
MessageType (..)
-- * Types
, Breakpoint (..)
, Breakpoints (..)
, BreakpointLocation (..)
, Capabilities (..)
, Checksum (..)
, ChecksumAlgorithm (..)
, ColumnDescriptor (..)
, CompletionItem (..)
, CompletionItemType (..)
, DataBreakpoint (..)
, DataBreakpointAccessType (..)
, DisassembledInstruction (..)
, ExceptionBreakMode (..)
, ExceptionBreakpointsFilter (..)
, ExceptionDetails (..)
, ExceptionFilterOptions (..)
, ExceptionOptions (..)
, ExceptionPathSegment (..)
, FunctionBreakpoint (..)
, GotoTarget (..)
, InstructionBreakpoint (..)
, InvalidatedAreas (..)
, Message (..)
, Module (..)
, ModulesViewDescriptor (..)
, PresentationHint (..)
, Scope (..)
, Source (..)
, SourceBreakpoint (..)
, SourcePresentationHint (..)
, StackFrame (..)
, StackFrameFormat (..)
, StepInTarget (..)
, SteppingGranularity (..)
, StoppedEventReason (..)
, Thread (..)
, ThreadEventReason (..)
, ValueFormat (..)
, Variable (..)
, VariablePresentationHint (..)
, ColumnDescriptorType (..)
, ScopePresentationHint (..)
, PresentationHintKind (..)
, PresentationHintAttributes (..)
, PresentationHintVisibility (..)
, EventGroup (..)
, EventReason (..)
, StartMethod (..)
, EvaluateArgumentsContext (..)
, PathFormat (..)
-- * Command
, Command (..)
-- * Reverse Command
, ReverseCommand (..)
-- * Event
, EventType (..)
-- ** Events
, StoppedEvent (..)
, ContinuedEvent (..)
, ExitedEvent (..)
, TerminatedEvent (..)
, ThreadEvent (..)
, OutputEvent (..)
, OutputEventCategory (..)
, BreakpointEvent (..)
, ModuleEvent (..)
, LoadedSourceEvent (..)
, ProcessEvent (..)
, CapabilitiesEvent (..)
, ProgressStartEvent (..)
, ProgressUpdateEvent (..)
, ProgressEndEvent (..)
, InvalidatedEvent (..)
, MemoryEvent (..)
-- * Server
, ServerConfig (..)
-- * Client
, Adaptor (..)
, AdaptorState (..)
, AdaptorLocal(..)
, AppStore
, MonadIO
-- * Errors
, AdaptorException (..)
, ErrorMessage (..)
, ErrorResponse (..)
-- * Request
, Request (..)
, ReverseRequestResponse (..)
-- * Misc.
, PayloadSize
, Seq
, SessionId
-- * Responses
, CompletionsResponse (..)
, ContinueResponse (..)
, DataBreakpointInfoResponse (..)
, DisassembleResponse (..)
, EvaluateResponse (..)
, ExceptionInfoResponse (..)
, GotoTargetsResponse (..)
, LoadedSourcesResponse (..)
, ModulesResponse (..)
, ReadMemoryResponse (..)
, RunInTerminalResponse (..)
, ScopesResponse (..)
, SetExpressionResponse (..)
, SetVariableResponse (..)
, SourceResponse (..)
, StackTraceResponse (..)
, StepInTargetsResponse (..)
, ThreadsResponse (..)
, VariablesResponse (..)
, WriteMemoryResponse (..)
-- * Arguments
, AttachRequestArguments (..)
, BreakpointLocationsArguments (..)
, CompletionsArguments (..)
, ConfigurationDoneArguments (..)
, ContinueArguments (..)
, DataBreakpointInfoArguments (..)
, DisassembleArguments (..)
, DisconnectArguments (..)
, EvaluateArguments (..)
, ExceptionInfoArguments (..)
, GotoArguments (..)
, GotoTargetsArguments (..)
, InitializeRequestArguments (..)
, LaunchRequestArguments (..)
, LoadedSourcesArguments (..)
, ModulesArguments (..)
, NextArguments (..)
, PauseArguments (..)
, ReadMemoryArguments (..)
, RestartArguments (..)
, RestartFrameArguments (..)
, ReverseContinueArguments (..)
, RunInTerminalRequestArguments (..)
, RunInTerminalRequestArgumentsKind (..)
, ScopesArguments (..)
, SetBreakpointsArguments (..)
, SetDataBreakpointsArguments (..)
, SetExceptionBreakpointsArguments (..)
, SetExpressionArguments (..)
, SetFunctionBreakpointsArguments (..)
, SetInstructionBreakpointsArguments (..)
, SetVariableArguments (..)
, SourceArguments (..)
, StackTraceArguments (..)
, StepBackArguments (..)
, StepInArguments (..)
, StepInTargetsArguments (..)
, StepOutArguments (..)
, TerminateArguments (..)
, TerminateThreadsArguments (..)
, ThreadsArguments (..)
, VariablesArguments (..)
, WriteMemoryArguments (..)
-- * defaults
, defaultBreakpoint
, defaultBreakpointLocation
, defaultCapabilities
, defaultColumnDescriptor
, defaultCompletionItem
, defaultDisassembledInstruction
, defaultExceptionBreakpointsFilter
, defaultExceptionDetails
, defaultFunctionBreakpoint
, defaultGotoTarget
, defaultMessage
, defaultModule
, defaultModulesViewDescriptor
, defaultScope
, defaultSource
, defaultSourceBreakpoint
, defaultStackFrame
, defaultStackFrameFormat
, defaultStepInTarget
, defaultThread
, defaultValueFormat
, defaultVariable
, defaultVariablePresentationHint
-- * Debug Thread state
, DebuggerThreadState (..)
) where
----------------------------------------------------------------------------
import Control.Applicative ( (<|>) )
import Control.Monad.Base ( MonadBase )
import Control.Monad.Except ( MonadError, ExceptT )
import Control.Monad.Trans.Control ( MonadBaseControl )
import Control.Concurrent ( ThreadId )
import Control.Concurrent.MVar ( MVar )
import Control.Monad.IO.Class ( MonadIO )
import Control.Monad.Reader ( MonadReader, ReaderT )
import Control.Monad.State ( MonadState, StateT )
import Data.IORef ( IORef )
import Data.Typeable ( typeRep )
import Control.Concurrent.STM ( TVar )
import Control.Exception ( Exception )
import Control.Monad.Reader ( )
import Data.Aeson ( (.:), (.:?), withObject, withText, object
, FromJSON(parseJSON), Value, KeyValue((.=))
, ToJSON(toJSON), genericParseJSON, defaultOptions
)
import Data.Aeson.Types ( Pair, typeMismatch, Parser )
import Data.Proxy ( Proxy(Proxy) )
import Data.String ( IsString(..) )
import Data.Time ( UTCTime )
import GHC.Generics ( Generic )
import Network.Socket ( SockAddr )
import System.IO ( Handle )
import Text.Read ( readMaybe )
import Data.Text (Text)
import qualified Data.Text as T ( pack, unpack , Text)
import qualified Data.HashMap.Strict as H
import Colog.Core
----------------------------------------------------------------------------
import DAP.Utils ( capitalize, getName, genericParseJSONWithModifier, genericToJSONWithModifier )
import DAP.Log
----------------------------------------------------------------------------
-- | Core type for Debug Adaptor to send and receive messages in a type safe way.
-- the state is 'AdaptorState' which holds configuration information, along with
-- the current event / response being constructed and the type of the message.
-- Of note: A 'StateT' is used because 'adaptorPayload' should not be shared
-- with other threads.
newtype Adaptor store r a =
Adaptor (ExceptT (ErrorMessage, Maybe Message) (ReaderT (AdaptorLocal store r) (StateT AdaptorState IO)) a)
deriving newtype
( Monad
, MonadIO, Applicative, Functor, MonadReader (AdaptorLocal store r)
, MonadState AdaptorState
, MonadBaseControl IO
, MonadError (ErrorMessage, Maybe Message)
, MonadBase IO
)
----------------------------------------------------------------------------
-- | The adaptor state is local to a single connection / thread
data AdaptorState
= AdaptorState
{ messageType :: MessageType
-- ^ Current message type being created
-- This was added as a convenience so we can set the 'request_seq'
-- and 'command' fields automatically.
--
, payload :: ![Pair]
-- ^ Payload of the current message to be sent
-- This should never be manually modified by the end user
-- The payload is accumulated automatically by usage of the API
--
--
}
----------------------------------------------------------------------------
-- | The adaptor local config
data AdaptorLocal app request = AdaptorLocal
{ appStore :: AppStore app
-- ^ Global app store, accessible on a per session basis
-- Initialized during 'attach' sessions
--
, serverConfig :: ServerConfig
-- ^ Configuration information for the ServerConfig
-- Identical across all debugging sessions
--
, handle :: Handle
-- ^ Connection Handle
--
--
, address :: SockAddr
-- ^ Address of Connection
--
, sessionId :: IORef (Maybe SessionId)
-- ^ Session ID
-- Local to the current connection's debugger session
--
, handleLock :: MVar ()
-- ^ A lock for writing to a Handle. One lock is created per connection
-- and exists for the duration of that connection
, logAction :: LogAction IO DAPLog
-- ^ Where to send log output
--
, request :: request
-- ^ Connection Request information, if we are responding to a request.
}
----------------------------------------------------------------------------
type SessionId = Text
----------------------------------------------------------------------------
-- | Used to store a map of debugging sessions
-- The 'ThreadId' is meant to be an asynchronous operation that
-- allows initalized debuggers to emit custom events
-- when they receive messages from the debugger
type AppStore app = TVar (H.HashMap SessionId (DebuggerThreadState, app))
----------------------------------------------------------------------------
-- | 'DebuggerThreadState'
-- State to hold both the thread that executes the debugger and the thread used
-- to propagate output events from the debugger + debuggee to the editor (via the
-- DAP server).
data DebuggerThreadState
= DebuggerThreadState
{ debuggerThreads :: [ThreadId]
}
----------------------------------------------------------------------------
data ServerConfig
= ServerConfig
{ host :: String
, port :: Int
, serverCapabilities :: Capabilities
, debugLogging :: Bool
} deriving stock (Show, Eq)
----------------------------------------------------------------------------
-- | Used to signify a malformed message has been received
data AdaptorException
= ParseException String
| ExpectedArguments T.Text
| DebugSessionIdException T.Text
| DebuggerException T.Text
deriving stock (Show, Eq)
deriving anyclass Exception
----------------------------------------------------------------------------
type PayloadSize = Int
----------------------------------------------------------------------------
data MessageType
= MessageTypeEvent
| MessageTypeResponse
| MessageTypeRequest
deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
instance ToJSON MessageType where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
type Seq = Int
----------------------------------------------------------------------------
data Request
= Request
{ args :: Maybe Value
-- ^ Request arguments
--
, requestSeqNum :: Seq
-- ^ Request sequence number
--
, command :: Command
-- ^ Command of Request
--
} deriving stock (Show)
----------------------------------------------------------------------------
instance FromJSON Request where
parseJSON = withObject "Request" $ \o -> do
"request" <- (o .: "type") :: Parser String
Request
<$> o .:? "arguments"
<*> o .: "seq"
<*> o .: "command"
----------------------------------------------------------------------------
data ReverseRequestResponse
= ReverseRequestResponse
{ body :: Maybe Value
-- ^ Request arguments
--
, reverseRequestResponseSeqNum :: Seq
-- ^ Request sequence number
--
, reverseRequestCommand :: ReverseCommand
-- ^ Command of Request
--
, success :: Bool
-- ^ Whether the reverse request was successful
} deriving stock (Show)
----------------------------------------------------------------------------
instance FromJSON ReverseRequestResponse where
parseJSON = withObject "ReverseRequestResponse" $ \o -> do
"response" <- (o .: "type") :: Parser String
ReverseRequestResponse
<$> o .:? "body"
<*> o .: "seq"
<*> o .: "command"
<*> o .: "success"
----------------------------------------------------------------------------
data Breakpoint
= Breakpoint
{ breakpointId :: Maybe Int
-- ^
-- The identifier for the breakpoint. It is needed if breakpoint events are
-- used to update or remove breakpoints.
--
, breakpointVerified :: Bool
-- ^
-- If true, the breakpoint could be set (but not necessarily at the desired
-- location).
--
, breakpointMessage :: Maybe Text
-- ^
-- A message about the state of the breakpoint.
-- This is shown to the user and can be used to explain why a breakpoint could
-- not be verified.
--
, breakpointSource :: Maybe Source
-- ^
-- The source where the breakpoint is located.
--
, breakpointLine :: Maybe Int
-- ^
-- The start line of the actual range covered by the breakpoint.
--
, breakpointColumn :: Maybe Int
-- ^
-- Start position of the source range covered by the breakpoint. It is
-- measured in UTF-16 code units and the client capability `columnsStartAt1`
-- determines whether it is 0- or 1-based.
--
, breakpointEndLine :: Maybe Int
-- ^
-- The end line of the actual range covered by the breakpoint.
--
, breakpointEndColumn :: Maybe Int
-- ^
-- End position of the source range covered by the breakpoint. It is measured
-- in UTF-16 code units and the client capability `columnsStartAt1` determines
-- whether it is 0- or 1-based.
-- If no end line is given, then the end column is assumed to be in the start
-- line.
--
, breakpointInstructionReference :: Maybe Text
-- ^
-- A memory reference to where the breakpoint is set.
--
, breakpointOffset :: Maybe Int
-- ^
-- The offset from the instruction reference.
-- This can be negative.
--
} deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
defaultBreakpoint :: Breakpoint
defaultBreakpoint = Breakpoint
{ breakpointId = Nothing
, breakpointVerified = False
, breakpointMessage = Nothing
, breakpointSource = Nothing
, breakpointLine = Nothing
, breakpointColumn = Nothing
, breakpointEndLine = Nothing
, breakpointEndColumn = Nothing
, breakpointInstructionReference = Nothing
, breakpointOffset = Nothing
}
----------------------------------------------------------------------------
instance ToJSON Breakpoint where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
newtype Breakpoints breakpoint = Breakpoints [breakpoint]
deriving stock (Show, Eq)
----------------------------------------------------------------------------
instance ToJSON breakpoint => ToJSON (Breakpoints breakpoint) where
toJSON (Breakpoints breakpoints)
= object
[ "breakpoints" .= breakpoints
]
----------------------------------------------------------------------------
data Source
= Source
{ sourceName :: Maybe Text
-- ^
-- The short name of the source. Every source returned from the debug adapter
-- has a name.
-- When sending a source to the debug adapter this name is optional.
--
, sourcePath :: Maybe Text
-- ^
-- The path of the source to be shown in the UI.
-- It is only used to locate and load the content of the source if no
-- `sourceReference` is specified (or its value is 0).
--
, sourceSourceReference :: Maybe Int
-- ^
-- If the value > 0 the contents of the source must be retrieved through the
-- `source` request (even if a path is specified).
-- Since a `sourceReference` is only valid for a session, it can not be used
-- to persist a source.
-- The value should be less than or equal to 2147483647 (2^31-1).
--
, sourcePresentationHint :: Maybe SourcePresentationHint
-- ^
-- A hint for how to present the source in the UI.
-- A value of `deemphasize` can be used to indicate that the source is not
-- available or that it is skipped on stepping.
-- Values: 'normal', 'emphasize', 'deemphasize'
--
, sourceOrigin :: Maybe Text
-- ^
-- The origin of this source. For example, 'internal module', 'inlined content
-- from source map', etc.
--
, sourceSources :: Maybe [Source]
-- ^
-- A list of sources that are related to this source. These may be the source
-- that generated this source.
--
, sourceAdapterData :: Maybe Value
-- ^
-- Additional data that a debug adapter might want to loop through the client.
-- The client should leave the data intact and persist it across sessions. The
-- client should not interpret the data.
--
, sourceChecksums :: Maybe [Checksum]
-- ^
-- The checksums associated with this file.
--
} deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
defaultSource :: Source
defaultSource
= Source
{ sourceName = Nothing
, sourcePath = Nothing
, sourceSourceReference = Nothing
, sourcePresentationHint = Nothing
, sourceOrigin = Nothing
, sourceSources = Nothing
, sourceAdapterData = Nothing
, sourceChecksums = Nothing
}
----------------------------------------------------------------------------
instance FromJSON Source where
parseJSON = genericParseJSONWithModifier
----------------------------------------------------------------------------
instance ToJSON Source where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
newtype Sources = Sources { getSources :: [Source] } deriving stock (Show, Eq)
----------------------------------------------------------------------------
instance ToJSON Sources where toJSON (Sources s) = object [ "sources" .= s ]
----------------------------------------------------------------------------
data SourcePresentationHint
= SourcePresentationHintNormal
| SourcePresentationHintEmphasize
| SourcePresentationHintDeemphasize
deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
instance FromJSON SourcePresentationHint where
parseJSON = genericParseJSONWithModifier
----------------------------------------------------------------------------
instance ToJSON SourcePresentationHint where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
data PresentationHint
= PresentationHintNormal
| PresentationHintLabel
| PresentationHintSubtle
deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
instance ToJSON PresentationHint where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
data Checksum
= Checksum
{ algorithm :: ChecksumAlgorithm
-- ^ The algorithm used to calculate this checksum.
--
, checksum :: Text
-- ^ Value of the checksum, encoded as a hexadecimal value.
--
} deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
----------------------------------------------------------------------------
data ChecksumAlgorithm
= MD5
| SHA1
| SHA256
| TimeStamp UTCTime
deriving stock (Show, Eq)
----------------------------------------------------------------------------
instance ToJSON ChecksumAlgorithm where
toJSON MD5 = "md5"
toJSON SHA1 = "sha1"
toJSON SHA256 = "sha256"
toJSON (TimeStamp utcTime) = toJSON utcTime
----------------------------------------------------------------------------
instance FromJSON ChecksumAlgorithm where
parseJSON = withText name $ \txt ->
case txt of
"md5" -> pure MD5
"sha1" -> pure SHA1
"sha256" -> pure SHA256
s -> typeMismatch name (toJSON s)
where
name = getName (Proxy @ChecksumAlgorithm)
----------------------------------------------------------------------------
data StackFrame
= StackFrame
{ stackFrameId :: Int
-- ^
-- An identifier for the stack frame. It must be unique across all threads.
-- This id can be used to retrieve the scopes of the frame with the `scopes`
-- request or to restart the execution of a stack frame.
--
, stackFrameName :: Text
-- ^
-- The name of the stack frame, typically a method name.
--
, stackFrameSource :: Maybe Source
-- ^
-- The source of the frame.
--
, stackFrameLine :: Int
-- ^
-- The line within the source of the frame. If the source attribute is missing
-- or doesn't exist, `line` is 0 and should be ignored by the client.
--
, stackFrameColumn :: Int
-- ^
-- Start position of the range covered by the stack frame. It is measured in
-- UTF-16 code units and the client capability `columnsStartAt1` determines
-- whether it is 0- or 1-based. If attribute `source` is missing or doesn't
-- exist, `column` is 0 and should be ignored by the client.
--
, stackFrameEndLine :: Maybe Int
-- ^
-- The end line of the range covered by the stack frame.
--
, stackFrameEndColumn :: Maybe Int
-- ^
-- End position of the range covered by the stack frame. It is measured in
-- UTF-16 code units and the client capability `columnsStartAt1` determines
-- whether it is 0- or 1-based.
--
, stackFrameCanRestart :: Maybe Bool
-- ^
-- Indicates whether this frame can be restarted with the `restart` request.
-- Clients should only use this if the debug adapter supports the `restart`
-- request and the corresponding capability `supportsRestartRequest` is true.
-- If a debug adapter has this capability, then `canRestart` defaults to
-- `true` if the property is absent.
--
, stackFrameInstructionPointerReference :: Maybe Text
-- ^
-- A memory reference for the current instruction pointer in this frame.
--
, stackFrameModuleId :: Maybe (Either Int Text)
-- ^
-- The module associated with this frame, if any.
--
, stackFramePresentationHint :: Maybe PresentationHint
-- ^
-- A hint for how to present this frame in the UI.
-- A value of `label` can be used to indicate that the frame is an artificial
-- frame that is used as a visual label or separator. A value of `subtle` can
-- be used to change the appearance of a frame in a 'subtle' way.
-- Values: 'normal', 'label', 'subtle'
--
} deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
defaultStackFrame :: StackFrame
defaultStackFrame
= StackFrame
{ stackFrameId = 0
, stackFrameName = mempty
, stackFrameSource = Nothing
, stackFrameLine = 0
, stackFrameColumn = 0
, stackFrameEndLine = Nothing
, stackFrameEndColumn = Nothing
, stackFrameCanRestart = Nothing
, stackFrameInstructionPointerReference = Nothing
, stackFrameModuleId = Nothing
, stackFramePresentationHint = Nothing
}
----------------------------------------------------------------------------
instance ToJSON StackFrame where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
data Thread
= Thread
{ threadId :: Int
-- ^ Unique identifier for the thread.
--
, threadName :: Text
-- ^ The name of the thread.
--
} deriving stock (Show, Eq, Generic)
----------------------------------------------------------------------------
defaultThread :: Thread
defaultThread
= Thread
{ threadId = 0
, threadName = "<main>"
}
----------------------------------------------------------------------------
instance ToJSON Thread where
toJSON = genericToJSONWithModifier
----------------------------------------------------------------------------
instance FromJSON Thread where
parseJSON = genericParseJSONWithModifier
----------------------------------------------------------------------------
defaultCapabilities :: Capabilities
defaultCapabilities = capabilities
where
capabilities = Capabilities
{ supportsConfigurationDoneRequest = False
, supportsFunctionBreakpoints = False
, supportsConditionalBreakpoints = False
, supportsHitConditionalBreakpoints = False
, supportsEvaluateForHovers = False
, exceptionBreakpointFilters = []
, supportsStepBack = False
, supportsSetVariable = False
, supportsRestartFrame = False
, supportsGotoTargetsRequest = False
, supportsStepInTargetsRequest = False
, supportsCompletionsRequest = False
, completionTriggerCharacters = []
, supportsModulesRequest = False
, additionalModuleColumns = []
, supportedChecksumAlgorithms = []
, supportsRestartRequest = False
, supportsExceptionOptions = False
, supportsValueFormattingOptions = False
, supportsExceptionInfoRequest = False
, supportTerminateDebuggee = False
, supportSuspendDebuggee = False
, supportsDelayedStackTraceLoading = False
, supportsLoadedSourcesRequest = False
, supportsLogPoints = False
, supportsTerminateThreadsRequest = False
, supportsSetExpression = False
, supportsTerminateRequest = False
, supportsDataBreakpoints = False
, supportsReadMemoryRequest = False
, supportsWriteMemoryRequest = False
, supportsDisassembleRequest = False
, supportsCancelRequest = False
, supportsBreakpointLocationsRequest = False
, supportsClipboardContext = False
, supportsSteppingGranularity = False
, supportsInstructionBreakpoints = False
, supportsExceptionFilterOptions = False
, supportsSingleThreadExecutionRequests = False
}
----------------------------------------------------------------------------
data Capabilities
= Capabilities
{ supportsConfigurationDoneRequest :: Bool
-- ^ The debug adapter supports the `configurationDone` request.
--
, supportsFunctionBreakpoints :: Bool
-- ^ The debug adapter supports function breakpoints.
--
, supportsConditionalBreakpoints :: Bool
-- ^ The debug adapter supports conditional breakpoints.
--
, supportsHitConditionalBreakpoints :: Bool
-- ^ The debug adapter supports breakpoints that break execution after a
-- specified number of hits.
--
, supportsEvaluateForHovers :: Bool
-- ^ The debug adapter supports a (side effect free) `evaluate` request for data
-- hovers.
--
, exceptionBreakpointFilters :: [ExceptionBreakpointsFilter]
-- ^ Available exception filter options for the `setExceptionBreakpoints`
-- ^ request.
--
, supportsStepBack :: Bool
-- ^ The debug adapter supports stepping back via the `stepBack` and
-- ^ `reverseContinue` requests.
--
, supportsSetVariable :: Bool
-- ^ The debug adapter supports setting a variable to a value.
--
, supportsRestartFrame :: Bool
-- ^ The debug adapter supports restarting a frame.
--
, supportsGotoTargetsRequest :: Bool
-- ^ The debug adapter supports the `gotoTargets` request.
--
, supportsStepInTargetsRequest :: Bool
-- ^ The debug adapter supports the `stepInTargets` request.
--
, supportsCompletionsRequest :: Bool
-- ^ The debug adapter supports the `completions` request.
--
, completionTriggerCharacters :: [Text]
-- ^ The set of characters that should trigger completion in a REPL. If not
-- ^ specified, the UI should assume the `.` character.
--
, supportsModulesRequest :: Bool
-- ^ The debug adapter supports the `modules` request.
--
, additionalModuleColumns :: [ColumnDescriptor]
-- ^ The set of additional module information exposed by the debug adapter.
--
, supportedChecksumAlgorithms :: [ChecksumAlgorithm]
-- ^ Checksum algorithms supported by the debug adapter.
--
, supportsRestartRequest :: Bool
-- ^ The debug adapter , supports the `restart` request. In this case a client
-- ^ should not implement `restart` by terminating and relaunching the adapter
-- ^ but by calling the `restart` request.
--
, supportsExceptionOptions :: Bool
-- ^ The debug adapter , supports `exceptionOptions` on the
-- ^ `setExceptionBreakpoints` request.
--
, supportsValueFormattingOptions :: Bool
-- ^ The debug adapter , supports a `format` attribute on the `stackTrace`,
-- ^ `variables`, and `evaluate` requests.
--
, supportsExceptionInfoRequest :: Bool
-- ^ The debug adapter , supports the `exceptionInfo` request.
--
, supportTerminateDebuggee :: Bool
-- ^ The debug adapter , supports the `terminateDebuggee` attribute on the `disconnect` request.
--
, supportSuspendDebuggee :: Bool
-- ^ The debug adapter , supports the `suspendDebuggee` attribute on the `disconnect` request.
--
, supportsDelayedStackTraceLoading :: Bool
-- ^ The debug adapter , supports the delayed loading of parts of the stack, which
-- ^ requires that both the `startFrame` and `levels` arguments and the
-- ^ `totalFrames` result of the `stackTrace` request are supported.
--
, supportsLoadedSourcesRequest :: Bool
-- ^ The debug adapter , supports the `loadedSources` request.
--
, supportsLogPoints :: Bool
-- ^ The debug adapter , supports log points by interpreting the `logMessage`
-- ^ attribute of the `SourceBreakpoint`.
--
, supportsTerminateThreadsRequest :: Bool
-- ^ The debug adapter , supports the `terminateThreads` request.
--
, supportsSetExpression :: Bool
-- ^ The debug adapter , supports the `setExpression` request.
--
, supportsTerminateRequest :: Bool
-- ^ The debug adapter , supports the `terminate` request.
--
, supportsDataBreakpoints :: Bool
-- ^ The debug adapter , supports data breakpoints.
--
, supportsReadMemoryRequest :: Bool
-- ^ The debug adapter , supports the `readMemory` request.
--
, supportsWriteMemoryRequest :: Bool
-- ^ The debug adapter , supports the `writeMemory` request.
--
, supportsDisassembleRequest :: Bool
-- ^ The debug adapter , supports the `disassemble` request.
--
, supportsCancelRequest :: Bool
-- ^ The debug adapter , supports the `cancel` request.
--
, supportsBreakpointLocationsRequest :: Bool
-- ^ The debug adapter , supports the `breakpointLocations` request.
--
, supportsClipboardContext :: Bool
-- ^ The debug adapter , supports the `clipboard` context value in the `evaluate`
-- request.
--
, supportsSteppingGranularity :: Bool
-- ^ The debug adapter , supports stepping granularities (argument `granularity`)
-- for the stepping requests.
--
, supportsInstructionBreakpoints :: Bool
-- ^ The debug adapter , supports adding breakpoints based on instruction
-- references.
--
, supportsExceptionFilterOptions :: Bool
-- ^ The debug adapter , supports `filterOptions` as an argument on the
-- `setExceptionBreakpoints` request.
--
, supportsSingleThreadExecutionRequests :: Bool
-- ^ The debug adapter , supports the `singleThread` property on the execution
-- requests (`continue`, `next`, `stepIn`, `stepOut`, `reverseContinue`,
-- `stepBack`).
--
} deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON)
----------------------------------------------------------------------------
data EventType
= EventTypeInitialized
| EventTypeStopped
| EventTypeContinued
| EventTypeExited
| EventTypeTerminated
| EventTypeThread
| EventTypeOutput
| EventTypeBreakpoint
| EventTypeModule
| EventTypeLoadedSource
| EventTypeProcess
| EventTypeCapabilities
| EventTypeProgressStart
| EventTypeProgressUpdate
| EventTypeProgressEnd
| EventTypeInvalidated
| EventTypeMemory
| EventTypeCustom Text
deriving stock (Show, Eq, Read, Generic)
----------------------------------------------------------------------------
instance ToJSON EventType where
toJSON (EventTypeCustom e) = toJSON e
toJSON e = genericToJSONWithModifier e
----------------------------------------------------------------------------
data Command
= CommandCancel
| CommandInitialize
| CommandConfigurationDone
| CommandLaunch
| CommandAttach
| CommandRestart
| CommandDisconnect
| CommandTerminate
| CommandBreakpointLocations
| CommandSetBreakpoints
| CommandSetFunctionBreakpoints
| CommandSetExceptionBreakpoints
| CommandDataBreakpointInfo
| CommandSetDataBreakpoints
| CommandSetInstructionBreakpoints
| CommandContinue
| CommandNext
| CommandStepIn
| CommandStepOut
| CommandStepBack
| CommandReverseContinue
| CommandRestartFrame
| CommandGoTo
| CommandPause
| CommandStackTrace
| CommandScopes
| CommandVariables
| CommandSetVariable
| CommandSource
| CommandThreads
| CommandTerminateThreads
| CommandModules
| CommandLoadedSources
| CommandEvaluate
| CommandSetExpression
| CommandStepInTargets
| CommandGoToTargets
| CommandCompletions
| CommandExceptionInfo
| CommandReadMemory
| CommandWriteMemory
| CommandDisassemble
| CustomCommand Text
deriving stock (Show, Eq, Read, Generic)
----------------------------------------------------------------------------
instance FromJSON Command where
parseJSON = withText name $ \command ->
case readMaybe (name <> capitalize (T.unpack command)) of
Just cmd ->
pure cmd
Nothing ->
pure (CustomCommand command)
where
name = show (typeRep (Proxy @Command))
----------------------------------------------------------------------------
instance ToJSON Command where
toJSON (CustomCommand x) = toJSON x
toJSON cmd = genericToJSONWithModifier cmd
----------------------------------------------------------------------------
data ReverseCommand
= ReverseCommandRunInTerminal
| ReverseCommandStartDebugging
deriving stock (Show, Eq, Read, Generic)
----------------------------------------------------------------------------
instance FromJSON ReverseCommand where
parseJSON = withText name $ \command ->
case readMaybe (name <> capitalize (T.unpack command)) of
Just cmd ->
pure cmd
Nothing ->
fail $ "Unknown reverse command: " ++ show command
where
name = show (typeRep (Proxy @ReverseCommand))
----------------------------------------------------------------------------
instance ToJSON ReverseCommand where