- Notifications
You must be signed in to change notification settings - Fork670
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 beundefined
. Though according to current logic, it's impossible.
I think you can have another util method here to parse theext
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.
Useimport
instead ofrequire
.
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 thetsconfig.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 moveawait 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.
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 |
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
showProblem
operation will try to load local code first. Here are the changes:lodash.kebabcase
in dependencies to generate a sluglangExt
inshared.ts
to do the extension mapping for languageproblemUtils.ts
which contains utils for problemshowProblem
inleetCodeExecutor.ts
will return the code file path right now