mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
json schema icon provider: compute only for files that can be schema files (json/yaml), not for the others
GitOrigin-RevId: e4fbad64a029527d6c9b2da415dc186a565adaa7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e08481940
commit
d2bc007554
@@ -1,24 +1,12 @@
|
||||
/*
|
||||
* 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-2019 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.jetbrains.jsonSchema;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IconProvider;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.jsonSchema.extension.JsonSchemaEnabler;
|
||||
import com.jetbrains.jsonSchema.ide.JsonSchemaService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,8 +20,13 @@ public class JsonSchemaIconProvider extends IconProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement element, int flags) {
|
||||
if (element instanceof PsiFile && JsonSchemaService.isSchemaFile((PsiFile)element)) {
|
||||
return AllIcons.FileTypes.JsonSchema;
|
||||
if (element instanceof PsiFile) {
|
||||
VirtualFile virtualFile = ((PsiFile)element).getVirtualFile();
|
||||
if (virtualFile != null
|
||||
&& JsonSchemaEnabler.EXTENSION_POINT_NAME.getExtensionList().stream().anyMatch(e -> e.canBeSchemaFile(virtualFile))
|
||||
&& JsonSchemaService.isSchemaFile((PsiFile)element)) {
|
||||
return AllIcons.FileTypes.JsonSchema;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -28,4 +28,8 @@ public interface JsonSchemaEnabler {
|
||||
default boolean shouldShowSwitcherWidget(VirtualFile file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default boolean canBeSchemaFile(VirtualFile file) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,9 @@ public class JsonSchemaInJsonFilesEnabler implements JsonSchemaEnabler {
|
||||
public boolean isEnabledForFile(VirtualFile file) {
|
||||
return JsonUtil.isJsonFile(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeSchemaFile(VirtualFile file) {
|
||||
return isEnabledForFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,9 @@ public class YamlJsonEnabler implements JsonSchemaEnabler {
|
||||
FileType type = file.getFileType();
|
||||
return type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() instanceof YAMLLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeSchemaFile(VirtualFile file) {
|
||||
return isEnabledForFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user