From c7d3bf089e58baf652c9915ee123fa579b5cab4e Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Wed, 28 Mar 2018 17:34:36 +0300 Subject: [PATCH] WEB-31966 Parameter info hint does not work with TypeScript in Vue files --- .../hint/ShowParameterInfoHandler.java | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowParameterInfoHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowParameterInfoHandler.java index 1d7c0bf4d43c..0d28880776c8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowParameterInfoHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ShowParameterInfoHandler.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.hint; @@ -31,6 +17,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.ui.LightweightHint; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -60,13 +47,6 @@ public class ShowParameterInfoHandler implements CodeInsightActionHandler { return false; } - @Nullable - private static PsiElement findAnyElementAt(@NotNull PsiFile file, int offset) { - PsiElement element = file.findElementAt(offset); - if (element == null && offset > 0) element = file.findElementAt(offset - 1); - return element; - } - /** * @deprecated use {@link #invoke(Project, Editor, PsiFile, int, PsiElement, boolean)} instead */ @@ -74,19 +54,19 @@ public class ShowParameterInfoHandler implements CodeInsightActionHandler { invoke(project, editor, file, lbraceOffset, highlightedElement, false); } - public static void invoke(final Project project, final Editor editor, PsiFile file, + public static void invoke(final Project project, final Editor editor, PsiFile file, int lbraceOffset, PsiElement highlightedElement, boolean requestFocus) { invoke(project, editor, file, lbraceOffset, highlightedElement, requestFocus, false); } - public static void invoke(final Project project, final Editor editor, PsiFile file, + public static void invoke(final Project project, final Editor editor, PsiFile file, int lbraceOffset, PsiElement highlightedElement, boolean requestFocus, boolean singleParameterHint) { ApplicationManager.getApplication().assertIsDispatchThread(); PsiDocumentManager.getInstance(project).commitAllDocuments(); final int offset = editor.getCaretModel().getOffset(); - final PsiElement psiElement = findAnyElementAt(file, offset); - if (psiElement == null) return; + final int fileLength = file.getTextLength(); + if (fileLength == 0) return; final ShowParameterInfoContext context = new ShowParameterInfoContext( editor, @@ -101,7 +81,9 @@ public class ShowParameterInfoHandler implements CodeInsightActionHandler { context.setHighlightedElement(highlightedElement); context.setRequestFocus(requestFocus); - final Language language = psiElement.getLanguage(); + // file.findElementAt(file.getTextLength()) returns null but we may need to show parameter info at EOF offset (for example in SQL) + final int offsetForLangDetection = offset > 0 && offset == fileLength ? offset - 1 : offset; + final Language language = PsiUtilCore.getLanguageAtOffset(file, offsetForLangDetection); ParameterInfoHandler[] handlers = getHandlers(project, language, file.getViewProvider().getBaseLanguage()); if (handlers == null) handlers = new ParameterInfoHandler[0];