luttje / glua-api-snippets

Scrapes the Garry's Mod Wiki in order to build Lua Language Server comments that will provide IDE suggestions and autocompletion.
MIT License
18 stars 6 forks source link

Inconsistent ordering of method definitions #48

Closed luttje closed 7 months ago

luttje commented 7 months ago

I believe a bug may have been introduced in #42. It causes methods to be ordered inconsistently. Probably because we're now scraping the wiki multiple pages at a time, causing for inconsistent load results between scrapes.

It's most noticeable when you compare recent commit changes: https://github.com/luttje/glua-api-snippets/commit/4af9755c9657221ea8d6294aace24496aab884e7 (which show a large amount of changes occurring) to those from before #42. These show only changes to the wiki data, without reordering methods: https://github.com/luttje/glua-api-snippets/commit/bd6de32d69108e1e68fbaa516f42fa4145cdd811

Additionally this bug causes the following side-effect, where some method definitions are placed before the local ContentIcon = {}: https://github.com/luttje/glua-api-snippets/blob/4af9755c9657221ea8d6294aace24496aab884e7/library/contenticon.lua

@robotboy655 Would love your feedback, do you recognize an easy fix? I'm thinking a sort somewhere might solve this issue, e.g: in here: https://github.com/luttje/glua-api-snippets/blob/b443e9f8534f9ece0bd5a0fbb0a0b3474c12a3a2/src/api-writer/glua-api-writer.ts#L73

robotboy655 commented 7 months ago

It is something I also noticed, but didn't think it would be a problem, ultimately.

I imagine easiest way to solve this would be to also supply the expected order to write page (https://github.com/luttje/glua-api-snippets/blob/main/src/cli-scraper.ts#L121) in addition to the file name, store it, and then sort pages before writing them.

As for the "method definitions are placed before the local ContentIcon = {}:" issue, I guess this only affects panels since they do not write a fallback class definition? Should be easily fixable though.

luttje commented 7 months ago

@robotboy655 Thanks for picking this up. Just confirming that comparing the most recent commit to one from two weeks ago helpfully shows changes made to the content (and doesn't reorder): https://github.com/luttje/glua-api-snippets/compare//bd6de32d69108e1e68fbaa516f42fa4145cdd811...lua-language-server-addon So all is good again + even beter since all the new changes you made.

Thanks for implementing the fix the clean way you did and with the speed you did it!