Skip to content

Address Gemini feedback about handling falsy values - #6077

Merged
DanTup merged 1 commit into
interactive-formsfrom
interactive-forms-gemini-feedback
Jun 22, 2026
Merged

DanTup merged 1 commit into
interactive-formsfrom
interactive-forms-gemini-feedback

Conversation

@DanTup

@DanTup DanTup commented Jun 8, 2026

Copy link
Copy Markdown
Member

@h9jiang this is the only thing in Gemini's feedback that seemed like a an issue to me - handling of 0/empty for number/string fields (we could convert an empty submission into a 0, and convert a 0/empty back into the default).

I think these changes make sense, but I wonder if we should specify more explicitly how optional questions should be handled by the client?

For example with this change, I think we will submit null for an "empty" submission of a Number field, but we would still submit an empty string for a String field. We could convert the empty string also to a null?

@DanTup DanTup added this to the v3.138.0 milestone Jun 8, 2026
@DanTup DanTup added is enhancement An enhancement or improvement that should be listed in release notes but is not a bug fix. in editor Relates to code editing or language features labels Jun 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the handling of optional and empty inputs for string and number fields in the interactive language client form. Specifically, it refines truthiness checks to explicitly check for undefined and null, and updates the number input validation and return values to correctly handle empty or canceled inputs. A review comment suggests further refining the string input handling to safely convert null values to undefined to prevent potential type violations and runtime issues with InputBoxOptions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

