LeetCode-OpenSource / vscode-leetcode

Solve LeetCode problems in VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-leetcode
MIT License
8.22k stars 650 forks source link

[FR] TypeScript support for leetcode's built-in data structures 力扣自定义数据结构(如ListNode、TreeNode)的TypeScript支持 #828

Open DarrenDanielDay opened 2 years ago

DarrenDanielDay commented 2 years ago

🚀 Feature Proposal

Add TypeScript type declaration file of leetcode's built-in data structures to the workspace root (such as ~/.leetcode) automatically when users open a leetcode workspace with language typescript.

Motivation

The online editor has correct type inference of leetcode's built-in data structure, such as TreeNode and ListNode. It's reasonable to have the same experience with this vscode extension.

Contribution

I think there already exists a TypeScript declaration file for those built-in data structures for the online editor. Just create a copy of that file via vscode.workspace.fs.writeFile when users open a leetcode workspace with language typescript. Also create a tsconfig.json file if necessary, or just execute npx tsc --init.

More

Support running JavaScript/TypeScript test cases locally, since nodejs 10+ is required for this extension, possibly by using babel to transpile TypeScript code to JavaScript code and calling nodejs API like vm.runInContext to execute the JavaScript code.

DarrenDanielDay commented 2 years ago

I've made my solution for this feature.

Here is the solution repo: https://github.com/DarrenDanielDay/leetcode-typescript-workspace

I'm also trying to make it easier to use, with less extra code. Here is my new idea and PR. demo PR

But the simple parser is not necessary if this extension supports to analyze and run test cases natively! Programmers will play tricks to make software suitable for use until software really meets the user requirements. But it's really really really a waste of time!

DarrenDanielDay commented 2 years ago

翻了一下issue,发现中国用户比较多,外加LeetCode-OpenSource组织位于中国上海,那我也就不强行用我这塑料英语交流了。

简单说下前面的Feature Proposal部分,就是对于习惯使用JavaScript/TypeScript解题的用户提供一些力扣内置数据结构的类型定义。比如ListNodeTreeNode这种,是由力扣自定义的class,线上编辑器有定义,但vscode里就没有还会爆红。可能的实现方法是直接在插件选的放代码的文件夹里直接生成几个类型定义文件,如果必要可以再加个tsconfig.json配置文件配上力扣线上判题的编译配置。然后如果这些都能内置集成,可以顺便附加一个基于nodejs的运行工具和调试配置,沙箱运行代码可以用vm.runInContext

为什么有这种想法呢?因为在线的编辑器里对TypeScript的支持是很好的,目前TypeScript也是线上编辑器里唯一一个能免费用到语法分析、代码提示、类型检查的完整功能的语言。既然免费线上编辑器让咱爽了,为啥免费插件就没了呢?

然后这个issue迟迟没有人回应,于是我做了自己的解决方案,代码仓库是这个: https://github.com/DarrenDanielDay/leetcode-typescript-workspace

然后我自己用得还是不太爽,今天又搞了个解析示例测试用例的parser,写了demo还给自己提了PR: demo PR

但是这parser显然没什么必要,力扣官方肯定有更好的解析用例输入和输出的方法。作为程序员,软件用不爽就会想去hack一些自定义的东西,直到软件本身真正满足了需求。我这么搞真的很浪费时间,希望官方能有更好的方案。

DarrenDanielDay commented 2 years ago

多造一点假的回复是不是就会有人来看呢?

NotEvenANeko commented 1 year ago

感觉这个 repo 是不是没人维护了...快一年没有 commit 了, pr 和 issue 也有一堆 open 的

theashggl commented 1 year ago

I am having this issue in Java language too. VSCode is not able to recognize the ListNode data structure built in and fails to provide basic features like code formatting and suggestions for the code.