Closed Eskibear closed 2 years ago
@Eskibear please go ahead with a fix :)
@Eskibear are you gonna fix this one for this release?
I did some investigation, it's not a low-hanging bug, I'm not going to work on it right now.
The CompilationUnit returned by upstream utility JavaCore.createCompilationUnitFrom(resource)
is incomplete, so JDTLS is not aware that the position is in an anonymous class.
To trigger the completion directly without inputting the hint
E.g. for sample code below
package com.example.demo;
public class Hello {
ThreadLocal<Integer> fieldVar = new ThreadLocal<Integer>() {
initialValue
};
public static void foo() {
ThreadLocal<Integer> localVar = new ThreadLocal<Integer>() {
initialValue
}
}
}
The compilationUnit misses the anonymous class part.
CompilationUnit@2359 "[Working copy] Hello.java [in com.example.demo [in src/main/java [in demo]]]
package com.example.demo
class Hello
ThreadLocal<Integer> fieldVar
static void foo()
class <anonymous #1>"
BUT, if we trigger completion directly (removing the hint "initialValue"), the unit is correct, with a subnode of the anonymous class.
...
public class Hello {
ThreadLocal<Integer> fieldVar = new ThreadLocal<Integer>() {
[CURSOR]
};
...
CompilationUnit@2373 "[Working copy] Hello.java [in com.example.demo [in src/main/java [in demo]]]
package com.example.demo
class Hello
ThreadLocal<Integer> fieldVar
class <anonymous #1> <-----HERE
static void foo()
class <anonymous #1>"
Don't know when but at least it's gone in the latest
Originally reported in https://github.com/MicrosoftDocs/intellicode/issues/173
Sample code to reproduce:
It only occurs when you initialize a field member in declaration. I tried the same thing within a method body, and it worked well.
Below is the response, we can see
textEdit.newText
is wrong.