Irrelevant Chatter
I haven't updated my blog for a long time, so I'll write an article using the readme I wrote after remaking the problem-solving repository!
Recently, I plan to get rid of my current Z4 extreme space and build a NAS with better performance. I will also provide an x86 remote development environment for ARM Mac. I might update a series of articles describing my process of tinkering in the near future, so stay tuned!~
Main Text
Recently, I had the urge to do some problem-solving. When I opened the problem-solving repository using vscode, I found that there were several issues with the previous directory structure:
- The folders were in Chinese, which caused go mod to not recognize them (the reason the unit tests were working before was because Goland would copy the tests to a temporary directory with only English characters).
- Many old problem descriptions did not include the built-in data types, causing syntax errors even after renaming the folders and recognizing them correctly.
So I decided to let go of the past and remove all the previous code. This remake is mainly to ensure that:
- When opening the problem-solving repository directory, all files can be recognized correctly.
- Each file has its own unit test that can be run in batches.
Implementation:
- Create a Golang project in the root directory of the project.
go mod init github.com/amtoaer/leetcode
- Install the vscode-leetcode plugin by labuladong.
- Set the problem-solving language to Go and set the file save directory to the root directory of the project.
"leetcode.workspaceFolder": "/Users/amtoaer/Documents/code/go/go-leetcode", "leetcode.defaultLanguage": "golang",
- Set the specific path for file saving (in English without spaces) and the file template with unit tests.
Note:
The existing LeetCode extension does not support using the English name of the problem as a variable. Therefore, to achieve the effect of using an English path, the problem translation needs to be turned off.
"leetcode.useEndpointTranslation": false,
"leetcode.filePath": {
"default": {
"folder": "${id}.${camelCaseName}",
"filename": "solution_test.${ext}"
}
},
"leetcode.codeTemplate": "package main\n\nimport (\n\t\"testing\"\n)\n\n${code}\n\nfunc Test(t *testing.T) {\n}",
- Gofmt does not limit line length, so there may be lines of code that are too long. Use golines for code formatting instead.
"editor.formatOnSave": true, "go.alternateTools": { "customFormatter": "/Users/amtoaer/.go/bin/golines" }, "go.formatTool": "custom"
Here are a few screenshots of problem-solving after configuration:
-
Problem-solving in the editor
-
Normal code completion
-
Running unit tests
-
Running unit tests in batches
What? You're asking if I wrote the test cases myself?
Of course not! Copilot will do that work for you. Just type assert.Equal, press tab a few times, and you'll have all the test cases!