Skip to content
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

Custom file name template #166

Closed
fhyoga opened this issue Feb 28, 2019 · 45 comments
Closed

Custom file name template #166

fhyoga opened this issue Feb 28, 2019 · 45 comments
Labels
enhancement New feature or request
Milestone

Comments

@fhyoga
Copy link

fhyoga commented Feb 28, 2019

考虑支持自定义的文件名吗?

比如 中文版生成的文件名含有中文,import一个中文文件,感觉不是很靠谱,所以每次都要手动修改。

我觉得,文件名最好支持模版插值,可以取{tag}{difficulty}等几个meta信息填充,这样也可以满足不同人的需求。

@jdneo
Copy link
Member

jdneo commented Feb 28, 2019

@poppinlp Guessing this might be a regression in #149

If the user is using Chinese version LeetCode, the file name we generated will contain Chinese

@fhyoga
Copy link
Author

fhyoga commented Feb 28, 2019

@poppinlp Guessing this might be a regression in #149

If the user is using Chinese version LeetCode, the file name we generated will contain Chinese

I think these two issues are not the same function, maybe you didn't understand what I meant. I am suggesting to add a configuration item, just like outputFolder, does not affect the reading of local files.

@fhyoga
Copy link
Author

fhyoga commented Feb 28, 2019

Setting Name Description Default Value
fileName The name of the generated file;{id}-{difficulty}-{tag}-{name} {id}.{name}.{ext}

like this? @jdneo

@poppinlp
Copy link
Contributor

@jdneo
I have not tested on the Chinese version LeetCode. That's my fault. I'll fix it and think about the test cases.

@Dec-F
Yep. You are talking about a different feature. I think I get your point.
What's your option about this? @jdneo I think this feature is reasonable but not high priority.

@fhyoga
Copy link
Author

fhyoga commented Feb 28, 2019

If this feature is necessary, I will submit a PR tomorrow or weekend. What do you think? @jdneo @poppinlp

@jdneo
Copy link
Member

jdneo commented Feb 28, 2019

@poppinlp Not your fault, we all missed that part, It's great if this can be fixed.

@Dec-F PR is welcome, you can send out it whenever you want.

@poppinlp
Copy link
Contributor

@jdneo I've sent a PR to fix the Chinese file name issue.

@jdneo @Dec-F Here maybe a plan to support the file name pattern:

We could pass the whole config into the genFileName function instead of the only endpoint right now to avoid too many params. And then generate the file name by the pattern in the setting. And don't forget to update the documents after that.

The variable in pattern could be:

  • id
  • name
  • difficulty
  • ext
  • companies(join the array in kebabcase?)
  • tags(join the array in kebabcase?)

@jdneo
Copy link
Member

jdneo commented Mar 1, 2019

For a certain problem, it may belong to multiple companies and tags, how to handle this scenario?

@Dec-F One thing I missed is that we prefer to discussing the implementation before sending the PR, free feel to share your thoughts.

@poppinlp
Copy link
Contributor

poppinlp commented Mar 1, 2019

On the one side, if we wanna support company and tag, of course, the tags and companies could be an array. So we may just merge the array items with a separate symbol such as underscore, dash, e.t.c.

On the other side, I think the first question is what should we support company and tag? For me, there's no such need. But maybe there could be a situation for others that they wanna grep the files by company name or tag. I'm not really sure about this. So I listed them and look forward to opinions.

BTW, there may be some risks that if the tags of a problem changed then the local source code could be missed.

@fhyoga
Copy link
Author

fhyoga commented Mar 1, 2019

I think there are two ways to deal with it.

  1. Let the user choose. Treat like this
  2. fileName option Support function, handed to user programming

What do you think?

@jdneo

This comment has been minimized.

@jdneo
Copy link
Member

jdneo commented Aug 2, 2019

@magic-akari This is the issue.

I think the outputFolder and the fileName could be combined into one setting. Like leetcode.relativeFilePath.

@magic-akari
Copy link
Contributor

I think the outputFolder and the fileName could be combined into one setting. Like leetcode.relativeFilePath.

Does this mean that outputFolder will be deprecated?

@jdneo
Copy link
Member

jdneo commented Aug 2, 2019

Yes. Make it deprecated and stop honor this setting in the future.

For now, we will honor both outputFolder and relativeFilePath. If the user set both two settings, relativeFilePath wins.

@magic-akari
Copy link
Contributor

magic-akari commented Aug 2, 2019

I prefer the following config format

{
    "leetcode.relativeFilePath": {
        "default": "{language}/{id}.{kebab-case-name}.{ext}",
        "java": "java/src/{id}-{BigCamelCaseName}/main.{ext}",
        "cpp": "cpp/src/{id}-{smallCamelCaseName}.cc",
        "rust": "src/p{id}_{snake_case_name}.{ext}"
    }
}

kebab-case-namesnake_case_name 这种写法都很夸张,这里只是举个例子。
还需要具体讨论应该用什么字段。

@jdneo
Copy link
Member

jdneo commented Aug 2, 2019

@magic-akari 可以简单一下,第一阶段先不考虑不同语言的命名习惯,今后可以根据不同语言生成不同样式的文件名。需要支持的变量可以有:

  • ${id}
  • ${difficulty}
  • ${tag}
  • ${name}

另一个问题,怎么比较好地区分folder和filename. 举例来说,有一个用户他只想自定义文件夹路径,但是使用了该配置项之后,他必须把文件名格式也补全。感觉似乎不是一个很好的用户体验

@magic-akari
Copy link
Contributor

另一个问题,怎么比较好地区分folder和filename. 举例来说,有一个用户他只想自定义文件夹路径,但是使用了该配置项之后,他必须把文件名格式也补全。感觉似乎不是一个很好的用户体验

什么都不设置,会用 default 设置吧,最开始的时候生成一个。
倒是可以考虑不废弃 outputFolder,然后把 relativeFilePath 接在 outputFolder 后边,但是这样做同样是令人困惑的。

@jdneo
Copy link
Member

jdneo commented Aug 2, 2019

不废弃 outputFolder 的话,那么setting名称就是fileName了。让我再想一想这个 experience 应该是怎么样的

@magic-akari
Copy link
Contributor

magic-akari commented Aug 2, 2019

第一阶段先不考虑不同语言的命名习惯,今后可以根据不同语言生成不同样式的文件名。需要支持的变量可以有:

其实我就是因为遇到了命名的问题,才来这里寻找解决办法的。
比如现在默认的命名,有的语言没办法导入这种数字开头命名的文件。想导入函数做测试的时候就遇到麻烦了。

其实 snake case 之类的,这个也不难做。

@fhyoga
Copy link
Author

fhyoga commented Aug 2, 2019

I think that merging into a configuration may not be a good idea. Atomic configuration understanding costs may be lower.
A good example is the path and filename in the webpack output configuration.

@magic-akari
Copy link
Contributor

magic-akari commented Aug 2, 2019

或者平铺这些设置,

{
    "leetcode.relativeFilePath.default": "{language}/{id}.{kebab-case-name}.{ext}",
    "leetcode.relativeFilePath.java": "java/src/{id}-{camelCaseName}/main.{ext}",
    "leetcode.relativeFilePath.cpp": "cpp/src/{id}-{PascalCaseName}.cc",
    "leetcode.relativeFilePath.rust": "src/p{id}_{snake_case_name}.{ext}"
}

@jdneo
Copy link
Member

jdneo commented Aug 2, 2019

I agree with @Dec-F's opinion. It makes me confused to merge outputFolder and fileName. IMO, the splitted setting leetcode.fileName makes more sense.

@magic-akari
Copy link
Contributor

magic-akari commented Aug 2, 2019

如果分开设置 filename 和 outputFolder,为每个语言设置独立的输出就会遇到困难。
我觉得每个语言可独立设置还是挺重要的,毕竟有的语言对名称有要求,或者在特定的结构目录下写起来会更顺手。

@jdneo
Copy link
Member

jdneo commented Aug 3, 2019

I don't get your point. Why splitting filename and outputFolder will make it different to generate different name style for different language?

@magic-akari
Copy link
Contributor

magic-akari commented Aug 4, 2019

Let's have a try.
We split the output config into filename and path. Now we have to write the following configuration.

{
    "leetcode.output.default.path": "...",
    "leetcode.output.default.filename": "...",
    "leetcode.output.java.path": "...",
    "leetcode.output.java.filename": "...",
    "leetcode.output.cpp.path": "...",
    "leetcode.output.cpp.filename": "...",
    "leetcode.output.rust.path": "...",
    "leetcode.output.rust.filename": "..."
}

or

{
    "leetcode.output.default": {
        "path": "",
        "filename": ""
    },
    "leetcode.output.java": {
        "path": "",
        "filename": ""
    },
    "leetcode.output.cpp": {
        "path": "",
        "filename": ""
    },
    "leetcode.output.rust": {
        "path": "",
        "filename": ""
    }
}

There is too much noise in the first one.
The second, we cannot write config in vscode settings UI.

@jdneo
Copy link
Member

jdneo commented Aug 5, 2019

@magic-akari Yes, I agree with your point. But one thing we need to figure out is how to make this setting easy to understand. Because actually we combined two settings into one. What if:

  • The user only want to set the folder
  • Or the user only want to set the file name

Things will become tricky during the implementation, because we have to guess which part is for folder and which part is for the file name.

@magic-akari
Copy link
Contributor

  • The user only want to set the folder
  • Or the user only want to set the file name

We can set the default value of leetcode.relativeFilePath.default.
It's easy to change it in vscode settings UI.

image

It will be logically equivalent to the current project.

@jdneo
Copy link
Member

jdneo commented Aug 5, 2019

So what's the expected behavior if the user set leetcode.relativeFilePath.java to: com.leetcode.problems. Or even com.leetcode.java(for folder name)

@magic-akari
Copy link
Contributor

Do you mean com.leetcode.problems/${id}.${camelCaseName}.${ext} ?
Copy the deafult value and paste it into Java input.
These efforts are required when the user needs to set it up.

@jdneo
Copy link
Member

jdneo commented Aug 5, 2019

I mean, the user only want to set the folder path. So he set it to com.leetcode.problems or even com.leetcode.java. How will the extension know that this is for the file name or its just a folder name.

@magic-akari
Copy link
Contributor

我们应该让用户输入完整的路径。而不是允许输入部分,然后猜测用户要做什么。
使用默认值的时候,用户什么都不需要做,一切逻辑和现在的项目逻辑等价。

当用户真的有需求,要改变某个语言的输出文件夹的时候,从默认值哪里复制粘贴出${id}.${camelCaseName}.${ext},然后在前边补上路径。
需要个性化设置,不至于这一点努力都不愿意付出吧。

@magic-akari
Copy link
Contributor

或许,有什么其他更方便的方法?
但是我觉得这样是最明确,不含糊的。

@magic-akari
Copy link
Contributor

magic-akari commented Aug 5, 2019

要么,放弃直接在 vscode settings UI 更改设置的便利。

{
    "leetcode.output": {
        "default": {
            "path": "...",
            "filename": "..."
        },
        "java": {
            "path": "...",
            "filename": "..."
        },
        "cpp": {
            "path": "...",
            "filename": "..."
        },
        "rust": {
            "path": "...",
            "filename": "..."
        }
    }
}

用户需要点击 Edit in settings.json

@jdneo
Copy link
Member

jdneo commented Aug 5, 2019

要么,放弃直接在 vscode settings UI 更改设置的便利。

{
    "leetcode.output": {
        "default": {
            "path": "...",
            "filename": "..."
        },
        "java": {
            "path": "...",
            "filename": "..."
        },
        "cpp": {
            "path": "...",
            "filename": "..."
        },
        "rust": {
            "path": "...",
            "filename": "..."
        }
    }
}

用户需要点击 Edit in settings.json

This might be something worth considering. But by calling leetcode.output. I'm worrying that some users might get confused with leetcode.workspaceFolder.

@magic-akari
Copy link
Contributor

This might be something worth considering. But by calling leetcode.output. I'm worrying that some users might get confused with leetcode.workspaceFolder.

名字不是重要的,最后由你来拍版决定。现在需要确定这种设置的结构能否接受。

@jdneo
Copy link
Member

jdneo commented Aug 5, 2019

Hmm, please give me some time to think about it. @Dec-F Do you have any feedback?

@fhyoga
Copy link
Author

fhyoga commented Aug 5, 2019

Hmm, please give me some time to think about it. @Dec-F Do you have any feedback?

guaranteed atomic configuration is a very important factor. The template variables contain language information. You can customize the complete path and cover all languages. I don't think there is any problem.

@jdneo
Copy link
Member

jdneo commented Aug 6, 2019

@Dec-F Thanks.

@magic-akari Could you list all the variables that you want to support first?

@magic-akari
Copy link
Contributor

请看这里
https://github.com/jdneo/vscode-leetcode/pull/380/files#diff-4f863ca9b6092167a0e40548789c2f3aR209-R230

我有个疑问。关于 tag 和 company.
现在的逻辑是,在多个值中选一个,然后生成文件。这里存在问题。

如果用户点击 code now 后,选择不同的值,就会新生成一个文件,而不是打开之前创建的。
我对这种行为感到困惑。

@jdneo
Copy link
Member

jdneo commented Aug 6, 2019

这确实是一个问题。关于多tag的情况你有什么好的建议吗?

@imindzzz
Copy link

我很需要这个功能。 我需要把文件名的改为 1-two-sum.cpp 。 因为如果是1.two-sum.cpp的话,编译输出的可执行文件是1.two-sum,tow-sum 会被当成后缀名,执行失败。

@magic-akari
Copy link
Contributor

关于 tag 和 company 这种多 tag 的情况,我并没有什么好的想法或者解决方案。
因为我的需求里并不包含这两个。
如果能够了解需要这两个 tag 的人,他们的需求是什么,问题也许就能明晰一些了。

@fhyoga
Copy link
Author

fhyoga commented Aug 21, 2019

Has anyone started to implement this feature?

Recently I have some time to try to complete this feature, so I want to know if someone is already doing it, so as not to repeat the work.

@jdneo
Copy link
Member

jdneo commented Aug 22, 2019

Hi @Dec-F,

I was busy with other stuff these days. Sorry for that I did not respond to this issue in time.

Actually @magic-akari has provided a PR #380 for this, which I haven't been able to take a look so far. Maybe you can take a look and provide your thoughts?

@jdneo
Copy link
Member

jdneo commented Sep 14, 2019

Resolved in #380 by @magic-akari .

Nice job!

@jdneo jdneo closed this as completed Sep 14, 2019
@jdneo jdneo added this to the 0.15.4 milestone Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants