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

AutoFixImports bug changes imports #292

Open
dominicmeyer opened this issue Oct 6, 2024 · 0 comments
Open

AutoFixImports bug changes imports #292

dominicmeyer opened this issue Oct 6, 2024 · 0 comments

Comments

@dominicmeyer
Copy link

dominicmeyer commented Oct 6, 2024

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"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant