Skip to content

Add more comments #1993

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Add more comments #1993

wants to merge 18 commits into from

Conversation

Bashamega
Copy link
Contributor

related to #1940
Hello:)
In my last PR I have used MDN to generate comments for interface declarations, in this pr I add it for the properties.

Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@Bashamega
Copy link
Contributor Author

Bashamega commented Apr 23, 2025

Not ready for review
Ready for review

Copy link
Contributor

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm yet to review this, but please do not convert to sync APIs.

@Bashamega
Copy link
Contributor Author

I'm yet to review this, but please do not convert to sync APIs.

Sure

@Bashamega
Copy link
Contributor Author

Bashamega commented Apr 23, 2025

Hello @saschanaz
I have switched the old functions to async, but the new function is still sync because the emitter is not async. I tried switching it to async, but it broke.

@@ -13,10 +13,7 @@ interface URLSearchParamsIterator<T> extends IteratorObject<T, BuiltinIteratorRe

interface URLSearchParams {
[Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
/** Returns an array of key, value pairs for every entry in the search params. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a loss?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This because the iterators don't have mdn links. So I have fixed it by adding the comments json back just for the iterators.

@@ -906,7 +907,10 @@ export function emitWebIdl(
comments.push("Available only in secure contexts.");
}
if (entity.mdnUrl) {
if (comments.length > 0) comments.push("");
if (comments.length == 0) {
comments.push(extractSummaryFromFile(entity.mdnUrl));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emitter should just emit the typescript lib based on the given data, rather than generating data. Any required generation should be done in build.ts and passed to this function.

const relativePath = url
.replace("https://developer.mozilla.org/docs/", "")
.split("#")[0]
.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should compute the path rather than using the URL this way. Basically for Foo.bar the path should be /api/foo/bar/index.md.

And why do we need this when we already have generateDescriptions above that collects index files?

@Bashamega
Copy link
Contributor Author

I have updated the context to not call the API in the emitter, but that cause the test to fail, I will fix it later

@Bashamega
Copy link
Contributor Author

Done @saschanaz

Comment on lines +910 to +921
if (comments.length == 0) {
const key = entity.mdnUrl
.split("/API/")
.pop()
?.replace("/", ".")
.split("#")[0]
.toLowerCase();
if (key && descriptions[key]) {
comments.push(descriptions[key]);
}
}
comments.push("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of processing should also be done outside emitter, namely here:

function mergeApiDescriptions(
idl: Browser.WebIdl,
descriptions: Record<string, string>,
) {
const namespaces = arrayToMap(
idl.namespaces!,
(i) => i.name,
(i) => i,
);
for (const [key, value] of Object.entries(descriptions)) {
const target = idl.interfaces!.interface[key] || namespaces[key];
if (target) {
target.comment = value;
}
}
return idl;
}

) {
const exposed = getExposedTypes(webidl, options.global, forceKnownTypes);
mergeNamesakes(exposed);
exposed.events = webidl.events;

const result = emitWebIdl(
const result = await emitWebIdl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emitWebidl is not async anymore.

console.error("Error reading directories:", error);
return [];
}
return sentenceMatch ? sentenceMatch[0] : normalizedText.split(" ")[0] || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing too much in one line. Multiple lines are often easier to read.

try {
const content = await fs.readFile(fileURL, "utf-8");

const titleMatch = content.match(/title:\s*["']?([^"'\n]+)["']?/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep this processing done in a separate function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants