-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1915: Allow result message to be truncated #1932
Changes from 1 commit
e8b3fe6
1887b04
64f3feb
2908166
98e313b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,7 +288,7 @@ public static string GetMessageText(this Result result, ReportingDescriptor rule | |
return GetMessageText(result, rule, concise: false); | ||
} | ||
|
||
public static string GetMessageText(this Result result, ReportingDescriptor rule, bool concise = false) | ||
public static string GetMessageText(this Result result, ReportingDescriptor rule, bool concise = false, int maxLength = 200) | ||
{ | ||
if (result == null) | ||
{ | ||
|
@@ -333,6 +333,10 @@ public static string GetMessageText(this Result result, ReportingDescriptor rule | |
if (concise) | ||
{ | ||
text = GetFirstSentence(text); | ||
if (text.Length > maxLength) | ||
{ | ||
text = text.Substring(0, maxLength) + "..."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why aren't you using the ellipsis char? #Resolved |
||
} | ||
} | ||
|
||
return text; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,5 +113,29 @@ public void SarifExtensions_Result_GetMessageText_Concise() | |
string actual = result.GetMessageText(rule, concise: true); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void SarifExtensions_Result_GetMessageText_Concise_Truncated() | ||
{ | ||
var result = new Result | ||
{ | ||
Message = new Message | ||
{ | ||
Id = "ruleStr1" | ||
} | ||
}; | ||
|
||
var rule = new ReportingDescriptor | ||
{ | ||
MessageStrings = new Dictionary<string, MultiformatMessageString> | ||
{ | ||
["ruleStr1"] = new MultiformatMessageString { Text = "First sentence is very long. Second sentence." } | ||
} | ||
}; | ||
|
||
const string Expected = "First sentence is ve..."; | ||
string actual = result.GetMessageText(rule, concise: true, maxLength: 20); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compute this from your expected value (length - length of your trailing dots or ellipses. #Resolved |
||
Assert.Equal(Expected, actual); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is 120 or 128 a better default? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I filed the issue I said 120; when I coded it, I worried it was too short. But OK, anybody who calls the API and decides it's not enough can always increase it.
In reply to: 445546182 [](ancestors = 445546182)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key question is 'too short for what'? i.e., under what circumstances would someone be likely to request a concise string and expect something around 200 characters. If you have a scenario in mind, let me know. I've mostly been thinking about flat list views in IDEs as a driver for this API, or work item titles. In these contexts, 200 chars seems more than what's required. Open to thinking about other UX scenarios if you have one.
In reply to: 445558418 [](ancestors = 445558418,445546182)