hyprland/module: deduplicate verify-config output and add json format for check

parent 841688ec
......@@ -40,6 +40,13 @@ func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error {
return err
}
if config.IsJSON(cmd) {
if result == nil {
result = []HyprConfigError{}
}
return ui.PrintJSON(result)
}
if len(result) == 0 {
color.Green(locale.T("No errors"))
return nil
......@@ -90,6 +97,14 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
return err
}
if config.IsJSON(cmd) {
jsonErrors := make([]ModuleErrorJSON, len(result))
for i, e := range result {
jsonErrors[i] = ModuleErrorJSON{Line: e.Line, Text: e.Text}
}
return ui.PrintJSON(jsonErrors)
}
if len(result) == 0 {
color.Green(locale.T("No errors"))
return nil
......
......@@ -41,6 +41,7 @@ func CommandList() *cli.Command {
{
Name: "check",
Usage: locale.T("Check the Hyprland config"),
Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandCheckCommand,
},
{
......@@ -77,6 +78,7 @@ func CommandList() *cli.Command {
Name: "check",
Usage: locale.T("Check Hyprland module"),
ArgsUsage: "module",
Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandModuleCheckCommand,
ShellComplete: ShellCompleteModule("all"),
},
......
......@@ -61,9 +61,9 @@ type HyprPlugin struct {
}
type HyprConfigError struct {
File string
Line int
Text string
File string `json:"file"`
Line int `json:"line"`
Text string `json:"text"`
}
func NewHyprlandManager() (*HyprlandManager, error) {
......@@ -1052,7 +1052,17 @@ func (m *HyprlandManager) parseCheckOutput(out []byte) []HyprConfigError {
})
}
return res
// Дедупликация: Hyprland может дублировать ошибки из source-файлов
seen := make(map[string]bool)
deduped := make([]HyprConfigError, 0, len(res))
for _, e := range res {
key := fmt.Sprintf("%s:%d:%s", e.File, e.Line, e.Text)
if !seen[key] {
seen[key] = true
deduped = append(deduped, e)
}
}
return deduped
}
func (m *HyprlandManager) removeLine(lineNumber int) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment