-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issues when bazel is used alongside cmake (#6770)
* fixed multiple registrations * fixed notification show for files in a different project model * Rename .java to .kt * changes for 243 * added read action * created service for CLionNotificationProvider * added psw status to simple integration test * Revert "added psw status to simple integration test" This reverts commit c2906ad. Let's wait with this until we drop 241. Don't want to introduce sdk compat for tests.
- Loading branch information
Showing
4 changed files
with
204 additions
and
197 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
143 changes: 0 additions & 143 deletions
143
clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.java
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.kt
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,132 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* 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.google.idea.blaze.clwb | ||
|
||
import com.google.idea.blaze.base.lang.buildfile.language.BuildFileType | ||
import com.google.idea.blaze.base.settings.Blaze | ||
import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction | ||
import com.google.idea.blaze.base.wizard2.BazelNotificationProvider | ||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.ui.EditorNotificationProvider | ||
import com.jetbrains.cidr.lang.daemon.OCFileScopeProvider.Companion.getProjectSourceLocationKind | ||
import com.jetbrains.cidr.project.ui.convertStatus | ||
import com.jetbrains.cidr.project.ui.isProjectAwareFile | ||
import com.jetbrains.cidr.project.ui.notifications.EditorNotificationWarningProvider | ||
import com.jetbrains.cidr.project.ui.notifications.ProjectNotification | ||
import com.jetbrains.cidr.project.ui.popup.ProjectFixesProvider | ||
import com.jetbrains.cidr.project.ui.widget.* | ||
|
||
private fun isBazelAwareFile(project: Project, file: VirtualFile): Boolean { | ||
if (Blaze.isBlazeProject(project)) { | ||
return false | ||
} | ||
|
||
if (!isProjectAwareFile(file, project) && file.fileType !== BuildFileType.INSTANCE) { | ||
return false | ||
} | ||
|
||
if (getProjectSourceLocationKind(project, file).isInProject()) { | ||
return false | ||
} | ||
|
||
if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { | ||
return false | ||
} | ||
|
||
return project.basePath != null | ||
} | ||
|
||
// #api241 | ||
@Service(Service.Level.APP) | ||
class CLionNotificationProvider : ProjectFixesProvider, WidgetStatusProvider, EditorNotificationWarningProvider, | ||
Disposable.Default { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun register(project: Project) { | ||
service<CLionNotificationProvider>().unregisterGenericProvider(project) | ||
} | ||
} | ||
|
||
init { | ||
registerSpecificProvider(); | ||
} | ||
|
||
private fun registerSpecificProvider() { | ||
val projectFixes = ProjectFixesProvider.Companion.EP_NAME.point | ||
projectFixes.registerExtension(this, this) | ||
|
||
val projectNotifications = EditorNotificationWarningProvider.EP_NAME.point | ||
projectNotifications.registerExtension(this, this) | ||
|
||
val widgetStatus = WidgetStatusProvider.EP_NAME.point | ||
widgetStatus.registerExtension(this, this) | ||
} | ||
|
||
private fun unregisterGenericProvider(project: Project) { | ||
val extensionPoint = EditorNotificationProvider.EP_NAME.getPoint(project) | ||
|
||
// Note: We need to remove the default style of showing project status and fixes used in | ||
// Android Studio and IDEA to introduce CLion's PSW style. | ||
for (extension in extensionPoint.extensions) { | ||
if (extension is BazelNotificationProvider) { | ||
extensionPoint.unregisterExtension(extension) | ||
} | ||
} | ||
} | ||
|
||
override fun collectFixes(project: Project, file: VirtualFile?, dataContext: DataContext): List<AnAction> { | ||
if (file == null) { | ||
return emptyList() | ||
} | ||
|
||
val isBazelFile = isBazelAwareFile(project, file) | ||
if (!isBazelFile) { | ||
return emptyList() | ||
} | ||
|
||
return listOf(ImportBazelAction(project.basePath ?: return emptyList())) | ||
} | ||
|
||
private class ImportBazelAction(private val root: String) : AnAction("Import Bazel project") { | ||
override fun actionPerformed(anActionEvent: AnActionEvent) { | ||
BazelImportCurrentProjectAction.createAction(root).run() | ||
} | ||
} | ||
|
||
override fun getProjectNotification(project: Project, virtualFile: VirtualFile): ProjectNotification? { | ||
return convertStatus(getWidgetStatus(project, virtualFile)) | ||
} | ||
|
||
override fun getWidgetStatus(project: Project, file: VirtualFile?): WidgetStatus? { | ||
if (Blaze.isBlazeProject(project)) { | ||
return DefaultWidgetStatus(Status.OK, Scope.Project, "Project is configured") | ||
} | ||
|
||
if (file == null || !isBazelAwareFile(project, file)) { | ||
return null | ||
} | ||
|
||
return DefaultWidgetStatus(Status.Warning, Scope.Project, "Project is not configured") | ||
} | ||
} |
Oops, something went wrong.