Proposal: Modifying PaperWM to utilize the benefits of TypeScript and LSP #800
Replies: 2 comments 5 replies
-
In general I wouldn't be opposed to this. I also thought about it in the past but I decided that there were to many problems. But if gnome now officially supports this and has a guide for it, it might be worth it. One issue that we will have if we move to typescript is that anyone that the extension will break for anyone that still has the extension installed through the git repo and pulls. But I think that is a minor issue now, since most people probably have it installed through EGO. Regarding the missing Do you have the code pushed somewhere? Then I might take another look at how much is still missing. |
Beta Was this translation helpful? Give feedback.
-
I'm here because I had an idea for a behavior change, went to add it, and immediately missed types very much 😅 @Thesola10 How do you feel about typescript? I'm a big fan of static types. The main benefit compared to doc comments is that when you make (certain types of) mistakes, the type checker will warn you about them, and the code would fail to "compile"* to javascript. I find this significantly reduces the number of cycles of manual testing I need to do. Importantly, it also means the types can't get out of date like doc types do. E.g. Lines 5201 to 5208 in 2b565b2 I'd be happy to help with a transition to Typescript. Most of my professional work has been in typescript (4-5 years depending on how you want to count) and I am very comfortable with all but its most advanced features (E.g. {in/co/contra}variance still sometimes trips me up — usually the error involving "X could be instantiated with a different subtype of Y"). The main risk is around how incomplete the gnome-shell types may be. If we constantly need to suppress errors (e.g. accessing a function which the types don't know exists) then it is significantly less useful and can be a time sink. On the other hand, any improvements we can contribute back upstream help everyone. *Quotes because it mostly just strips the types and outputs the rest verbatim. If we switched to TS and wanted to switch back, it would be a relatively easy process. In general I would not hesitate to maintain javascript code generated by the typescript compiler. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I've been delving into the codes of PaperWM for some time now, trying to implement certain tweaks. However I'm having some difficulties in comprehending and modifying the codes. I've spent much time in navigating back and forth, trying to locate the declaration/initialization of a variable (e.g. its type and available fields) or to figure out the usage of a function or a class (e.g. arguments that an api accepts).
According to GJS Guid/TypeScript and LSP, it is now possible to develop gnome extensions with LSP support, so that editors would provide auto-completion, hover-documentation and diagnostics. I believe most of us are used to coding with code completions and diagnostic warnings so it should help.
Efforts & Problems
As I need the support of LSP for coding, I spared some time trying to let it work. I'm not an expert in TypeScript so what I can do is simply to follow the steps of the guide and to say "wow it works", then navigating to every diagnostic warning and trying to fix it. I renamed every
*.js
file to*.ts
and moved them into thesrc/
directory, and then tweaked a couple of files to eliminate their warnings. Mostly it works as expected:Code completion (screenshot)
API documentation (screenshot)
Still, there are pieces that I can't fix:
Undeclared imports (screenshot)
According to their source codes, I found that the file
utils.js
exists in GNOME Shell/js/misc while does not exist in Gjsify/gnome-shell/src/misc. So there are libraries that do exist in GNOME Shell and can be imported and used, but are not declared in@girs
modules.Next Steps
I believe it's possible to modify PaperWM to use TypeScript but there's still so much work to do. And I think there should be one who's proficient in it to lead this work. At least these tasks should be done in my eyes:
tsconfig.json
,makefile
, etc.install.sh
,uninstall.sh
, etc.*.js
to*.ts
and fix those LSP warnings, solving those undefined imports.I've put forward this proposal with the hope that it will be realized. However, upon further consideration, I recognized my limitations in overcoming all these challenges above. Looking forward to your ideas.
Beta Was this translation helpful? Give feedback.
All reactions