Skip to content

Commit

Permalink
fix(hover): format numbers correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Apr 1, 2024
1 parent c004c5b commit 0565edf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions internal/handler/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ func (h *langHandler) formatToYAML(field reflect.Value, fieldName string) string
return h.toYAML(map[string]interface{}{fieldName: field.Interface()})
case reflect.Bool:
return fmt.Sprint(h.getBoolType(field))
case reflect.Float32, reflect.Float64:
return fmt.Sprint(field.Float())
default:
logger.Error("Unknown kind for hover type: ", field.Kind())
return "<Unknown>"
}
}
16 changes: 7 additions & 9 deletions internal/handler/hover_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestHoverMain(t *testing.T) {
Line: 25,
Character: 28,
},
expected: fmt.Sprintf("### %s\n%s\n\n", filepath.Join("..", "..", "testdata", "example", "values.yaml"), "imagePullSecrets: []\n"),
expected: fmt.Sprintf("### %s\n%s\n\n\n", filepath.Join("..", "..", "testdata", "example", "values.yaml"), "imagePullSecrets: []"),
expectedError: nil,
},
{
Expand Down Expand Up @@ -96,13 +96,13 @@ func TestHoverMain(t *testing.T) {
expectedError: nil,
},
{
desc: "Test not existing values list",
desc: "Test hover values number",
position: lsp.Position{
Line: 101,
Character: 35,
Line: 8,
Character: 28,
},
expected: "",
expectedError: fmt.Errorf("Could not parse ast correctly"),
expected: fmt.Sprintf("### %s\n%s\n\n", filepath.Join("..", "..", "testdata", "example", "values.yaml"), "1"),
expectedError: nil,
},
}
for _, tt := range testCases {
Expand Down Expand Up @@ -139,9 +139,7 @@ func TestHoverMain(t *testing.T) {
},
})
assert.Equal(t, tt.expectedError, err)
if err == nil {
assert.Equal(t, tt.expected, result.Contents.Value)
}
assert.Equal(t, tt.expected, result.Contents.Value)
})
}
}
22 changes: 22 additions & 0 deletions internal/handler/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ middleValue
### ` + filepath.Join("charts", "subchart", "charts", "subsubchart", "values.yaml") + `
value
`,
wantErr: false,
},
{
name: "Formatting of number",
args: args{
chart: &charts.Chart{
ChartMetadata: &charts.ChartMetadata{},
ValuesFiles: &charts.ValuesFiles{
MainValuesFile: &charts.ValuesFile{
Values: map[string]interface{}{
"key": float64(1.2345),
},
URI: "file://tmp/values.yaml",
},
},
},
splittedVar: []string{"key"},
},
want: `### values.yaml
1.2345
`,
wantErr: false,
},
Expand Down

0 comments on commit 0565edf

Please sign in to comment.