Closed fhyoga closed 5 years ago
@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
@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.
Setting Name | Description | Default Value |
---|---|---|
fileName | The name of the generated file;{id}-{difficulty}-{tag}-{name} | {id}.{name}.{ext} |
like this? @jdneo
@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.
If this feature is necessary, I will submit a PR tomorrow or weekend. What do you think? @jdneo @poppinlp
@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.
@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:
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.
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.
I think there are two ways to deal with it.
What do you think?
@Dec-F Will your request get satisfied if we implement the comment here: https://github.com/jdneo/vscode-leetcode/issues/119#issuecomment-466778120
@magic-akari This is the issue.
I think the outputFolder
and the fileName
could be combined into one setting. Like leetcode.relativeFilePath
.
I think the
outputFolder
and thefileName
could be combined into one setting. Likeleetcode.relativeFilePath
.
Does this mean that outputFolder
will be deprecated?
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.
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-name
和 snake_case_name
这种写法都很夸张,这里只是举个例子。
还需要具体讨论应该用什么字段。
@magic-akari 可以简单一下,第一阶段先不考虑不同语言的命名习惯,今后可以根据不同语言生成不同样式的文件名。需要支持的变量可以有:
另一个问题,怎么比较好地区分folder和filename. 举例来说,有一个用户他只想自定义文件夹路径,但是使用了该配置项之后,他必须把文件名格式也补全。感觉似乎不是一个很好的用户体验
另一个问题,怎么比较好地区分folder和filename. 举例来说,有一个用户他只想自定义文件夹路径,但是使用了该配置项之后,他必须把文件名格式也补全。感觉似乎不是一个很好的用户体验
什么都不设置,会用 default 设置吧,最开始的时候生成一个。 倒是可以考虑不废弃 outputFolder,然后把 relativeFilePath 接在 outputFolder 后边,但是这样做同样是令人困惑的。
不废弃 outputFolder 的话,那么setting名称就是fileName了。让我再想一想这个 experience 应该是怎么样的
第一阶段先不考虑不同语言的命名习惯,今后可以根据不同语言生成不同样式的文件名。需要支持的变量可以有:
其实我就是因为遇到了命名的问题,才来这里寻找解决办法的。 比如现在默认的命名,有的语言没办法导入这种数字开头命名的文件。想导入函数做测试的时候就遇到麻烦了。
其实 snake case 之类的,这个也不难做。
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.
或者平铺这些设置,
{
"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}"
}
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.
如果分开设置 filename 和 outputFolder,为每个语言设置独立的输出就会遇到困难。 我觉得每个语言可独立设置还是挺重要的,毕竟有的语言对名称有要求,或者在特定的结构目录下写起来会更顺手。
I don't get your point. Why splitting filename
and outputFolder
will make it different to generate different name style for different language?
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.
@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:
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.
- 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.
It will be logically equivalent to the current project.
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)
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.
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.
我们应该让用户输入完整的路径。而不是允许输入部分,然后猜测用户要做什么。 使用默认值的时候,用户什么都不需要做,一切逻辑和现在的项目逻辑等价。
当用户真的有需求,要改变某个语言的输出文件夹的时候,从默认值哪里复制粘贴出${id}.${camelCaseName}.${ext}
,然后在前边补上路径。
需要个性化设置,不至于这一点努力都不愿意付出吧。
或许,有什么其他更方便的方法? 但是我觉得这样是最明确,不含糊的。
要么,放弃直接在 vscode settings UI 更改设置的便利。
{
"leetcode.output": {
"default": {
"path": "...",
"filename": "..."
},
"java": {
"path": "...",
"filename": "..."
},
"cpp": {
"path": "...",
"filename": "..."
},
"rust": {
"path": "...",
"filename": "..."
}
}
}
用户需要点击 Edit in settings.json
要么,放弃直接在 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
.
This might be something worth considering. But by calling
leetcode.output
. I'm worrying that some users might get confused withleetcode.workspaceFolder
.
名字不是重要的,最后由你来拍版决定。现在需要确定这种设置的结构能否接受。
Hmm, please give me some time to think about it. @Dec-F Do you have any feedback?
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.
@Dec-F Thanks.
@magic-akari Could you list all the variables that you want to support first?
我有个疑问。关于 tag 和 company. 现在的逻辑是,在多个值中选一个,然后生成文件。这里存在问题。
如果用户点击 code now 后,选择不同的值,就会新生成一个文件,而不是打开之前创建的。 我对这种行为感到困惑。
这确实是一个问题。关于多tag的情况你有什么好的建议吗?
我很需要这个功能。 我需要把文件名的改为 1-two-sum.cpp 。 因为如果是1.two-sum.cpp的话,编译输出的可执行文件是1.two-sum,tow-sum 会被当成后缀名,执行失败。
关于 tag 和 company 这种多 tag 的情况,我并没有什么好的想法或者解决方案。 因为我的需求里并不包含这两个。 如果能够了解需要这两个 tag 的人,他们的需求是什么,问题也许就能明晰一些了。
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.
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?
Resolved in #380 by @magic-akari .
Nice job!
考虑支持自定义的文件名吗?
比如 中文版生成的文件名含有中文,import一个中文文件,感觉不是很靠谱,所以每次都要手动修改。
我觉得,文件名最好支持模版插值,可以取{tag}{difficulty}等几个meta信息填充,这样也可以满足不同人的需求。