Skip to content

Commit 18fdee7

Browse files
fix it itests
- Update configFileTemplate to include necessary runtimes when no tools are specified - Enhance error handling for retrieving supported tools - Ensure tools are listed with their versions only if a version is available - Adjust sorting logic for runtimes and tools for better organization
1 parent d3fff03 commit 18fdee7

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

cmd/init.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ func configFileTemplate(tools []tools.Tool) string {
203203
if len(tools) > 0 {
204204
// Create a sorted slice of runtimes
205205
var sortedRuntimes []string
206-
for runtime := range runtimeVersions {
207-
if neededRuntimes[runtime] {
208-
sortedRuntimes = append(sortedRuntimes, runtime)
209-
}
206+
for runtime := range neededRuntimes {
207+
sortedRuntimes = append(sortedRuntimes, runtime)
210208
}
211209
sort.Strings(sortedRuntimes)
212210

@@ -215,9 +213,27 @@ func configFileTemplate(tools []tools.Tool) string {
215213
sb.WriteString(fmt.Sprintf(" - %s@%s\n", runtime, runtimeVersions[runtime]))
216214
}
217215
} else {
218-
// In local mode with no tools specified, include all runtimes
216+
// In local mode with no tools specified, include only the necessary runtimes
217+
supportedTools, err := plugins.GetSupportedTools()
218+
if err != nil {
219+
log.Printf("Warning: failed to get supported tools: %v", err)
220+
return sb.String()
221+
}
222+
223+
// Get runtimes needed by supported tools
224+
for toolName := range supportedTools {
225+
if runtime, ok := runtimeDependencies[toolName]; ok {
226+
if toolName == "dartanalyzer" {
227+
neededRuntimes["dart"] = true
228+
} else {
229+
neededRuntimes[runtime] = true
230+
}
231+
}
232+
}
233+
234+
// Create a sorted slice of runtimes
219235
var sortedRuntimes []string
220-
for runtime := range runtimeVersions {
236+
for runtime := range neededRuntimes {
221237
sortedRuntimes = append(sortedRuntimes, runtime)
222238
}
223239
sort.Strings(sortedRuntimes)
@@ -266,14 +282,19 @@ func configFileTemplate(tools []tools.Tool) string {
266282
// Convert map keys to slice and sort them
267283
for toolName := range supportedTools {
268284
if version, ok := defaultVersions[toolName]; ok {
269-
sortedTools = append(sortedTools, fmt.Sprintf("%s@%s", toolName, version))
285+
// Skip tools without a version
286+
if version != "" {
287+
sortedTools = append(sortedTools, toolName)
288+
}
270289
}
271290
}
272291
sort.Strings(sortedTools)
273292

274293
// Write sorted tools
275-
for _, tool := range sortedTools {
276-
sb.WriteString(fmt.Sprintf(" - %s\n", tool))
294+
for _, toolName := range sortedTools {
295+
if version, ok := defaultVersions[toolName]; ok {
296+
sb.WriteString(fmt.Sprintf(" - %s@%s\n", toolName, version))
297+
}
277298
}
278299
}
279300

0 commit comments

Comments
 (0)