Skip to content
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

Update apiview token prefix #9230

Merged
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
3 changes: 3 additions & 0 deletions src/dotnet/APIView/APIView/Model/V2/ReviewLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ private string ToString(bool includeAllTokens)
return string.Empty;
}
StringBuilder sb = new();
bool spaceAdded = false;
foreach (var token in filterdTokens)
{
sb.Append(token.HasPrefixSpace == true && !spaceAdded ? " " : string.Empty);
sb.Append(token.Value);
sb.Append(token.HasSuffixSpace == true ? " " : string.Empty);
spaceAdded = token.HasSuffixSpace == true;
}
return sb.ToString();
}
Expand Down
4 changes: 4 additions & 0 deletions src/dotnet/APIView/APIView/Model/V2/ReviewToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public ReviewToken(string value, TokenKind kind)
/// Set this to false if there is no suffix space required before next token. For e.g, punctuation right after method name
/// </summary>
public bool HasSuffixSpace { get; set; } = true;
/// <summary>
/// Set this to true if there is a prefix space required before current token.
/// </summary>
public bool HasPrefixSpace { get; set; } = false;

/// <summary>
/// Set isDocumentation to true if current token is part of documentation
Expand Down

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ private static CodePanelRowData GetCodePanelRowData(CodePanelData codePanelData,
}
}

bool spaceAdded = false;
// Convert ReviewToken to UI required StructuredToken
foreach (var token in reviewLine.Tokens)
{
if (token.HasPrefixSpace == true && !spaceAdded)
{
var spaceToken = StructuredToken.CreateSpaceToken();
spaceToken.Value = " ";
tokensInRow.Add(spaceToken);
}
var structuredToken = new StructuredToken(token);
tokensInRow.Add(structuredToken);

Expand All @@ -268,6 +275,11 @@ private static CodePanelRowData GetCodePanelRowData(CodePanelData codePanelData,
var spaceToken = StructuredToken.CreateSpaceToken();
spaceToken.Value = " ";
tokensInRow.Add(spaceToken);
spaceAdded = true;
}
else
{
spaceAdded = false;
}
}
return codePanelRowData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@
"default": true,
"description": "Set this to false if there is no suffix space required before next token. For e.g, punctuation right after method name"
},
"HasPrefixSpace": {
"type": "boolean",
"default": false,
"description": "Set this to true if there is a prefix space required before current token. For e.g, space before token for ="
},
"IsDocumentation": {
"type": "boolean",
"default": false,
Expand Down
13 changes: 12 additions & 1 deletion tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ model ReviewToken {
IsDeprecated?: boolean = false;
/** Set this to false if there is no suffix space required before next token. For e.g, punctuation right after method name */
HasSuffixSpace?: boolean = true;
/** Set this to true if there is a prefix space required before current token. For e.g, space before token for = */
HasPrefixSpace?: boolean = false;
/** Set isDocumentation to true if current token is part of documentation */
IsDocumentation?: boolean = false;
/** Language specific style css class names */
Expand All @@ -78,7 +80,7 @@ model ReviewToken {
model CodeDiagnostic {
/** Diagnostic ID is auto generated ID by CSharp analyzer. */
DiagnosticId?: string;
/** Id of ReviewLine object where this diagnostic needs to be displayed */
/** Id of ReviewLine object where this diagnostic needs to be displayed */
TargetId: string;
/** Auto generated system comment to be displayed under targeted line. */
Text: string;
Expand All @@ -87,13 +89,22 @@ model CodeDiagnostic {
}

enum TokenKind {
/** Text: Token kind should be set as Text for any plan text token. for e.g documentation, namespace value, or attribute or decorator tokens **/
Text: 0,
/** Punctuation **/
Punctuation: 1,
/** Keyword **/
Keyword: 2,
/** TypeName: Kind should be set as TypeName for class definitions, base class token, parameter types etc **/
TypeName: 3,
/** MemberName: Kind should be set as MemberName for method name tokens, member variable tokens **/
MemberName: 4,
/** StringLiteral: Token kind for any metadata or string literals to show in API view **/
StringLiteral: 5,
/** Literal: Token kind for any literals, for e.g. enum value or numerical constant literal or default value **/
Literal: 6,
/** Comment: Comment text within the code that's really a documentation.
* Few languages wants to show comments within API review that's not tagged as documentation **/
Comment: 7
}

Expand Down