java-language-server
java-language-server copied to clipboard
AutoFixImports bug changes imports
Hi when using the server with neovim it changes imports, so that the code is wrong afterwards. Look at the fourth import in the example below.
Installed version: 0.2.39 Java Version: openjdk 23 Temurin-23+37
Before:
package com.example.demo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.SpringApplication;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
After:
package com.example.demo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Logs:
[DEBUG][2024-10-06 14:01:22] ...m/lsp/client.lua:678 "LSP[java_language_server]" "client.request" 2 "textDocument/formatting" {
options = {
insertSpaces = true,
tabSize = 2
},
textDocument = {
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
} <function 1> 20
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:286 "rpc.send" {
id = 25,
jsonrpc = "2.0",
method = "textDocument/formatting",
params = {
options = {
insertSpaces = true,
tabSize = 2
},
textDocument = {
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:408 "rpc.receive" {
id = 25,
jsonrpc = "2.0",
result = {
{
newText = "",
range = {
["end"] = {
character = 0,
line = 3
},
start = {
character = 0,
line = 2
}
}
}, {
newText = "",
range = {
["end"] = {
character = 0,
line = 4
},
start = {
character = 0,
line = 3
}
}
}, {
newText = "",
range = {
["end"] = {
character = 0,
line = 5
},
start = {
character = 0,
line = 4
}
}
}, {
newText = "",
range = {
["end"] = {
character = 0,
line = 6
},
start = {
character = 0,
line = 5
}
}
}, {
newText = "import org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;\nimport org.springframework.web.bind.annotation.RestController;\n",
range = {
["end"] = {
character = 0,
line = 2
},
start = {
character = 0,
line = 2
}
}
}
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:286 "rpc.send" {
jsonrpc = "2.0",
method = "textDocument/didChange",
params = {
contentChanges = {
{
range = {
["end"] = {
character = 0,
line = 6
},
start = {
character = 0,
line = 5
}
},
rangeLength = 51,
text = ""
}
},
textDocument = {
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java",
version = 203
}
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:286 "rpc.send" {
jsonrpc = "2.0",
method = "textDocument/didChange",
params = {
contentChanges = {
{
range = {
["end"] = {
character = 0,
line = 5
},
start = {
character = 0,
line = 4
}
},
rangeLength = 63,
text = ""
}, {
range = {
["end"] = {
character = 0,
line = 4
},
start = {
character = 0,
line = 3
}
},
rangeLength = 80,
text = ""
}, {
range = {
["end"] = {
character = 68,
line = 2
},
start = {
character = 32,
line = 2
}
},
rangeLength = 36,
text = "SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;\nimport org.springframework.web.bind.annotation.RestController;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;"
}, {
range = {
["end"] = {
character = 68,
line = 3
},
start = {
character = 32,
line = 2
}
},
rangeLength = 87,
text = "autoconfigure.SpringBootApplication;"
}
},
textDocument = {
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java",
version = 207
}
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:286 "rpc.send" {
jsonrpc = "2.0",
method = "textDocument/didSave",
params = {
textDocument = {
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:408 "rpc.receive" {
jsonrpc = "2.0",
method = "textDocument/publishDiagnostics",
params = {
diagnostics = {
{
code = "compiler.err.cant.resolve.location",
message = "cannot find symbol\n symbol: variable SpringApplication\n location: class de.nordakademie.demo.DemoApplication",
range = {
["end"] = {
character = 23,
line = 11
},
start = {
character = 6,
line = 11
}
},
severity = 1
}
},
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}
[DEBUG][2024-10-06 14:01:22] .../vim/lsp/rpc.lua:408 "rpc.receive" {
jsonrpc = "2.0",
method = "java/colors",
params = {
fields = {},
statics = {},
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}
[DEBUG][2024-10-06 14:01:23] .../vim/lsp/rpc.lua:408 "rpc.receive" {
jsonrpc = "2.0",
method = "textDocument/publishDiagnostics",
params = {
diagnostics = {
{
code = "compiler.err.cant.resolve.location",
message = "cannot find symbol\n symbol: variable SpringApplication\n location: class de.nordakademie.demo.DemoApplication",
range = {
["end"] = {
character = 23,
line = 11
},
start = {
character = 6,
line = 11
}
},
severity = 1
}
},
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}
[DEBUG][2024-10-06 14:01:23] .../vim/lsp/rpc.lua:408 "rpc.receive" {
jsonrpc = "2.0",
method = "java/colors",
params = {
fields = {},
statics = {},
uri = "file:///root/workspace/backend/src/main/java/com/example/demo/DemoApplication.java"
}
}