remove editor context menu action to enable parameter hints

doesn't seem to be useful
This commit is contained in:
Dmitry Batrak
2017-07-21 13:11:11 +03:00
parent ffd356b916
commit 92528456af
3 changed files with 0 additions and 115 deletions
@@ -1,82 +0,0 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.java.codeInsight.daemon.inlays
import com.intellij.codeInsight.hints.isPossibleHintNearOffset
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.assertj.core.api.Assertions.assertThat
class ToggleInlineHintsActionTest : LightCodeInsightFixtureTestCase() {
private var before: Boolean = false
override fun setUp() {
super.setUp()
before = EditorSettingsExternalizable.getInstance().isShowParameterNameHints
EditorSettingsExternalizable.getInstance().isShowParameterNameHints = false
}
override fun tearDown() {
EditorSettingsExternalizable.getInstance().isShowParameterNameHints = before
super.tearDown()
}
fun `test is enabled near method with possible hints`() {
myFixture.configureByText("A.java", """"
class Test {
Test(int time) {}
void initialize(int loadTime) {}
static void s_test() {
Test test = new T<caret>est(<caret>10);
test.initial<caret>ize(100<caret>00);
}
}
""")
val file = myFixture.file
val caretModel = myFixture.editor.caretModel
assertThat(caretModel.caretCount).isEqualTo(4)
editor.caretModel.allCarets.forEach {
val hintCanBeAtCaret = isPossibleHintNearOffset(file, it.offset)
assertThat(hintCanBeAtCaret).isTrue()
}
}
fun `test is disabled in random places`() {
myFixture.configureByText("A.java", """"
class Test {
static void s_<caret>test() {
int a <caret>= 2;
Li<caret>st<String> list = null;
}
}
""")
val file = myFixture.file
val caretModel = myFixture.editor.caretModel
assertThat(caretModel.caretCount).isEqualTo(3)
editor.caretModel.allCarets.forEach {
val hintCanBeAtCaret = isPossibleHintNearOffset(file, it.offset)
assertThat(hintCanBeAtCaret).isFalse()
}
}
}
@@ -29,7 +29,6 @@ import com.intellij.lang.Language
import com.intellij.notification.Notification
import com.intellij.notification.NotificationListener
import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
@@ -275,22 +274,6 @@ class ToggleInlineHintsAction : AnAction() {
val isHintsShownNow = EditorSettingsExternalizable.getInstance().isShowParameterNameHints
e.presentation.text = if (isHintsShownNow) disableText else enableText
e.presentation.isEnabledAndVisible = true
if (isInMainEditorPopup(e)) {
val file = CommonDataKeys.PSI_FILE.getData(e.dataContext) ?: return
val editor = CommonDataKeys.EDITOR.getData(e.dataContext) ?: return
val caretOffset = editor.caretModel.offset
e.presentation.isEnabledAndVisible = !isHintsShownNow && isPossibleHintNearOffset(file, caretOffset)
}
}
private fun isInMainEditorPopup(e: AnActionEvent): Boolean {
if (e.place != ActionPlaces.EDITOR_POPUP) return false
val editor = CommonDataKeys.EDITOR.getData(e.dataContext) ?: return false
val offset = editor.caretModel.offset
return !editor.inlayModel.hasInlineElementAt(offset)
}
override fun actionPerformed(e: AnActionEvent) {
@@ -349,21 +332,6 @@ fun PsiElement.isOwnsInlayInEditor(editor: Editor): Boolean {
return !editor.inlayModel.getInlineElementsInRange(start, textRange.endOffset).isEmpty()
}
fun isPossibleHintNearOffset(file: PsiFile, offset: Int): Boolean {
val hintProvider = InlayParameterHintsExtension.forLanguage(file.language) ?: return false
var element = file.findElementAt(offset)
for (i in 0..3) {
if (element == null) return false
val hints = hintProvider.getParameterHints(element)
if (hints.isNotEmpty()) return true
element = element.parent
}
return false
}
fun MethodInfo.toPattern() = this.fullyQualifiedName + '(' + this.paramNames.joinToString(",") + ')'
@@ -304,7 +304,6 @@
</group>
<action id="ToggleInlineHintsAction" class="com.intellij.codeInsight.hints.ToggleInlineHintsAction">
<add-to-group group-id="EditorPopupMenu"/>
<add-to-group group-id="ParameterNameHints"/>
</action>