Skip to content

Commit 7ed7028

Browse files
committed
Add disable rule quick fix
1 parent 29c086d commit 7ed7028

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/main/java/org/bsplines/languagetool_languageserver/LanguageToolLanguageServer.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ public class LanguageToolLanguageServer implements LanguageServer, LanguageClien
4545
CodeActionKind.QuickFix + ".ltex.acceptSuggestion";
4646
private static final String addToDictionaryCodeActionKind =
4747
CodeActionKind.QuickFix + ".ltex.addToDictionary";
48+
private static final String disableRuleCodeActionKind =
49+
CodeActionKind.QuickFix + ".ltex.disableRule";
4850
private static final String ignoreRuleInSentenceCodeActionKind =
4951
CodeActionKind.QuickFix + ".ltex.ignoreRuleInSentence";
5052
private static final String addToDictionaryCommandName = "ltex.addToDictionary";
53+
private static final String disableRuleCommandName = "ltex.disableRule";
5154
private static final String ignoreRuleInSentenceCommandName = "ltex.ignoreRuleInSentence";
5255

5356
private static boolean locationOverlaps(
@@ -100,10 +103,10 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
100103
capabilities.setCodeActionProvider(
101104
new CodeActionOptions(Arrays.asList(
102105
acceptSuggestionCodeActionKind, addToDictionaryCodeActionKind,
103-
ignoreRuleInSentenceCodeActionKind)));
106+
disableRuleCodeActionKind, ignoreRuleInSentenceCodeActionKind)));
104107
capabilities.setExecuteCommandProvider(
105108
new ExecuteCommandOptions(Arrays.asList(
106-
addToDictionaryCommandName, ignoreRuleInSentenceCommandName)));
109+
addToDictionaryCommandName, disableRuleCommandName, ignoreRuleInSentenceCommandName)));
107110

108111
// Until it is specified in the LSP that the locale is automatically sent with
109112
// the initialization request, we have to do that manually.
@@ -304,6 +307,22 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(
304307
result.add(Either.forRight(codeAction));
305308
}
306309

310+
{
311+
Command command = new Command(Tools.i18n("disableRule"),
312+
disableRuleCommandName);
313+
JsonObject arguments = new JsonObject();
314+
arguments.addProperty("commandName", disableRuleCommandName);
315+
arguments.addProperty("uri", document.getUri());
316+
arguments.addProperty("ruleId", ruleId);
317+
command.setArguments(Arrays.asList(arguments));
318+
319+
CodeAction codeAction = new CodeAction(command.getTitle());
320+
codeAction.setKind(disableRuleCodeActionKind);
321+
codeAction.setDiagnostics(Collections.singletonList(diagnostic));
322+
codeAction.setCommand(command);
323+
result.add(Either.forRight(codeAction));
324+
}
325+
307326
for (String newWord : match.getSuggestedReplacements()) {
308327
CodeAction codeAction = new CodeAction(Tools.i18n("useWord", newWord));
309328
codeAction.setKind(acceptSuggestionCodeActionKind);
@@ -549,6 +568,7 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
549568
@Override
550569
public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
551570
if (params.getCommand().equals(addToDictionaryCommandName) ||
571+
params.getCommand().equals(disableRuleCommandName) ||
552572
params.getCommand().equals(ignoreRuleInSentenceCommandName)) {
553573
client.telemetryEvent(params.getArguments().get(0));
554574
return CompletableFuture.completedFuture(true);

src/main/resources/MessagesBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ couldNotLoadFalseFriendRules = Could not load false friend rules from "{0}", dis
55
couldNotLoadLanguageModel = Could not load language model rules from "{0}", disabling them: {1}
66
couldNotLoadNeuralNetworkModel = Could not load neural network model rules from "{0}", disabling them: {1}
77
couldNotLoadWord2VecModel = Could not load word2vec model rules from "{0}", disabling them: {1}
8+
disableRule = Disable rule
89
ignoreRuleInThisSentence = Ignore rule in this sentence
910
languageToolFailed = LanguageTool failed: {0}
1011
latexAnnotatedTextBuilderFailed = LatexAnnotatedTextBuilder failed. This is probably a bug in LTeX. Please file a bug report at https://github.com/valentjn/vscode-ltex/issues and attach the LaTeX document (or some equivalent example) for which this occurred.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
addWordToDictionary = '{0}' zum W\u00f6rterbuch hinzuf\u00fcgen
2+
disableRule = Regel deaktivieren
23
ignoreRuleInThisSentence = Regel in diesem Satz ignorieren
34
useWord = '{0}' verwenden

0 commit comments

Comments
 (0)