-
Notifications
You must be signed in to change notification settings - Fork 22
SLLS-345 fall back to window/showMessage for unsupported clients #551
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
Open
sophio-japharidze-sonarsource
wants to merge
1
commit into
master
Choose a base branch
from
SLLS-345_fallBack_to_simple_error_for_some_clients
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...rg/sonarsource/sonarlint/ls/MissingRequirementsNotificationDisplayOptionDeserializer.java
This file contains hidden or 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,52 @@ | ||
| /* | ||
| * SonarLint Language Server | ||
| * Copyright (C) 2009-2025 SonarSource SA | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * 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 02110-1301, USA. | ||
| */ | ||
| package org.sonarsource.sonarlint.ls; | ||
|
|
||
| import com.google.gson.JsonDeserializationContext; | ||
| import com.google.gson.JsonDeserializer; | ||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonParseException; | ||
| import java.lang.reflect.Type; | ||
| import java.util.Locale; | ||
|
|
||
| public class MissingRequirementsNotificationDisplayOptionDeserializer implements | ||
| JsonDeserializer<SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption> { | ||
| @Override | ||
| public SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption deserialize(JsonElement jsonElement, Type type, | ||
| JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
| if (jsonElement.isJsonNull()) { | ||
| return SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.ERROR_ONLY; | ||
| } | ||
|
|
||
| var primitive = jsonElement.getAsJsonPrimitive(); | ||
|
|
||
| if (primitive.isBoolean()) { | ||
| return primitive.getAsBoolean() ? SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.FULL | ||
| : SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.DO_NOT_SHOW_AGAIN; | ||
| } | ||
|
|
||
| return switch (primitive.getAsString().toLowerCase(Locale.US)) { | ||
| case "full" -> SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.FULL; | ||
| case "error_only" -> SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.ERROR_ONLY; | ||
| case "never_again" -> SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.DO_NOT_SHOW_AGAIN; | ||
| default -> throw new JsonParseException("Cannot deserialize missing requirements notifications."); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
...onarsource/sonarlint/ls/MissingRequirementsNotificationDisplayOptionDeserializerTest.java
This file contains hidden or 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,65 @@ | ||
| /* | ||
| * SonarLint Language Server | ||
| * Copyright (C) 2009-2025 SonarSource SA | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * 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 02110-1301, USA. | ||
| */ | ||
| package org.sonarsource.sonarlint.ls; | ||
|
|
||
| import com.google.gson.JsonDeserializationContext; | ||
| import com.google.gson.JsonNull; | ||
| import com.google.gson.JsonParseException; | ||
| import com.google.gson.JsonPrimitive; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| class MissingRequirementsNotificationDisplayOptionDeserializerTest { | ||
| private final JsonDeserializationContext mockContext = mock(JsonDeserializationContext.class); | ||
| private final MissingRequirementsNotificationDisplayOptionDeserializer underTest = new MissingRequirementsNotificationDisplayOptionDeserializer(); | ||
|
|
||
| @Test | ||
| void should_default_to_error_only() { | ||
| var result = underTest.deserialize(JsonNull.INSTANCE, null, mockContext); | ||
|
|
||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.ERROR_ONLY, result); | ||
| } | ||
|
|
||
| @Test | ||
| void should_support_old_clients_with_boolean_values() { | ||
| var trueResult = underTest.deserialize(new JsonPrimitive(true), null, mockContext); | ||
| var falseResult = underTest.deserialize(new JsonPrimitive(false), null, mockContext); | ||
|
|
||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.FULL, trueResult); | ||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.DO_NOT_SHOW_AGAIN, falseResult); | ||
| } | ||
|
|
||
| @Test | ||
| void should_support_new_clients_with_message_display_options() { | ||
| var fullResult = underTest.deserialize(new JsonPrimitive("full"), null, mockContext); | ||
| var errorOnlyResult = underTest.deserialize(new JsonPrimitive("error_only"), null, mockContext); | ||
| var neverAgainResult = underTest.deserialize(new JsonPrimitive("never_again"), null, mockContext); | ||
|
|
||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.FULL, fullResult); | ||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.ERROR_ONLY, errorOnlyResult); | ||
| assertEquals(SonarLintExtendedLanguageClient.MissingRequirementsNotificationDisplayOption.DO_NOT_SHOW_AGAIN, neverAgainResult); | ||
|
|
||
| var randomPrimitive = new JsonPrimitive("random"); | ||
| assertThrows(JsonParseException.class, () -> underTest.deserialize(randomPrimitive, null, mockContext)); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#548 introduced
ShowMissingRequirementsNotificationDeserializerto keep the protocol backward compatible (sonarlint/canShowMissingRequirementsNotificationcan then return boolean and the enum values).This could be extremely helpful, because currently, I know that users of sonarlint.nvim are on different versions. For example, people on Mason did not receive a recent update because mason-org/mason-registry#11979 is blocked for some reason.
If you don't want to include the custom deserializer, then I suppose this is another major version bump, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR with the custom deserialiser. I've added tests for it, and tested manually that it works. Please also double-check on your side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking the time. I wanted to test it locally by building the version on this branch, but the compilation failed because some dependencies are not publicly available:
Is there a public Maven repo that I can add to my Maven settings and that hosts these versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a workaround: I cherry-picked your commit onto the tagged release and then I could build it locally. Then, I could see the error in Neovim based, using this MR