Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLI-1751 Enable analysis for Jupyter when plugin is enabled #1269

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.sonarlint.intellij.util.GlobalLogOutput
import org.sonarsource.sonarlint.core.client.utils.ClientLogOutput
import org.sonarsource.sonarlint.core.rpc.protocol.common.Language

private const val JUPYTER_PLUGIN_ID = "intellij.jupyter"
private const val DATABASE_PLUGIN_ID = "com.intellij.database"
private const val JAVA_MODULE_ID = "com.intellij.modules.java"
private const val GO_PLUGIN_ID = "org.jetbrains.plugins.go"
Expand All @@ -54,7 +55,6 @@ object EnabledLanguages {
Language.DOCKER,
Language.KUBERNETES,
Language.TERRAFORM,
Language.IPYTHON
)
private val EMBEDDED_PLUGINS_TO_USE_IN_CONNECTED_MODE = listOf(
EmbeddedPlugin(Language.CPP, "CFamily", "sonar-cfamily-plugin-*.jar"),
Expand Down Expand Up @@ -103,6 +103,9 @@ object EnabledLanguages {
if (isIdeModuleEnabled(GO_PLUGIN_ID)) {
enabledLanguages.add(Language.GO)
}
if (isIdeModuleEnabled(JUPYTER_PLUGIN_ID)) {
enabledLanguages.add(Language.IPYTHON)
}
enabledLanguages
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static TextRangeDto computeTextRangeForNotebook(String fileContent, int p
var endLine = prevEndLine;
var lineNumber = 0;
for (var line : fileContent.lines().toList()) {
if (line.startsWith("#%% md")) {
if (line.startsWith("#%% md") || line.startsWith("#%% raw")) {
isMarkdown = true;
} else if (line.startsWith("#%%")) {
isMarkdown = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object VirtualFileUtils {
var isMarkdown = false
val result = StringBuilder()
for (line in fileContent.lines()) {
if (line.startsWith("#%% md")) {
if (line.startsWith("#%% md") || line.startsWith("#%% raw")) {
isMarkdown = true
} else if (line.startsWith("#%%")) {
isMarkdown = false
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/META-INF/plugin-jupyter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--

SonarLint for IntelliJ IDEA
Copyright (C) 2015-2024 SonarSource
[email protected]

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02

-->
<idea-plugin>
</idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<depends optional="true" config-file="plugin-clion.xml">com.intellij.cidr.lang</depends>
<depends optional="true" config-file="plugin-clion-resharper.xml">org.jetbrains.plugins.clion.radler</depends>
<depends optional="true" config-file="plugin-rider.xml">com.intellij.modules.rider</depends>
<depends optional="true" config-file="plugin-jupyter.xml">intellij.jupyter</depends>

<projectListeners>
<listener class="org.sonarlint.intellij.module.ModuleChangeListener" topic="com.intellij.openapi.project.ModuleListener"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TextRangeMatcherTest {
test message
#%%
t = 2
#%% raw
raw
""".trimIndent()

val result = computeTextRangeForNotebook(fileContent, 3, 0, 3, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class VirtualFileUtilsTests : AbstractSonarLintHeavyTests() {
#%% md
test message
#%%
t = 2""".trimIndent()
t = 2
#%% raw
raw""".trimIndent()

val result = removeMarkdownCells(fileContent)

Expand Down
Loading