chore: use go fix to enhance codebase (#29)
This pull request modernizes the codebase by adopting Go 1.21+ features, including built-in functions like min and max, standard library iterators such as strings.SplitSeq and strings.FieldsSeq, utility functions like maps.Copy and slices.Contains, and string manipulation helpers like strings.Cut and strings.CutPrefix. Feedback is provided on a test file where the usage of strings.Builder can be further optimized to avoid unnecessary string allocations during concatenation. `go fix -diff ./...`
This commit is contained in:
+4
-7
@@ -170,7 +170,7 @@ func runWrapper() {
|
||||
out, errCmd := exec.CommandContext(ctx, "lsof", "-p", fmt.Sprintf("%d", c.Process.Pid), "-a", "-d", "cwd", "-F", "n").Output()
|
||||
cancel()
|
||||
if errCmd == nil {
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
for line := range strings.SplitSeq(string(out), "\n") {
|
||||
if strings.HasPrefix(line, "n") {
|
||||
cwd = strings.TrimSpace(line[1:])
|
||||
linkErr = nil
|
||||
@@ -191,8 +191,8 @@ func runWrapper() {
|
||||
if logDir, pathErr := config.CachePath(); pathErr == nil {
|
||||
argsFile := filepath.Join(logDir, "reload-args")
|
||||
if data, readErr := os.ReadFile(argsFile); readErr == nil {
|
||||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(string(data), "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed != "" {
|
||||
execArgs = append(execArgs, trimmed)
|
||||
@@ -560,10 +560,7 @@ func runWrapper() {
|
||||
activeModeMu.RUnlock()
|
||||
results := MergeResults("", currentMode)
|
||||
if len(results) > 0 {
|
||||
limit := 100
|
||||
if len(results) < limit {
|
||||
limit = len(results)
|
||||
}
|
||||
limit := min(len(results), 100)
|
||||
var historyList []core.Suggestion
|
||||
|
||||
if inputSlice[i+2] == 'A' {
|
||||
|
||||
Reference in New Issue
Block a user