Skip to content

Commit 9bee119

Browse files
authored
Merge pull request #679 from usethesource/fix/395-cleanup-unused-progress
Clean up `ITerminalIDEServer`
2 parents fd4b3db + 43f129b commit 9bee119

File tree

2 files changed

+10
-236
lines changed

2 files changed

+10
-236
lines changed

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/terminal/ITerminalIDEServer.java

Lines changed: 8 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,6 @@ default void showHTML(BrowseParameter content) {
9696
throw new UnsupportedOperationException();
9797
}
9898

99-
@JsonRequest("rascal/jobStart")
100-
default CompletableFuture<Void> jobStart(JobStartParameter param) {
101-
throw new UnsupportedOperationException();
102-
}
103-
104-
@JsonRequest("rascal/jobStep")
105-
default CompletableFuture<Void> jobStep(JobStepParameter param) {
106-
throw new UnsupportedOperationException();
107-
}
108-
109-
@JsonRequest("rascal/jobEnd")
110-
default CompletableFuture<AmountOfWork> jobEnd(JobEndParameter param) {
111-
throw new UnsupportedOperationException();
112-
}
113-
114-
@JsonRequest("rascal/jobIsCanceled")
115-
default CompletableFuture<BooleanParameter> jobIsCanceled() {
116-
throw new UnsupportedOperationException();
117-
}
118-
119-
@JsonRequest("rascal/jobTodo")
120-
default CompletableFuture<Void> jobTodo(AmountOfWork param) {
121-
throw new UnsupportedOperationException();
122-
}
123-
124-
@JsonNotification("rascal/warning")
125-
default void warning(WarningMessage param) {
126-
throw new UnsupportedOperationException();
127-
}
128-
12999
@JsonNotification("rascal/registerLocations")
130100
default void registerLocations(RegisterLocationsParameters param) {
131101
throw new UnsupportedOperationException();
@@ -206,121 +176,6 @@ public String getRawAuthority() {
206176

207177
}
208178

209-
public static class WarningMessage {
210-
private final String location;
211-
private final String message;
212-
213-
public WarningMessage(String message, ISourceLocation src) {
214-
this.message = message;
215-
this.location = src.toString();
216-
}
217-
218-
public String getMessage() {
219-
return message;
220-
}
221-
222-
public ISourceLocation getLocation() {
223-
return buildLocation(location);
224-
}
225-
226-
}
227-
228-
private static ISourceLocation buildLocation(String location) throws FactTypeUseException {
229-
try {
230-
return (ISourceLocation) new StandardTextReader().read(IRascalValueFactory.getInstance(), TypeFactory.getInstance().sourceLocationType(), new StringReader(location));
231-
} catch (IOException e) {
232-
throw new RuntimeException("this should never happen:", e);
233-
}
234-
}
235-
public static class AmountOfWork {
236-
private final int amount;
237-
238-
public AmountOfWork(int amount) {
239-
this.amount = amount;
240-
}
241-
242-
public int getAmount() {
243-
return amount;
244-
}
245-
}
246-
247-
public static class BooleanParameter {
248-
private final boolean truth;
249-
250-
public BooleanParameter(boolean s) {
251-
this.truth = s;
252-
}
253-
254-
public boolean isTrue() {
255-
return truth;
256-
}
257-
}
258-
public static class JobStartParameter {
259-
private final String name;
260-
private final int workShare;
261-
private final int totalWork;
262-
263-
public JobStartParameter(String name, int workShare, int totalWork) {
264-
this.name = name;
265-
this.workShare = workShare;
266-
this.totalWork = totalWork;
267-
}
268-
269-
public String getName() {
270-
return name;
271-
}
272-
273-
public int getTotalWork() {
274-
return totalWork;
275-
}
276-
277-
public int getWorkShare() {
278-
return workShare;
279-
}
280-
}
281-
282-
public static class JobStepParameter {
283-
private final String name;
284-
private final String message;
285-
private final int inc;
286-
287-
public JobStepParameter(String name, String message, int inc) {
288-
this.name = name;
289-
this.message = message;
290-
this.inc = inc;
291-
}
292-
293-
public String getName() {
294-
return name;
295-
}
296-
297-
public String getMessage() {
298-
return message;
299-
}
300-
301-
public int getInc() {
302-
return inc;
303-
}
304-
}
305-
306-
public static class JobEndParameter {
307-
private final String name;
308-
private final boolean success;
309-
310-
public JobEndParameter(String name, boolean total) {
311-
this.name = name;
312-
this.success = total;
313-
}
314-
315-
public String getName() {
316-
return name;
317-
}
318-
319-
public boolean getSuccess() {
320-
return success;
321-
}
322-
}
323-
324179
public static String value2string(IValue value) {
325180
final Encoder encoder = Base64.getEncoder();
326181
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
@@ -378,18 +233,6 @@ public String toString() {
378233
}
379234
}
380235

381-
public static class JobCanceledParameter {
382-
private String jobName;
383-
384-
public JobCanceledParameter(String jobName) {
385-
this.jobName = jobName;
386-
}
387-
388-
public String getModule() {
389-
return jobName;
390-
}
391-
}
392-
393236
public static class BrowseParameter {
394237
private String uri;
395238
private String title;
@@ -599,5 +442,13 @@ public String toString() {
599442
+ ", nonTerminalIsStart=" + nonTerminalIsStart + ", allowAmbiguity=" + allowAmbiguity + "]";
600443
}
601444

445+
private static ISourceLocation buildLocation(String location) throws FactTypeUseException {
446+
try {
447+
return (ISourceLocation) new StandardTextReader().read(IRascalValueFactory.getInstance(), TypeFactory.getInstance().sourceLocationType(), new StringReader(location));
448+
} catch (IOException e) {
449+
throw new RuntimeException("this should never happen:", e);
450+
}
451+
}
452+
602453
}
603454
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/terminal/TerminalIDEServer.java

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,19 @@
2828

2929
import java.net.URISyntaxException;
3030
import java.util.Collections;
31-
import java.util.HashSet;
3231
import java.util.List;
3332
import java.util.Map;
3433
import java.util.Map.Entry;
35-
import java.util.Set;
3634
import java.util.concurrent.CompletableFuture;
35+
3736
import org.apache.logging.log4j.LogManager;
3837
import org.apache.logging.log4j.Logger;
3938
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
4039
import org.eclipse.lsp4j.Diagnostic;
41-
import org.eclipse.lsp4j.MessageParams;
42-
import org.eclipse.lsp4j.MessageType;
43-
import org.eclipse.lsp4j.ProgressParams;
4440
import org.eclipse.lsp4j.PublishDiagnosticsParams;
4541
import org.eclipse.lsp4j.ShowDocumentParams;
4642
import org.eclipse.lsp4j.ShowDocumentResult;
47-
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
48-
import org.eclipse.lsp4j.WorkDoneProgressEnd;
49-
import org.eclipse.lsp4j.WorkDoneProgressReport;
5043
import org.eclipse.lsp4j.WorkspaceFolder;
51-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
5244
import org.rascalmpl.uri.LogicalMapResolver;
5345
import org.rascalmpl.uri.URIResolverRegistry;
5446
import org.rascalmpl.uri.URIUtil;
@@ -58,6 +50,7 @@
5850
import org.rascalmpl.vscode.lsp.util.Diagnostics;
5951
import org.rascalmpl.vscode.lsp.util.DocumentChanges;
6052
import org.rascalmpl.vscode.lsp.util.locations.Locations;
53+
6154
import io.usethesource.vallang.IList;
6255
import io.usethesource.vallang.ISourceLocation;
6356
import io.usethesource.vallang.IValue;
@@ -70,7 +63,6 @@ public class TerminalIDEServer implements ITerminalIDEServer {
7063
private static final Logger logger = LogManager.getLogger(TerminalIDEServer.class);
7164

7265
private final IBaseLanguageClient languageClient;
73-
private final Set<String> jobs = new HashSet<>();
7466
private final IBaseTextDocumentService docService;
7567
private final BaseWorkspaceService workspaceService;
7668

@@ -146,75 +138,6 @@ public CompletableFuture<Void> applyDocumentEdits(DocumentEditsParameter edits)
146138
languageClient.applyEdit(new ApplyWorkspaceEditParams(DocumentChanges.translateDocumentChanges(docService, list))));
147139
}
148140

