Skip to content

Commit

Permalink
Replace ltex/progress with LSP's $/progress
Browse files Browse the repository at this point in the history
Fixes #34.
  • Loading branch information
valentjn committed Dec 12, 2020
1 parent 73143c6 commit 62b3020
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 95 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

# Changelog

## 9.0.0 (upcoming)

- Make versioning independent of vscode-ltex; LT<sub>E</sub>X LS now adheres to [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html)
- Require support of LSP 3.15
- Replace `ltex/progress` with `$/progress` (fixes [#34](https://github.com/valentjn/ltex-ls/issues/34))

## 8.1.1 (November 24, 2020)

- Migrate from Travis CI to GitHub Actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.ConfigurationParams;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.services.LanguageClient;

public interface LtexLanguageClient extends LanguageClient {
@JsonRequest("ltex/workspaceSpecificConfiguration")
CompletableFuture<List<Object>> ltexWorkspaceSpecificConfiguration(ConfigurationParams params);

@JsonNotification("ltex/progress")
void ltexProgress(LtexProgressParams params);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.bsplines.ltexls.client.LtexLanguageClient;
import org.bsplines.ltexls.client.LtexProgressParams;
import org.bsplines.ltexls.languagetool.LanguageToolRuleMatch;
import org.bsplines.ltexls.parsing.AnnotatedTextFragment;
import org.bsplines.ltexls.tools.Tools;
Expand All @@ -23,17 +22,22 @@
import org.eclipse.lsp4j.ConfigurationParams;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.ProgressParams;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
import org.eclipse.lsp4j.TextDocumentItem;
import org.eclipse.lsp4j.WorkDoneProgressBegin;
import org.eclipse.lsp4j.WorkDoneProgressEnd;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.xtext.xbase.lib.Pair;

public class LtexTextDocumentItem extends TextDocumentItem {
private LtexLanguageServer languageServer;
private List<Integer> lineStartPosList;
private @Nullable Pair<List<LanguageToolRuleMatch>, List<AnnotatedTextFragment>> checkingResult;
private @Nullable List<Diagnostic> diagnostics;
private ProgressTokenGenerator progressTokenGenerator;
private @Nullable Position caretPosition;
private Instant lastCaretChangeInstant;

Expand All @@ -44,6 +48,7 @@ public LtexTextDocumentItem(LtexLanguageServer languageServer,
this.lineStartPosList = new ArrayList<>();
this.checkingResult = null;
this.diagnostics = null;
this.progressTokenGenerator = new ProgressTokenGenerator();
this.caretPosition = null;
this.lastCaretChangeInstant = Instant.now();
reinitializeLineStartPosList(text, this.lineStartPosList);
Expand Down Expand Up @@ -400,6 +405,16 @@ public CompletableFuture<Pair<List<LanguageToolRuleMatch>, List<AnnotatedTextFra
}

String uri = getUri();

WorkDoneProgressBegin workDoneProgressBegin = new WorkDoneProgressBegin();
workDoneProgressBegin.setTitle(Tools.i18n("checkingUri", uri));
workDoneProgressBegin.setCancellable(false);

Either<String, Number> progressToken =
this.progressTokenGenerator.generate(uri, "checkDocument");

languageClient.notifyProgress(new ProgressParams(progressToken, workDoneProgressBegin));

ConfigurationItem configurationItem = new ConfigurationItem();
configurationItem.setScopeUri(uri);
configurationItem.setSection("ltex");
Expand All @@ -411,20 +426,19 @@ public CompletableFuture<Pair<List<LanguageToolRuleMatch>, List<AnnotatedTextFra
CompletableFuture<List<Object>> workspaceSpecificConfigurationFuture =
languageClient.ltexWorkspaceSpecificConfiguration(configurationParams);

languageClient.ltexProgress(new LtexProgressParams(uri, "checkDocument", 0));

return configurationFuture.thenCombine(workspaceSpecificConfigurationFuture,
(List<Object> configuration, List<Object> workspaceSpecificConfiguration) -> {
try {
this.languageServer.getSettingsManager().setSettings(
(JsonElement)configuration.get(0),
(JsonElement)workspaceSpecificConfiguration.get(0));
this.checkingResult = this.languageServer.getDocumentChecker().check(this);
return this.checkingResult;
} finally {
if (languageClient != null) {
languageClient.ltexProgress(new LtexProgressParams(uri, "checkDocument", 1));
}
this.languageServer.getSettingsManager().setSettings(
(JsonElement)configuration.get(0),
(JsonElement)workspaceSpecificConfiguration.get(0));
this.checkingResult = this.languageServer.getDocumentChecker().check(this);
return this.checkingResult;
}).whenComplete((
Pair<List<LanguageToolRuleMatch>, List<AnnotatedTextFragment>> checkingResult,
Throwable e) -> {
if (languageClient != null) {
languageClient.notifyProgress(new ProgressParams(
progressToken, new WorkDoneProgressEnd()));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (C) 2020 Julian Valentin, LTeX Development Community
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package org.bsplines.ltexls.server;

import com.google.gson.JsonObject;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

public class ProgressTokenGenerator {
private int counter;

public ProgressTokenGenerator() {
this.counter = 0;
}

public Either<String, Number> generate(String uri, String operation) {
JsonObject jsonToken = new JsonObject();
jsonToken.addProperty("uri", uri);
jsonToken.addProperty("operation", operation);
jsonToken.addProperty("counter", this.counter);
this.counter++;
return Either.forLeft(jsonToken.toString());
}
}
3 changes: 2 additions & 1 deletion ltexls-core/src/main/resources/MessagesBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

addAllUnknownWordsInSelectionToDictionary = Add all unknown words in selection to dictionary
addWordToDictionary = Add '{0}' to dictionary
checkingText = Checking the following text in language '{0}' via LanguageTool: "{1}"{2}
checkingDone = Checking done in {0}ms
checkingText = Checking the following text in language '{0}' via LanguageTool: "{1}"{2}
checkingUri = Checking '{0}'...
codeLanguageNotSupported = Code language '{0}' is not supported
couldNotDeleteTemporaryFile = Could not delete temporary file '{0}'
couldNotFindDocumentWithUri = Could not find document with URI '{0}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
addAllUnknownWordsInSelectionToDictionary = Alle unbekannten W\u00f6rter in Auswahl zum \
W\u00f6rterbuch hinzuf\u00fcgen
addWordToDictionary = '{0}' zum W\u00f6rterbuch hinzuf\u00fcgen
checkingUri = \u00dcberpr\u00fcfe '{0}' ...
couldNotParseDocumentUri = Parsen der Dokument-URI fehlgeschlagen
couldNotReadFile = Lesen der Datei '{0}' fehlgeschlagen
couldNotWriteFile = Schreiben der Datei '{0}' fehlgeschlagen
Expand Down
104 changes: 60 additions & 44 deletions ltexls-core/src/test/resources/LtexLanguageServerTestLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ Params: {
}


[Trace - 12:45:12 PM] Received notification '$/progress'.
Params: {
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":0}",
"value": {
"kind": "begin",
"title": "Checking 'untitled:Untitled-1'...",
"cancellable": false
}
}


[Trace - 12:45:12 PM] Received request 'workspace/configuration - (1)'.
Params: {
"items": [
Expand Down Expand Up @@ -457,19 +468,12 @@ Result: [
]


[Trace - 12:45:12 PM] Received notification 'ltex/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 0
}


[Trace - 12:45:13 PM] Received notification 'ltex/progress'.
[Trace - 12:45:13 PM] Received notification '$/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 1
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":0}",
"value": {
"kind": "end"
}
}


Expand All @@ -494,6 +498,17 @@ Params: {
}


[Trace - 12:45:22 PM] Received notification '$/progress'.
Params: {
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":1}",
"value": {
"kind": "begin",
"title": "Checking 'untitled:Untitled-1'...",
"cancellable": false
}
}


[Trace - 12:45:22 PM] Received request 'workspace/configuration - (3)'.
Params: {
"items": [
Expand Down Expand Up @@ -589,19 +604,12 @@ Result: [
]


[Trace - 12:45:22 PM] Received notification 'ltex/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 0
}


[Trace - 12:46:06 PM] Received notification 'ltex/progress'.
[Trace - 12:46:06 PM] Received notification '$/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 1
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":1}",
"value": {
"kind": "end"
}
}


Expand Down Expand Up @@ -1183,6 +1191,17 @@ Params: {
}


[Trace - 12:46:30 PM] Received notification '$/progress'.
Params: {
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":2}",
"value": {
"kind": "begin",
"title": "Checking 'untitled:Untitled-1'...",
"cancellable": false
}
}


[Trace - 12:46:30 PM] Received request 'workspace/configuration - (5)'.
Params: {
"items": [
Expand Down Expand Up @@ -1278,11 +1297,14 @@ Result: [
]


[Trace - 12:46:30 PM] Received notification 'ltex/progress'.
[Trace - 12:46:30 PM] Received notification '$/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 0
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":3}",
"value": {
"kind": "begin",
"title": "Checking 'untitled:Untitled-1'...",
"cancellable": false
}
}


Expand Down Expand Up @@ -1381,19 +1403,12 @@ Result: [
]


[Trace - 12:46:30 PM] Received notification 'ltex/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 0
}


[Trace - 12:46:30 PM] Received notification 'ltex/progress'.
[Trace - 12:46:30 PM] Received notification '$/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 1
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":2}",
"value": {
"kind": "end"
}
}


Expand All @@ -1420,11 +1435,12 @@ Params: {
}


[Trace - 12:46:30 PM] Received notification 'ltex/progress'.
[Trace - 12:46:30 PM] Received notification '$/progress'.
Params: {
"uri": "untitled:Untitled-1",
"operation": "checkDocument",
"progress": 1
"token": "{\"uri\":\"untitled:Untitled-1\",\"operation\":\"checkDocument\",\"counter\":3}",
"value": {
"kind": "end"
}
}


Expand Down

0 comments on commit 62b3020

Please sign in to comment.