eclipse-jdtls / eclipse-jdt-core-incubator

Eclipse Public License 2.0
7 stars 1 forks source link

[Javac] Audit NetBeans completion #123

Open mickaelistria opened 1 year ago

mickaelistria commented 1 year ago

As discussed earlier with @robstryker after he carried out a lot of analysis, enabling completion on top of a potentially faulty DOM is tricky, and what ECJ-based does is that it keeps track of the grammar rules that are being applied and that is usually very helpful. We should investigate how NetBeans deals with this: does it manage to re-infer rules from a potentially faulty DOM? Or does it reimplement some kind of parser to get some rules and facilitate completion? Or does it do something else...?

robstryker commented 1 year ago

https://github.com/apache/netbeans/blob/643b64771c00c24d857773cd4d454c19f40bb57f/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java#L284

This was a tab someone sent to me and I forgot to add here as commentary.

mickaelistria commented 1 year ago

NetBeans uses the JavacTask to get an AST, that's probably an interesting path to follow. @fbricon also noticed it's been used by https://github.com/georgewfraser/java-language-server too.

gayanper commented 12 months ago

I think this shows that they use a similar approach like the CompletionParser and AssistParser is JDT ECJ variant https://github.com/apache/netbeans/blob/643b64771c00c24d857773cd4d454c19f40bb57f/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java#L1564

mickaelistria commented 12 months ago

It depends on which part you consider. NB's JavaCompletionTask doesn't implement a different parser like JDT does, it does retrieve a DOM ( https://github.com/apache/netbeans/blob/643b64771c00c24d857773cd4d454c19f40bb57f/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java#L294 ) most likely from the compiler. Then it looks at the current node under completion to split the cases into smaller ones, and in these case, they optionally look back in the code/context to decide of the best actions. This could be mimicked in DOMCompletionEngine.

gayanper commented 12 months ago

It depends on which part you consider. NB's JavaCompletionTask doesn't implement a different parser like JDT does, it does retrieve a DOM ( https://github.com/apache/netbeans/blob/643b64771c00c24d857773cd4d454c19f40bb57f/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java#L294 ) most likely from the compiler.

Then it looks at the current node under completion to split the cases into smaller ones, and in these case, they optionally look back in the code/context to decide of the best actions. This could be mimicked in DOMCompletionEngine.

Yes thats the same i was thinking, i brought ECJ since it uses tokens alot, here in NB they use tokens to figure out what's missing by looking at surrounding tokens around completion node.