Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Protocol/Models/FormattingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FormattingOptions : Dictionary<string, BooleanNumberString>
[JsonIgnore]
public long TabSize
{
get => this["tabSize"].IsLong ? this["tabSize"].Long : -1;
get => TryGetValue("tabSize", out var tabSize) && tabSize.IsLong ? tabSize.Long : -1;
set => this["tabSize"] = value;
}

Expand All @@ -25,7 +25,7 @@ public long TabSize
[JsonIgnore]
public bool InsertSpaces
{
get => this["insertSpaces"].IsBool ? this["insertSpaces"].Bool : false;
get => TryGetValue("insertSpaces", out var insertSpaces) && insertSpaces.IsBool && insertSpaces.Bool;
set => this["insertSpaces"] = value;
}

Expand All @@ -37,7 +37,7 @@ public bool InsertSpaces
[JsonIgnore]
public bool TrimTrailingWhitespace
{
get => this["trimTrailingWhitespace"].IsBool ? this["trimTrailingWhitespace"].Bool : false;
get => TryGetValue("trimTrailingWhitespace", out var trimTrailingWhitespace) && trimTrailingWhitespace.IsBool && trimTrailingWhitespace.Bool;
set => this["trimTrailingWhitespace"] = value;
}

Expand All @@ -49,7 +49,7 @@ public bool TrimTrailingWhitespace
[JsonIgnore]
public bool InsertFinalNewline
{
get => this["insertFinalNewline"].IsBool ? this["insertFinalNewline"].Bool : false;
get => TryGetValue("insertFinalNewline", out var insertFinalNewline) && insertFinalNewline.IsBool && insertFinalNewline.Bool;
set => this["insertFinalNewline"] = value;
}

Expand All @@ -61,7 +61,7 @@ public bool InsertFinalNewline
[JsonIgnore]
public bool TrimFinalNewlines
{
get => this["trimFinalNewlines"].IsBool ? this["trimFinalNewlines"].Bool : false;
get => TryGetValue("trimFinalNewlines", out var trimFinalNewlines) && trimFinalNewlines.IsBool && trimFinalNewlines.Bool;
set => this["trimFinalNewlines"] = value;
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/Lsp.Tests/Models/FormattingOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
Expand All @@ -24,5 +25,27 @@ public void SimpleTest(string expected)
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<FormattingOptions>(expected);
deresult.Should().BeEquivalentTo(model);
}

[Fact]
public void Should_Not_Require_A_Value_To_Be_Defined()
{
var model = new FormattingOptions();
model.InsertSpaces.Should().BeFalse();
model.TabSize.Should().Be(-1L);
model.InsertFinalNewline.Should().BeFalse();
model.TrimFinalNewlines.Should().BeFalse();
model.TrimTrailingWhitespace.Should().BeFalse();
}

[Fact]
public void Should_Allow_Values_To_Be_Set()
{
var model = new FormattingOptions();
model.InsertSpaces = true;
model.TabSize = 4;
model.InsertFinalNewline = true;
model.TrimFinalNewlines = true;
model.TrimTrailingWhitespace = true;
}
}
}