Skip to content

safer auto completion chaining#4165

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:check-completion-invoke
Jun 18, 2022
Merged

safer auto completion chaining#4165
mbien merged 1 commit intoapache:masterfrom
mbien:check-completion-invoke

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented May 27, 2022

  • attempting to open the next completion can cause problems if the
    completion itself is not implemented properly (infinite completion
    loops)
  • to mitigate this we can check if the last removed group of the
    template had "completionInvoke" set, so that for example constructor
    completions still work as expected

follow up on #2519, #3290

history:
#2519 fixed a separate issue, but caused also a regression. #3290 attempted to restore the functionality (<12.3) without reverting #2519 but this could cause the above mentioned issue in some situations.

example for a completion which never finishes: #3805

example for completion chaining (intended behavior):

// completion for:
new HashM
// would have the (dynamically generated) template:
"HashMap<>${cursor completionInvoke}"
// and would insert
new HashMap<>
// and would continue with the next completion for constructors due to the removed "completionInvoke" group
// pressing (first item) return would result in 
new HashMap<>()

lets see if all tests are green.

@mbien mbien added the Editor label May 27, 2022
@mbien mbien added this to the NB15 milestone May 27, 2022
 - attempting to open the next completion can cause problems if the
   completion itself is not implemented properly (infinite completion
   loops)
 - to mitigate this we can check if the last removed group of the
   template had "completionInvoke" set, so that for example constructor
   completions still works as expected

follow up on apache#2519, apache#3290
@mbien mbien force-pushed the check-completion-invoke branch from 728ca8a to ab3fecb Compare May 30, 2022 21:21
@mbien mbien marked this pull request as ready for review May 30, 2022 21:24
@mbien
Copy link
Copy Markdown
Member Author

mbien commented May 31, 2022

everything looks good so far. I did some testing with editor templates but would have to do more to be confident that this does not cause regressions.

@Chris2011
Copy link
Copy Markdown
Contributor

Chris2011 commented May 31, 2022

The thing is that it take sometime (some ms) to add the () after I hit enter to see the ctor but this is a general problem I think. I just wanted to mentioned it here, because I think this is of this completion chaining stuff what you mentioned. I mean I really wanted the ctor and it still completes to new HashMap<>...~200ms new HashMap<>(). Why not just immediately?

@mbien
Copy link
Copy Markdown
Member Author

mbien commented May 31, 2022

The thing is that it take sometime (some ms) to add the () after I hit enter to see the ctor but this is a general problem I think. I just wanted to mentioned it here, because I think this is of this completion chaining stuff what you mentioned. I mean I really wanted the ctor and it still completes to new HashMap<>...~200ms new HashMap<>(). Why not just immediately?

I don't think i can reproduce this issue. The text substitution happens as fast as i can press return twice in a row. Might be influenced by the complexity of the document/project, this PR doesn't do any heavy lifting, it only tweaks the conditions when followup/parametrized completions are triggered.

I mean I really wanted the ctor and it still completes to new HashMap<>...~200ms new HashMap<>(). Why not just immediately?

because the first completion is for the type (HashMap), the second for the constructor. There is more than one constructor, therefore another completion popup opens. If there would be just one constructor it would insert it right away. Thats also why #3805 loops forever since the completion itself sets the cursor to a location which resembles the initial conditions (and there is just one item in the completion list).

edit: btw #4142 is working on removing a completion related bottleneck, but this isn't related to this PR here

@junichi11
Copy link
Copy Markdown
Member

junichi11 commented Jun 1, 2022

I think we should implement it in the Java editor after we revert all changes for the editor.
I guess that we can handle it in the Java editor (Maybe, we should be able to run CC again from the Java editor if needed.) because the Java editor knows the context.
Did you try that?

I think fixing it in the editor(invoking CC repeatedly in it) is risky.

@sdedic @jlahoda Do you have any ideas or advice?

Add: This is my misunderstanding, sorry.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 1, 2022

@junichi11 this isn't java specific. ${cursor completionInvoke}is part of regular completion templates.

public final class CodeTemplateParameter {
/**
* Name of the parameter corresponding to the caret position parameter.
*/
public static final String CURSOR_PARAMETER_NAME = "cursor"; // NOI18N
public static final String COMPLETION_INVOKE_HINT_NAME = "completionInvoke"; // NOI18N

@junichi11
Copy link
Copy Markdown
Member

@mbien I don't say about it. If we can implement your issue in the Java editor, we shouldn't change the editor.

e.g. call the method like the following (scheduleShowingCompletion()) in the Java editor

    private static ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();

    private static void scheduleShowingCompletion() {
        service.schedule(() -> {
            Completion.get().showCompletion();
        }, 750, TimeUnit.MILLISECONDS);
    }

@Chris2011
Copy link
Copy Markdown
Contributor

Chris2011 commented Jun 1, 2022

What is the delay for and why is it that high? I mean, I see for what it is, but why is it intended to be that high to wait for it?

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 1, 2022

@mbien I don't say about it. If we can implement your issue in the Java editor, we shouldn't change the editor.

again. This is not a java issue. A completion template (for any language) with a completionInvoke parameter, should open the completion if the parameter is active. This was always the case, there was just a regression in 12.3 caused by #2519 (please read the PR text and also of this PR here). So lets try to fix this properly in the editor lib. This PR is attempting exactly that, restore <12.3 functionality without causing regressions.

@junichi11
Copy link
Copy Markdown
Member

@mbien Ah, I see now. I thought you are working on a Java issue, sorry.

@junichi11
Copy link
Copy Markdown
Member

@mbien I've verified #3805 doesn't occur. Thank you for your work!

netbeans-gh-4165

@junichi11 junichi11 linked an issue Jun 3, 2022 that may be closed by this pull request
@mbien mbien added the kind:bug Bug report or fix label Jun 3, 2022
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 10, 2022

@lkishalmi Is groovy using the same API for code completion (ide/editor.codetemplates)?

We tested this PR for php and java and it looks promising.

@mbien mbien requested a review from matthiasblaesing June 10, 2022 22:15
@lkishalmi
Copy link
Copy Markdown
Contributor

@mbien I'm sorry, but I do not know the Groovy implementation details.

@matthiasblaesing
Copy link
Copy Markdown
Contributor

I don't feel really qualified to review this. However I verified, that the issue is gone and the behavior seems to be fixed. The changes look ok to me.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 12, 2022

if anyone knows someone who might want to review this, please add to PR.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 18, 2022

i would like to merge this one soon too so that it gets good testing in during NB 15 dev

@junichi11
Copy link
Copy Markdown
Member

Agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Editor kind:bug Bug report or fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

php editor : infinte semicolon while autocomplet on "return"

6 participants