Skip to content

Commit

Permalink
fix parsing complex rulers objects in user settings, fix #488
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Oct 15, 2024
1 parent 0c7fe66 commit b5138ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
11 changes: 6 additions & 5 deletions source/served/commands/format.d
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ string[] generateDfmtArgs(const ref UserConfiguration config, EolType overrideEo
{
int maxLineLength = 120;
int softMaxLineLength = 80;
if (config.editor.rulers.length == 1)
auto rulers = config.editor.parseRulers;
if (rulers.length == 1)
{
softMaxLineLength = maxLineLength = config.editor.rulers[0];
softMaxLineLength = maxLineLength = rulers[0];
}
else if (config.editor.rulers.length >= 2)
else if (rulers.length >= 2)
{
maxLineLength = config.editor.rulers[$ - 1];
softMaxLineLength = config.editor.rulers[$ - 2];
maxLineLength = rulers[$ - 1];
softMaxLineLength = rulers[$ - 2];
}
ResolvedFormattingOptions options = gFormattingOptions;
//dfmt off
Expand Down
26 changes: 25 additions & 1 deletion source/served/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,32 @@ struct Configuration
struct Editor
{
@serdeOptional:
int[] rulers;
JsonValue[] rulers;
int tabSize;

int[] parseRulers() const
{
int[] ret;
foreach (value; rulers)
{
switch (value.kind)
{
case JsonValue.Kind.object:
auto obj = value.get!(StringMap!JsonValue);
if (auto v = "column" in obj)
{
ret ~= cast(int) v.get!long;
}
break;
case JsonValue.Kind.integer:
ret ~= cast(int) value.get!long;
break;
default:
break;
}
}
return ret;
}
}

struct Git
Expand Down

0 comments on commit b5138ca

Please sign in to comment.