-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide InlayHint for property expression in
microprofile-config.properties (#971) Fixes #971 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
3e86087
commit b3fa3c5
Showing
16 changed files
with
744 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/MicroProfileBundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4mp4ij; | ||
|
||
import com.intellij.DynamicBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.PropertyKey; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* MicroProfile messages bundle. | ||
*/ | ||
public final class MicroProfileBundle extends DynamicBundle { | ||
|
||
@NonNls public static final String BUNDLE = "messages.MicroProfileBundle"; | ||
private static final MicroProfileBundle INSTANCE = new MicroProfileBundle(); | ||
|
||
private MicroProfileBundle() { | ||
super(BUNDLE); | ||
} | ||
|
||
@NotNull | ||
public static @Nls String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) { | ||
return INSTANCE.getMessage(key, params); | ||
} | ||
|
||
@NotNull | ||
public static Supplier<@Nls String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) { | ||
return INSTANCE.getLazyMessage(key, params); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4mp4ij.settings; | ||
|
||
import com.intellij.openapi.options.ConfigurationException; | ||
import com.intellij.openapi.ui.NamedConfigurable; | ||
import com.intellij.openapi.util.NlsContexts; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; | ||
|
||
import javax.swing.*; | ||
|
||
public class MicroProfileConfigurable extends NamedConfigurable<UserDefinedMicroProfileSettings> { | ||
|
||
private MicroProfileView myView; | ||
|
||
public MicroProfileConfigurable() { | ||
} | ||
|
||
@Override | ||
public UserDefinedMicroProfileSettings getEditableObject() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @NlsContexts.DetailedDescription String getBannerSlogan() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public JComponent createOptionsPanel() { | ||
if (myView == null) { | ||
myView = new MicroProfileView(); | ||
} | ||
return myView.getComponent(); | ||
} | ||
|
||
@Override | ||
public void setDisplayName(String name) { | ||
} | ||
|
||
@Override | ||
public @NlsContexts.ConfigurableName String getDisplayName() { | ||
return MicroProfileBundle.message("microprofile"); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isModified() { | ||
if (myView == null) return false; | ||
return false; | ||
} | ||
|
||
@Override | ||
public void apply() throws ConfigurationException { | ||
// Do nothing | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ava/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurableProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4mp4ij.settings; | ||
|
||
import com.intellij.openapi.options.Configurable; | ||
import com.intellij.openapi.options.ConfigurableProvider; | ||
|
||
/** | ||
* MicroProfile UI settings provider. | ||
*/ | ||
public class MicroProfileConfigurableProvider extends ConfigurableProvider { | ||
|
||
@Override | ||
public Configurable createConfigurable() { | ||
return new MicroProfileConfigurable(); | ||
} | ||
|
||
@Override | ||
public boolean canCreateConfigurable() { | ||
return true; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4mp4ij.settings; | ||
|
||
import com.intellij.openapi.Disposable; | ||
import com.intellij.util.ui.FormBuilder; | ||
import com.intellij.util.ui.UI; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; | ||
|
||
import javax.swing.*; | ||
|
||
/** | ||
* MicroProfile view. | ||
*/ | ||
public class MicroProfileView implements Disposable { | ||
|
||
private final JPanel myMainPanel; | ||
|
||
public MicroProfileView() { | ||
this.myMainPanel = FormBuilder.createFormBuilder() | ||
.setFormLeftIndent(10) | ||
.addComponent(createTitleComponent(), 1) | ||
.addComponentFillVertically(new JPanel(), 0) | ||
.getPanel(); | ||
} | ||
|
||
private JComponent createTitleComponent() { | ||
JLabel title = new JLabel(MicroProfileBundle.message("microprofile.title")); | ||
String description = MicroProfileBundle.message("microprofile.description"); | ||
if (description != null && description.length() > 0) { | ||
// @See com.intellij.internal.ui.ComponentPanelTestAction for more details on how to create comment panels | ||
return UI.PanelFactory.panel(title) | ||
.withComment(description) | ||
.createPanel(); | ||
} | ||
return title; | ||
} | ||
|
||
public JComponent getComponent() { | ||
return myMainPanel; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
|
||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...java/com/redhat/devtools/intellij/lsp4mp4ij/settings/UserDefinedMicroProfileSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4mp4ij.settings; | ||
|
||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import com.intellij.util.xmlb.annotations.Tag; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* User defined MicroProfile settings. | ||
*/ | ||
@State( | ||
name = "MicroProfileSettingsState", | ||
storages = {@Storage("microProfileSettings.xml")} | ||
) | ||
public class UserDefinedMicroProfileSettings implements PersistentStateComponent<UserDefinedMicroProfileSettings.MyState> { | ||
|
||
public volatile MyState myState = new MyState(); | ||
|
||
public static UserDefinedMicroProfileSettings getInstance() { | ||
return ServiceManager.getService(UserDefinedMicroProfileSettings.class); | ||
} | ||
|
||
// ---------- Properties | ||
|
||
public boolean isInlayHintEnabled() { | ||
UserDefinedMicroProfileSettings.MyState state = getState(); | ||
return state != null && state.myInlayHintEnabled; | ||
} | ||
|
||
// ---------- Java | ||
|
||
public boolean isUrlCodeLensEnabled() { | ||
UserDefinedMicroProfileSettings.MyState state = getState(); | ||
return state != null && state.myUrlCodeLensEnabled; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public MyState getState() { | ||
return myState; | ||
} | ||
|
||
@Override | ||
public void loadState(@NotNull MyState state) { | ||
myState = state; | ||
} | ||
|
||
public void setInlayHintEnabled(boolean inlayHintEnabled) { | ||
UserDefinedMicroProfileSettings.MyState state = getState(); | ||
if (myState != null) { | ||
state.myInlayHintEnabled = inlayHintEnabled; | ||
} | ||
} | ||
|
||
public void setUrlCodeLensEnabled(boolean urlCodeLensEnabled) { | ||
UserDefinedMicroProfileSettings.MyState state = getState(); | ||
if (myState != null) { | ||
state.myUrlCodeLensEnabled = urlCodeLensEnabled; | ||
} | ||
} | ||
|
||
|
||
static class MyState { | ||
@Tag("inlayHintEnabled") | ||
public boolean myInlayHintEnabled = true; | ||
|
||
@Tag("urlCodeLensEnabled") | ||
public boolean myUrlCodeLensEnabled = true; | ||
|
||
MyState() { | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.