Random Thoughts#
I haven't updated my blog for a long time. I'll just write an article using the readme I wrote after remaking the problem-solving repository!
Recently, I plan to get rid of my current Z4 workspace and build a NAS with better performance myself, while also providing an x86 remote development environment for the ARM-based Mac. I might possibly 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 with vscode, I found that there were quite a few issues with the previous directory structure:
- The folders were in Chinese, which caused go mod to not recognize them (the reason why the unit tests were working fine before was because Goland would copy the tests to a temporary directory with only English characters).
- Many of the old problem's built-in data types were not included, 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. The main purpose of this remake is 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 project's root directory.
"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, so in order to achieve the effect of using an English path, the translation of the problem 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 some screenshots of the 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 job for you. Just type assert.Equal, press tab a few times, and you'll have all the test cases!