Enable full highlighting in script files everywhere (was inside source roots only)
Extract KotlinHighlightingUtil to hold this logic
This commit is contained in:
committed by
Ilya Chernikov
parent
34f8e9303f
commit
24b4afb3b8
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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 org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
object KotlinHighlightingUtil {
|
||||
fun shouldHighlight(psiElement: PsiElement): Boolean {
|
||||
val ktFile = psiElement.containingFile as? KtFile ?: return false
|
||||
return ktFile is KtCodeFragment || ktFile.isScript || ProjectRootsUtil.isInProjectOrLibraryContent(ktFile)
|
||||
}
|
||||
|
||||
fun shouldHighlightErrors(psiElement: PsiElement): Boolean {
|
||||
val ktFile = psiElement.containingFile as? KtFile ?: return false
|
||||
return ktFile is KtCodeFragment || ktFile.isScript || ProjectRootsUtil.isInProjectSource(ktFile)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.idea.highlighter
|
||||
import com.intellij.codeInsight.daemon.ProblemHighlightFilter
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import com.intellij.ide.projectView.impl.ProjectRootsUtil
|
||||
|
||||
class KotlinProblemHighlightFilter : ProblemHighlightFilter() {
|
||||
|
||||
override fun shouldHighlight(psiFile: PsiFile): Boolean {
|
||||
return psiFile.fileType != KotlinFileType.INSTANCE || !ProjectRootsUtil.isOutsideSourceRoot(psiFile)
|
||||
}
|
||||
if (psiFile.fileType == KotlinFileType.INSTANCE && !KotlinHighlightingUtil.shouldHighlight(psiFile)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -56,9 +56,9 @@ import java.util.*
|
||||
open class KotlinPsiChecker : Annotator, HighlightRangeExtension {
|
||||
|
||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||
if (!(ProjectRootsUtil.isInProjectOrLibraryContent(element) || element.containingFile is KtCodeFragment)) return
|
||||
val file = element.containingFile as? KtFile ?: return
|
||||
|
||||
val file = element.containingFile as KtFile
|
||||
if (!KotlinHighlightingUtil.shouldHighlight(file)) return
|
||||
|
||||
val analysisResult = file.analyzeFullyAndGetResult()
|
||||
if (analysisResult.isError()) {
|
||||
@@ -88,7 +88,7 @@ open class KotlinPsiChecker : Annotator, HighlightRangeExtension {
|
||||
|
||||
if (diagnosticsForElement.isEmpty()) return
|
||||
|
||||
if (ProjectRootsUtil.isInProjectSource(element) || element.containingFile is KtCodeFragment) {
|
||||
if (KotlinHighlightingUtil.shouldHighlightErrors(element)) {
|
||||
ElementAnnotator(element, holder, { param -> shouldSuppressUnusedParameter(param) }).registerDiagnosticsAnnotations(diagnosticsForElement)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user