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

Code action: add static import #796

Closed
str-ay opened this issue Feb 13, 2019 · 9 comments
Closed

Code action: add static import #796

str-ay opened this issue Feb 13, 2019 · 9 comments

Comments

@str-ay
Copy link

str-ay commented Feb 13, 2019

Hi. I wonder that there is no way to quickly add static import (+ refactor all occurances).
It is really actual while writing tests or using spring 5 functional routing for example.

  • Visual Studio Code version: 1.32
  • Java extension version: 0.38
@cedric05
Copy link

static import itself throwing error, in my case

@testforstephen
Copy link
Collaborator

testforstephen commented Mar 15, 2019

@jnesspro By default, the Java extension will only recommend static import for the members below.

    "java.completion.favoriteStaticMembers": [
        "org.junit.Assert.*",
        "org.junit.Assume.*",
        "org.junit.jupiter.api.Assertions.*",
        "org.junit.jupiter.api.Assumptions.*",
        "org.junit.jupiter.api.DynamicContainer.*",
        "org.junit.jupiter.api.DynamicTest.*",
        "org.mockito.Mockito.*",
        "org.mockito.ArgumentMatchers.*",
        "org.mockito.Answers.*"
      ]

If you want to enable static import for spring 5 members, you need modify the user settings and append your favorite package into java.completion.favoriteStaticMembers.
For example:

    "java.completion.favoriteStaticMembers": [
        ...
        "org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*",
        "org.springframework.test.web.servlet.result.MockMvcResultMatchers.*"
      ]

@testforstephen
Copy link
Collaborator

@cedric05 Can you execute VS Code command Java: Open Java Language Server log file, and share us the log?

@cedric05
Copy link

@testforstephen sorry for filing wrong. its working.

@fbricon
Copy link
Collaborator

fbricon commented Mar 26, 2019

You asked for it, @testforstephen delivered:

Mar-26-2019 15-56-04

@notmattlythgoe
Copy link

@fbricon How are you bringing up the menu?

@fbricon
Copy link
Collaborator

fbricon commented May 21, 2019

Click on static method, Ctrl+. (Cmd+. on mac) or click on lightbulb or right-click -> Code Action

@bvedant
Copy link

bvedant commented May 4, 2022

@fbricon thanks for the update! any chance we could have this feature in Show Code Actions dropdown like it is in IntelliJ, perhaps a toggle to move the feature function to there for those who want it?

@appleseedexm
Copy link

appleseedexm commented Feb 22, 2023

So for me this was never enabled by default and I had to Edit in settings.json in the settings UI (java.completion.favoriteStaticMembers) for it to add the default static imports to my settings.json.

Very weird behaviour, but at least it works now. Seems to me like this is not set on install (neither in default / user settings.json).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants