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

fix: reenable codegen for CF & codegen quality improve #11524

Merged
merged 7 commits into from
May 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ts = require("typescript");
import { fetchRawFileContent } from "./utils";
import { SampleData } from "./samples/sampleData";
import { DocParagraph, DocPlainText, TSDocParser } from "@microsoft/tsdoc";
import { DocLinkTag, DocParagraph, DocPlainText, TSDocParser } from "@microsoft/tsdoc";

export class DeclarationFinder {
private static DECLARATION_FILE_NAME = "office-js.d.ts";
Expand Down Expand Up @@ -128,6 +128,14 @@
}

private getDocCommentAndSummary(node: ts.Node): { docComment: string; summary: string } {
// For the comments, we'd like to get the summary section of the comments. For example:
// /**
// * Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
// * @param properties A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
// * @param options Provides an option to suppress errors if the properties object tries to set any read-only properties.
// */
// We expect to get the summary section of the comments, like:
// "Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type."
const sourceFile = this.definionFile;
const commentRanges = ts.getLeadingCommentRanges(sourceFile!.text, node.pos);
const comments: string | undefined = commentRanges
Expand All @@ -144,9 +152,19 @@
while (!summarySectionNext.done) {
const node = summarySectionNext.value;
if (node.kind === "PlainText") {
// Deal with the plain text in the summary section. Like:
// "Gets the first note item in this collection. Throws an `ItemNotFound` error if this collection is empty."
description += (node as DocPlainText).text.trim().replace("`", "'") + " ";
}
if (node.kind === "LinkTag") {
const link = node as DocLinkTag;

Check warning on line 160 in packages/vscode-extension/src/officeChat/common/declarationFinder.ts

View check run for this annotation

Codecov / codecov/patch

packages/vscode-extension/src/officeChat/common/declarationFinder.ts#L160

Added line #L160 was not covered by tests
if (link.linkText) {
description += " " + link.linkText + " ";

Check warning on line 162 in packages/vscode-extension/src/officeChat/common/declarationFinder.ts

View check run for this annotation

Codecov / codecov/patch

packages/vscode-extension/src/officeChat/common/declarationFinder.ts#L162

Added line #L162 was not covered by tests
}
}
if (node.kind === "Paragraph") {
// dealing with comments has extra content beyond pure text (link, for example), like:
// "Contains a collection of {@link Word.NoteItem} objects."
const paragraph = node as DocParagraph;
const paragraphIterator = paragraph.nodes.values();
let paragraphNext = paragraphIterator.next();
Expand All @@ -156,6 +174,22 @@
description +=
(paragraphNode as unknown as DocPlainText).text.trim().replace("`", "'") + " ";
}
// dealing with links in the paragraph, like:
// "{@link Word.NoteItem}"
// It will get the Word.NoteItem from the link.
if (paragraphNode.kind === "LinkTag") {
const link = paragraphNode as DocLinkTag;
let plainText = "";
if (link.codeDestination) {
const parts = link.codeDestination.memberReferences.map(
(memberReference) => memberReference.memberIdentifier?.identifier
);
plainText += parts.join(".");
} else {
plainText += link.linkText || "";
}
description += ` ${plainText} `;
}
paragraphNext = paragraphIterator.next();
}
}
Expand Down
Loading
Loading