Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Work on checkline logic.
  • Loading branch information
tjprescott committed Nov 8, 2024
commit cc7692549f8f05c8a20a2fc403dbeff9ed6c5cc2
12 changes: 3 additions & 9 deletions tools/apiview/emitters/typespec-apiview/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
namespace Azure.Test {

op GetFoo is ResourceRead<
{
@doc("The name")
name: string;
},
{
parameters:
{
@doc("The collection id.")
fooId: string;
};
}
Expand All @@ -28,8 +23,7 @@ namespace Azure.Test {

// op GetFoo is ResourceRead<string, string>;

op ResourceRead<TResource, TParams>(
resource: TResource,
params: TParams
): TResource;
op ResourceRead<T>(
params: T
): void;
}
29 changes: 18 additions & 11 deletions tools/apiview/emitters/typespec-apiview/src/apiview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,24 @@ export class ApiView {
}
}

private getLastNonBlankLine(): ReviewLine | undefined {
if (this.currentLine.Tokens.length > 0) {
return this.currentLine;
private getLastLine(line: ReviewLine | undefined): ReviewLine | undefined {
if (!line) {
return undefined;
}
const lastLine = line.Children[line.Children.length - 1];
if (lastLine.Children.length > 0) {
return this.getLastLine(lastLine);
}
// FIXME: Need to recursively search
return this.currentParent?.Children[this.currentParent.Children.length - 1];
return lastLine
}

private removeLastNonBlankLine() {
// FIXME: Need to recursively search
this.currentParent?.Children.pop();
private removeLastLine(line: ReviewLine) {
const lastLine = line.Children[line.Children.length - 1];
if (lastLine.Children.length > 0) {
this.removeLastLine(lastLine);
} else {
line.Children.pop();
}
}

/** Chomps whitespace to any of the provided characters. If the first non-whitespace
Expand All @@ -260,7 +267,7 @@ export class ApiView {
private trimTo(characters: string) {
const allowed = new Set(characters.split(""));
const trimCurrent = (this.currentLine.Tokens.length !== 0);
const checkLine = trimCurrent ? this.currentLine : this.getLastNonBlankLine();
const checkLine = trimCurrent ? this.currentLine : this.getLastLine(this.currentParent);
if (!checkLine) {
return;
}
Expand All @@ -284,8 +291,8 @@ export class ApiView {
this.currentLine = checkLine;
this.currentLine.Tokens = trimmedTokens;
// get rid of the current last child since it's now currentLine
if (!trimCurrent) {
this.removeLastNonBlankLine();
if (!trimCurrent && this.currentParent) {
this.removeLastLine(this.currentParent);
}
}
return;
Expand Down