149-
@Override
150-
public CompletableFuture<Void> jobStart(JobStartParameter param) {
151-
// TODO does this have the intended semantics?
152-
if (!jobs.contains(param.getName())) {
153-
jobs.add(param.getName());
154-
return languageClient.createProgress(new WorkDoneProgressCreateParams(Either.forLeft(param.getName())));
155-
}
156-
else {
157-
logger.debug("job {} was already running. ignored.", param.getName());
158-
return CompletableFuture.completedFuture(null);
159-
}
160-
}
161-
162-
@Override
163-
public CompletableFuture<Void> jobStep(JobStepParameter param) {
164-
if (jobs.contains(param.getName())) {
165-
return CompletableFuture.supplyAsync(() -> {
166-
languageClient.notifyProgress(
167-
new ProgressParams(
168-
Either.forLeft(param.getName()),
169-
Either.forLeft(new WorkDoneProgressReport()))
170-
);
171-
return null;
172-
}
173-
);
174-
}
175-
else {
176-
logger.debug("stepping a job that does not exist: {}", param.getName());
177-
return CompletableFuture.completedFuture(null);
178-
}
179-
}
180-
181-
@Override
182-
public CompletableFuture<AmountOfWork> jobEnd(JobEndParameter param) {
183-
if (jobs.contains(param.getName())) {
184-
jobs.remove(param.getName());
185-
return CompletableFuture.supplyAsync(() -> {
186-
languageClient.notifyProgress(
187-
new ProgressParams(
188-
Either.forLeft(param.getName()),
189-
Either.forLeft(new WorkDoneProgressEnd())
190-
));
191-
return new AmountOfWork(1);
192-
}
193-
);
194-
}
195-
else {
196-
logger.debug("ended an non-existing job: {}", param.getName());
197-
return CompletableFuture.completedFuture(new AmountOfWork(1));
198-
}
199-
}
200-
201-
@Override
202-
public CompletableFuture<Void> jobTodo(AmountOfWork param) {
203-
// TODO think of how to implement this
204-
return CompletableFuture.completedFuture(null);
205-
}
206-
207-
@Override
208-
public CompletableFuture<BooleanParameter> jobIsCanceled() {
209-
// TODO think of how to implement this
210-
return CompletableFuture.completedFuture(new BooleanParameter(false));
211-
}
212-
213-
@Override
214-
public void warning(WarningMessage param) {
215-
languageClient.showMessage(new MessageParams(MessageType.Warning, param.getLocation() + ":" + param.getMessage()));
216-
}
217-
218141
@Override
219142
public void registerLocations(RegisterLocationsParameters param) {
220143
URIResolverRegistry.getInstance().registerLogical(

0 commit comments

Comments
 (0)