Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
jdneo merged 2 commits intoLeetCode-OpenSource:masterfrompoppinlp:issue59
Feb 24, 2019

Conversation

poppinlp
Copy link
Contributor

This RP is for#59. The main logic change is thatshowProblem operation will try to load local code first. Here are the changes:

  • Addlodash.kebabcase in dependencies to generate a slug
  • AddlangExt inshared.ts to do the extension mapping for language
  • AddproblemUtils.ts which contains utils for problem
  • TheshowProblem inleetCodeExecutor.ts will return the code file path right now

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}`;
Copy link
Member

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.

Copy link
ContributorAuthor

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Useimport instead ofrequire.

Copy link
ContributorAuthor

@poppinlppoppinlpFeb 22, 2019
edited
Loading

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK, it's fine.

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);
Copy link
Member

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK.

Copy link
Member

@jdneojdneo left a 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!

@poppinlp
Copy link
ContributorAuthor

I'm sorry for the lint error. T_T

Copy link
Member

@jdneojdneo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@jdneojdneo merged commit7ca9b8a intoLeetCode-OpenSource:masterFeb 24, 2019
@jdneo
Copy link
Member

@poppinlp Thank you for the contribution. Nice job!

I'll send out another PR to add you the contributors..

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jdneojdneojdneo approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@poppinlp@jdneo

[8]ページ先頭

©2009-2025 Movatter.jp