-
Notifications
You must be signed in to change notification settings - Fork 683
feat: support load code from local file for issue 59 #149
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
Conversation
src/utils/problemUtils.ts
Outdated
| export function genFileName(node: IProblem, language: string): string { | ||
| const name: string = kebabCase(node.name); | ||
| const ext: string | undefined = langExt.get(language); | ||
| return `${node.id}.${name}.${ext}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext here might be undefined. Though according to current logic, it's impossible.
I think you can have another util method here to parse the ext from a language name. Meanwhile, throw an error if the language is not supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I'll fix it.
| @@ -0,0 +1,8 @@ | |||
| import kebabCase = require("lodash.kebabcase"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use import instead of require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of the issue of lodash. T_T
Another way is to change the tsconfig.json. But I think its impact may be even bigger, so I wrote it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it's fine.
src/leetCodeExecutor.ts
Outdated
| public async showProblem(node: IProblem, language: string, outDir: string): Promise<string> { | ||
| const fileName: string = genFileName(node, language); | ||
| const filePath: string = path.join(outDir, fileName); | ||
| const hasLocalCode: boolean = await fse.pathExists(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasLocalCode is redundant. We can move await fse.pathExists(filePath) into the if block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
jdneo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to fix the linting error.
Overall the idea is clear and promising!
|
I'm sorry for the lint error. T_T |
jdneo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@poppinlp Thank you for the contribution. Nice job! I'll send out another PR to add you the contributors.. |
This RP is for #59. The main logic change is that
showProblemoperation will try to load local code first. Here are the changes:lodash.kebabcasein dependencies to generate a sluglangExtinshared.tsto do the extension mapping for languageproblemUtils.tswhich contains utils for problemshowProbleminleetCodeExecutor.tswill return the code file path right now