Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hover): format numbers correctly #71

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading