netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

In VSCode extension added user configuration for commit characters for accepting code suggestions

Open Achal1607 opened this issue 7 months ago • 3 comments

This PR adds support for configurable commit characters in the Java LSP server. Users can now define which characters (e.g., ., ,) trigger the acceptance of a code completion suggestion via the new netbeans.java.completion.commit.chars setting in the Netbeans VS Code extension. The server reads this configuration and applies the characters to completion items dynamically. This improves the flexibility and user control over the code completion behaviour.

Achal1607 avatar May 21 '25 10:05 Achal1607

Not sure what @dbalek thinks here, but thinking of this for a bit: I am not sure that forcing the same list of commit characters on all completion items is ideal. E.g. there may be some items where it may make sense to confirm them on (, while some not, and that is not possible to do with a single list.

Maybe one of these would work better:

  • have a boolean switch that would enable/disable the commit characters that the provider filled in. I.e. if enabled, whatever commit character that the provider filled in the item would be used; if disabled, none would be used.
  • have a setting with permitted commit characters. I.e. the real commit characters in an item would be the intersection between this setting and the characters from the provider. (Or, the setting could be a deny list - i.e. the characters in the list would be removed from every item's commit characters.)

lahodaj avatar May 22 '25 18:05 lahodaj

Going back to this - thinking of this more, the actual commit characters sent out from the server should probably be an intersection between the commit characters requested by the completion item, and the user-selected commit characters. That would make most sense to me.

lahodaj avatar Jun 12 '25 06:06 lahodaj

Going back to this - thinking of this more, the actual commit characters sent out from the server should probably be an intersection between the commit characters requested by the completion item, and the user-selected commit characters. That would make most sense to me.

Yes, this approach would be better, however even in NetBeans, all JavaCompletionItems currently share the same list of commit characters (even though the API would allow more fine grained approach). Would be a nice enhancement.

dbalek avatar Jun 12 '25 07:06 dbalek

I was digging a little bit more on how this works in NetBeans, and it turns out that whatever is in the settings is used unconditionally for all completion items, except for ( for a very specific list of completion items (MethodItem, etc.).

So, ultimately, we can go with the patch as proposed here, I think.

lahodaj avatar Jun 30 '25 09:06 lahodaj

FWIW, the existing filter is here: https://github.com/apache/netbeans/blob/cd3f7299071d4753b1c4999d87db77eb8a64a04f/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java#L311

lahodaj avatar Jun 30 '25 09:06 lahodaj

Unless there are objections, I would like to integrate in a few days.

lahodaj avatar Jul 02 '25 04:07 lahodaj