return await vscode.window.showInputBox({
prompt: field.description,
value: prevAnswer ? prevAnswer : field.default,
value: prevAnswer !== undefined ? prevAnswer : field.default,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If prevAnswer or field.default is null (which can happen for optional fields), passing it directly to value will violate the InputBoxOptions type definition (which expects string | undefined) and may cause runtime issues or display "null" in the input box.

We should safely handle null values by converting them to undefined so that the input box remains empty.

Suggested change
value: prevAnswer !== undefined ? prevAnswer : field.default,
value: (prevAnswer !== undefined && prevAnswer !== null) ? prevAnswer : (prevAnswer === null ? undefined : (field.default ?? undefined)),

@codecov

codecov Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.00%. Comparing base (b27254f) to head (aa8b70a).

Files with missing lines Patch % Lines
src/extension/analysis/form.ts 0.00% 10 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           interactive-forms    #6077      +/-   ##
=====================================================
- Coverage              70.02%   70.00%   -0.03%     
=====================================================
  Files                    173      173              
  Lines                  13265    13271       +6     
  Branches                2665     2668       +3     
=====================================================
+ Hits                    9289     9290       +1     
- Misses                  3480     3485       +5     
  Partials                 496      496              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}
if (numResult.trim() === '') {
return null; // null = empty (eg. not answering optional question)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h9jiang hmm, now I'm wondering about this more... If we return null here, should it be added to formAnswers or skipped?

If we say null is used as a signal here to mean "no answer" and then we skip adding it to formAnswers, should the same apply to string fields submitted as an empty string? It might be odd to include those in formAnswers if not doing the same for numbers.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Danny, how about a button on the right top corner like this: (note the -> on the right top corner)

Image

We could use this button to say, user can skip this question and we only render this button when the question is "optional". And if the user hit enter (even it is empty, since empty string is still a valid string), we interpret user intention as an answer so we run our client side validation. (like if this is really a number...) If user hit the skip button then, we consider this as a skip operation and the client will not send this answer to the client.

The following code is generated by Gemini and it seems to meet the requirement. However, we can only render this button for "inputBox" and "quickPick" (which covers every kinds of question except for "file"). IMO, the "ideal" file picker is the native built Quick Open using hot key cmd + p that allows user to fuzzy matching files they are looking for, and this would have support for rendering a "skip" button.

			case 'string':
				return new Promise<string | null | undefined>((resolve) => {
					const inputBox = vscode.window.createInputBox();
					inputBox.prompt = field.description;
					inputBox.placeholder = field.description;
					inputBox.value = prevAnswer !== undefined ? prevAnswer : field.default || '';
					inputBox.ignoreFocusOut = true;
					// 1. Create a custom "Next / Skip" button if the field is not required
					const skipButton: vscode.QuickInputButton = {
						iconPath: new vscode.ThemeIcon('arrow-right'),
						tooltip: 'Skip / Next'
					};
					if (!field.required) {
						inputBox.buttons = [skipButton];
					}
					// 2. Handle button clicks
					inputBox.onDidTriggerButton((button) => {
						if (button === skipButton) {
							// Return null to signify "skipped / not answered"
							resolve(null);
							inputBox.hide();
						}
					});
					// Handle standard submission (Enter key)
					inputBox.onDidAccept(() => {
						resolve(inputBox.value);
						inputBox.hide();
					});
					// Handle cancellation (Escape key)
					inputBox.onDidHide(() => {
						resolve(undefined); // undefined signifies user cancelled the entire flow
						inputBox.dispose();
					});
					inputBox.show();
				});

We will have to make a little bit more change to render the skip button conditionally based on the "required" field but shouldn't be complicated. What do you think?

@DanTup DanTup Jun 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(edit: this comment was posted before the one above was submitted, so it's out of order and I hadn't read it at the time!)

@h9jiang not urgent, just in case you missed it.. this is a question about how to represent skipped optional answers - if you press <enter> on a string input we might get empty string, not null, but on numbers we would presumably want to use null, which feels inconsistent. I think we should specify something so servers/clients agree.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, what I meant was, as long as user hit <enter> we will consider it as an input even it is empty.

In this case, if the user hit <enter> on a string input, we will consider it as an empty string answer. If the user hit <enter> on a number input, we will consider invalid.

If the user want to skip the question, either for string or number, user should click the -> arrow button. The arrow button is only available for optional questions. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but I do wonder if the -> icon is too subtle. Is there any real benefit to distinguishing between empty and skipped? (in a "full dialog" client, I don't imagine this distinction would be made). I also don't imagine that a "required string" field would expect to accept an empty string as a valid supplied value.

So what about just treating any empty inputs as unanswered/skipped? If they are required, they will be rejected during validation and the user forced to provide a value (ofc, if there was a default already entered, pressing <enter> would just have submitted that as the actual value).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DanTup

I do wonder if the -> icon is too subtle.

I think you are correct, this is probably too subtle. I don't have a strong opinion on this, I think what you have described is also very reasonable.

The way I approached this problem is trying to eliminate ambiguity. I don't like "ambiguous" UI or special/default interpretation. But as you mentioned, the UI for -> is just too subtle.

So I would say, comparing between both solutions, the proposal you got is more user friendly. Let's go with that!

@DanTup
DanTup force-pushed the interactive-forms-gemini-feedback branch from 2a3c2bf to 14fbd9f Compare June 10, 2026 11:06
@DanTup DanTup self-assigned this Jun 10, 2026
@DanTup
DanTup force-pushed the interactive-forms branch from 3c83172 to 28f3455 Compare June 16, 2026 14:23
@DanTup
DanTup changed the base branch from interactive-forms to interactive-forms-as-lsl-client-feature June 16, 2026 15:42
@DanTup
DanTup force-pushed the interactive-forms-gemini-feedback branch from 14fbd9f to 45e5e7d Compare June 16, 2026 15:42
Base automatically changed from interactive-forms-as-lsl-client-feature to interactive-forms June 16, 2026 19:07
@DanTup
DanTup force-pushed the interactive-forms-gemini-feedback branch from 45e5e7d to aa8b70a Compare June 16, 2026 19:09

@h9jiang h9jiang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable.

As you have suggested, we should not really expect a question that accept empty string as input. It make sense to interpret empty as zero value for required field, skip for optional field.

Thanks Danny.

@DanTup

DanTup commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

It make sense to interpret empty as zero value for required field, skip for optional field.

I actually think we should not treat empty as zero for numerics either - if a numeric is required and has no default, we should treat empty the same as an invalid number, and force the user to type 0 if that's what they want? (of course, if zero is a reasonable default, the server can provide it as such). WDYT?

@DanTup
DanTup force-pushed the interactive-forms-gemini-feedback branch from aa8b70a to 6be4299 Compare June 22, 2026 09:28
@DanTup

DanTup commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@h9jiang I'll merge this as-is (into the interactive-forms branch) as I'd like to start trying to add some tests around the whole lot. If you think we should change anything based on the last few comments above, let me know and I can tweak.

I think probably I'll merge the interactive-forms branch into master (but still behind a flag) before the end of this month. I would like to improve the validation (see #6092 - I'd like your input) before removing that flag, but that may depend on how big that jobs ends up being.

@DanTup
DanTup merged commit 2ed820e into interactive-forms Jun 22, 2026
21 checks passed
@DanTup
DanTup deleted the interactive-forms-gemini-feedback branch June 22, 2026 09:38
@bwilkerson

Copy link
Copy Markdown

I actually think we should not treat empty as zero for numerics either - if a numeric is required and has no default, we should treat empty the same as an invalid number, and force the user to type 0 if that's what they want? (of course, if zero is a reasonable default, the server can provide it as such).

I agree. We have a way to indicate that a value isn't required because there's a reasonable default value. We also need a way to indicate that a value is required because there's no reasonable default. Allowing blank to mean 0 defeats the second requirement.

Strings are similar. I haven't been following closely (the quoted comment just caught my eye), so I don't know what the current state is, but I'd advocate for not allowing an empty string when a string is required. I think that makes more sense than not being able to distinguish between and empty string and no string.

@DanTup

DanTup commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

I'd advocate for not allowing an empty string when a string is required

Yep, I agree. I'm just preparing a PR that adds some tests (I will CC you both shortly when it's all green and the AIs reviewers are happy!) and I noticed this wasn't handled, so it also addresses that (as well as applying validation to lists that was missed before).

@DanTup DanTup modified the milestones: v3.138.0, v3.140.0 Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in editor Relates to code editing or language features is enhancement An enhancement or improvement that should be listed in release notes but is not a bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants