Skip to content

Commit 744860f

Browse files
committed
add DebuggerDisplay
1 parent 22e9eea commit 744860f

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

src/Types.cg.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace rec Ionide.LanguageServerProtocol.Types
22

3+
open System
4+
open System.Diagnostics
5+
open Newtonsoft.Json
36
/// URI’s are transferred as strings. The URI’s format is defined in https://tools.ietf.org/html/rfc3986
47
///
58
/// See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#uri
@@ -3409,6 +3412,7 @@ type LocationLink =
34093412
/// end : { line 6, character : 0 }
34103413
/// }
34113414
/// ```
3415+
[<DebuggerDisplay("{DebuggerDisplay}")>]
34123416
type Range =
34133417
{
34143418
/// The range's start position.
@@ -3417,6 +3421,9 @@ type Range =
34173421
End: Position
34183422
}
34193423

3424+
[<DebuggerBrowsable(DebuggerBrowsableState.Never); JsonIgnore>]
3425+
member x.DebuggerDisplay = $"{x.Start.DebuggerDisplay}-{x.End.DebuggerDisplay}"
3426+
34203427
type ImplementationOptions =
34213428
{ WorkDoneProgress: bool option }
34223429

@@ -3534,6 +3541,7 @@ type DeclarationOptions =
35343541
/// that denotes `\r|\n` or `\n|` where `|` represents the character offset.
35353542
///
35363543
/// @since 3.17.0 - support for negotiated position encoding.
3544+
[<DebuggerDisplay("{DebuggerDisplay}")>]
35373545
type Position =
35383546
{
35393547
/// Line position in a document (zero-based).
@@ -3551,6 +3559,9 @@ type Position =
35513559
Character: uint32
35523560
}
35533561

3562+
[<DebuggerBrowsable(DebuggerBrowsableState.Never); JsonIgnore>]
3563+
member x.DebuggerDisplay = $"({x.Line},{x.Character})"
3564+
35543565
type SelectionRangeOptions =
35553566
{ WorkDoneProgress: bool option }
35563567

@@ -4480,6 +4491,7 @@ type FileSystemWatcher =
44804491

44814492
/// Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
44824493
/// are only valid in the scope of a resource.
4494+
[<DebuggerDisplay("{DebuggerDisplay}")>]
44834495
type Diagnostic =
44844496
{
44854497
/// The range at which the message applies
@@ -4514,6 +4526,10 @@ type Diagnostic =
45144526
Data: LSPAny option
45154527
}
45164528

4529+
[<DebuggerBrowsable(DebuggerBrowsableState.Never); JsonIgnore>]
4530+
member x.DebuggerDisplay =
4531+
$"[{defaultArg x.Severity DiagnosticSeverity.Error}] ({x.Range.DebuggerDisplay}) {x.Message} ({Option.map string x.Code |> Option.defaultValue String.Empty})"
4532+
45174533
/// Contains additional information about the context in which a completion request is triggered.
45184534
type CompletionContext =
45194535
{

src/Types.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,34 @@ type ErasedUnionAttribute() =
2323
type U2<'T1, 'T2> =
2424
| C1 of 'T1
2525
| C2 of 'T2
26+
override x.ToString() =
27+
match x with
28+
| C1 c -> string c
29+
| C2 c -> string c
2630

2731
[<ErasedUnion>]
2832
type U3<'T1, 'T2, 'T3> =
2933
| C1 of 'T1
3034
| C2 of 'T2
3135
| C3 of 'T3
36+
override x.ToString() =
37+
match x with
38+
| C1 c -> string c
39+
| C2 c -> string c
40+
| C3 c -> string c
3241

3342
[<ErasedUnion>]
3443
type U4<'T1, 'T2, 'T3, 'T4> =
3544
| C1 of 'T1
3645
| C2 of 'T2
3746
| C3 of 'T3
3847
| C4 of 'T4
48+
override x.ToString() =
49+
match x with
50+
| C1 c -> string c
51+
| C2 c -> string c
52+
| C3 c -> string 3
53+
| C4 c -> string 3
3954

4055

4156
type LspResult<'t> = Result<'t, JsonRpc.Error>

tests/GenerateTests.fs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,51 @@ module GenerateTests =
484484
| Some x -> sprintf "%s %s" s x
485485
| None -> s
486486

487+
let range_debuggerDisplay (r : WidgetBuilder<TypeDefnRecordNode>) =
488+
r
489+
.attribute(
490+
Attribute("DebuggerDisplay(\"{DebuggerDisplay}\")")
491+
)
492+
.members () {
493+
Property("x.DebuggerDisplay", "$\"{x.Start.DebuggerDisplay}-{x.End.DebuggerDisplay}\"")
494+
.attributes([
495+
Attribute("DebuggerBrowsable(DebuggerBrowsableState.Never)")
496+
Attribute("JsonIgnore")
497+
])
498+
}
499+
500+
let position_debuggerDisplay (r : WidgetBuilder<TypeDefnRecordNode>) =
501+
r
502+
.attribute(
503+
Attribute("DebuggerDisplay(\"{DebuggerDisplay}\")")
504+
)
505+
.members () {
506+
Property("x.DebuggerDisplay", "$\"({x.Line},{x.Character})\"")
507+
.attributes ([
508+
Attribute("DebuggerBrowsable(DebuggerBrowsableState.Never)")
509+
Attribute("JsonIgnore")
510+
])
511+
}
512+
513+
let diagnostic_debuggerDisplay (r : WidgetBuilder<TypeDefnRecordNode>) =
514+
r
515+
.attribute(
516+
Attribute("DebuggerDisplay(\"{DebuggerDisplay}\")")
517+
)
518+
.members () {
519+
Property("x.DebuggerDisplay", "$\"[{defaultArg x.Severity DiagnosticSeverity.Error}] ({x.Range.DebuggerDisplay}) {x.Message} ({Option.map string x.Code |> Option.defaultValue String.Empty})\"")
520+
.attributes ([
521+
Attribute("DebuggerBrowsable(DebuggerBrowsableState.Never)")
522+
Attribute("JsonIgnore")
523+
])
524+
}
525+
526+
let debuggerDisplays =
527+
Map [
528+
"Range", range_debuggerDisplay
529+
"Position", position_debuggerDisplay
530+
"Diagnostic", diagnostic_debuggerDisplay
531+
]
487532

488533
let handleSameShapeStructuredUnions path createField (ts: MetaModel.Type array) =
489534
if
@@ -979,6 +1024,12 @@ module GenerateTests =
9791024
structure.StructuredDocs
9801025
|> Option.map (fun docs -> r.xmlDocs docs)
9811026
|> Option.defaultValue r
1027+
1028+
let r =
1029+
debuggerDisplays
1030+
|> Map.tryFind structure.Name
1031+
|> Option.map(fun f -> f r)
1032+
|> Option.defaultValue r
9821033

9831034
match implementInterface structure with
9841035
| [||] -> r
@@ -1262,7 +1313,9 @@ See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17
12621313
let source =
12631314
Ast.Oak() {
12641315
Namespace("Ionide.LanguageServerProtocol.Types") {
1265-
1316+
Open("System")
1317+
Open("System.Diagnostics")
1318+
Open("Newtonsoft.Json")
12661319
// Simple aliases for types that are not in dotnet
12671320
Abbrev("URI", "string")
12681321
.xmlDocs (
@@ -1347,4 +1400,4 @@ See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17
13471400

13481401

13491402
[<Tests>]
1350-
let tests = ftestList "Generate" [ generateTests ]
1403+
let tests = ptestList "Generate" [ generateTests ]

0 commit comments

Comments
 (0)