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

Invalid snippet suggested in completion before the Class statement [context] #402

Open
turkeylurkey opened this issue Jun 2, 2023 · 7 comments · May be fixed by #476
Open

Invalid snippet suggested in completion before the Class statement [context] #402

turkeylurkey opened this issue Jun 2, 2023 · 7 comments · May be fixed by #476
Labels
bug Something isn't working

Comments

@turkeylurkey
Copy link

This issue revolves around the field and method snippets and the context in which the language server suggests them when the user activates completion (e.g. Ctrl-Space).

Consider this sample class:

package a.b.c;
// Position A
class d{ 
    // Position B
    class Inner {}
    // Position C
}

When you use completion in Position A the language server provides rest_get as one of the choices. This snippet represents the insertion of a method but this is not valid in this context. When you use completion in Position C the snippet rest_get is valid. It looks like method snippets should not be allowed before a class. This requires fix #1.

This brings us to Position B. Currently the language server considers this to be "before a class." We must allow a method snippet here. This exposes an ambiguity in the definitions. Position B is both 'In A Class' and 'Before A Class.' The former should dominate the latter and this would allow the language server to suggest a method snippet here. This requires fix #2.

@angelozerr
Copy link
Contributor

@datho7561 do you think we could improve java cursor context to cover this Issue?

@angelozerr
Copy link
Contributor

@turkeylurkey we know that our java cursor context is not perfect, but it should filter the most common usecases, any contribution are welcome!

@datho7561
Copy link
Contributor

I thought I handled this case correctly. I'll take a quick look at what is happening.

@datho7561
Copy link
Contributor

From my testing, cases B and C seem to work properly, but A doesn't work (either with class or public class). For all of these cases, I get Exceptions in the output when I select the completion item.

(I am testing using VS Code, this might be different from Eclipse).

@turkeylurkey
Copy link
Author

The reason A doesn't work is that SnippetContextForJava explicitly allows the wrong snippets to be available:

|| kind == JavaCursorContextKind.BEFORE_CLASS || kind == JavaCursorContextKind.IN_CLASS;

If you just remove BEFORE_CLASS then you will break B. That fix requires reworking the code that examines the syntax tree.

@angelozerr
Copy link
Contributor

@turkeylurkey is there any chance that you provide a PR with your idea?

@turkeylurkey
Copy link
Author

Unfortunately I'm having trouble building and running in Eclipse to update FindWhatsBeingAnnotatedASTVisitor and making a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants