Skip to content

Commit 102e5c7

Browse files
committed
Merge branch 'main' into feature/rename-refactoring/parametric
2 parents e36e251 + a85b7f9 commit 102e5c7

81 files changed

Lines changed: 2242 additions & 1566 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ jobs:
120120
if: failure()
121121
with:
122122
name: screenshots-${{ matrix.os }}
123-
path: ./rascal-vscode-extension/uitests/**/screenshots/*.png
123+
path: ./rascal-vscode-extension/uitests/screenshots/**/*.png
124124
retention-days: 5
125+
if-no-files-found: error
125126

126127
- name: "cleanup before cache"
127128
shell: bash

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ We are committed to making participation in this community a harassment-free exp
3636

3737
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
3838

39-
[Project Owners](/about/processes.html) have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Contributors who do not follow the Code of Conduct may be removed from the project team.
39+
[Project Owners](http://www.usethesource.io/about/processes.html) have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Contributors who do not follow the Code of Conduct may be removed from the project team.
4040

4141
This code of conduct applies both within project spaces and in public spaces when an individual is representing the UseTheSource community or one of its projects.
4242

43-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by [opening an issue](https://github.com/usethesource/usethesource.github.io/issues) or contacting one or more of the [Project Owners](/projects/).
43+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by [opening an issue](https://github.com/usethesource/usethesource.github.io/issues) or contacting one or more of the [Project Owners](http://www.usethesource.io/projects/).
4444

4545
This Code of Conduct is adapted from the Contributor Covenant, version 1.1.0, available from <http://contributor-covenant.org/version/1/1/0/>
4646

package.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
set -euxo pipefail
44

55
(cd rascal-vscode-extension && npx vsce package )
6-

rascal-lsp/META-INF/RASCAL.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Project-Name: rascal-lsp
2-
Source: src/main/rascal
2+
Source: src/main/rascal/library,src/main/rascal/lsp/

rascal-lsp/pom.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3636
<junit.version>4.13.2</junit.version>
3737
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
38-
<log4j2.version>2.24.3</log4j2.version>
38+
<log4j2.version>2.25.0</log4j2.version>
3939
<lsp4j.version>0.24.0</lsp4j.version>
4040
<sonar.organization>usethesource</sonar.organization>
4141
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -63,7 +63,7 @@
6363
<dependency>
6464
<groupId>org.rascalmpl</groupId>
6565
<artifactId>rascal</artifactId>
66-
<version>0.41.0-RC42</version>
66+
<version>0.41.0-RC54</version>
6767
</dependency>
6868
<!-- Rascal tests require JUnit 4 -->
6969
<dependency>
@@ -165,12 +165,8 @@
165165
<errorsAsWarnings>false</errorsAsWarnings>
166166
<bin>${project.build.outputDirectory}</bin>
167167
<srcs>
168-
<src>${project.basedir}/src/main/rascal</src>
168+
<src>${project.basedir}/src/main/rascal/library</src>
169169
</srcs>
170-
<ignores>
171-
<ignore>${project.basedir}/src/main/rascal/lang/rascal</ignore>
172-
<ignore>${project.basedir}/src/main/rascal/framework</ignore>
173-
</ignores>
174170
</configuration>
175171
</execution>
176172
<execution>
@@ -198,7 +194,7 @@
198194
<ignore>${project.basedir}/src/main/rascal/framework</ignore>
199195
</ignores>
200196
</configuration>
201-
</execution>
197+
</execution>
202198
</executions>
203199
</plugin>
204200

@@ -234,6 +230,13 @@
234230
<groupId>org.apache.maven.plugins</groupId>
235231
<artifactId>maven-shade-plugin</artifactId>
236232
<version>3.6.0</version>
233+
<dependencies>
234+
<dependency> <!-- correctly shade multiple log4j2 depencneis -->
235+
<groupId>org.apache.logging.log4j</groupId>
236+
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
237+
<version>0.2.0</version>
238+
</dependency>
239+
</dependencies>
237240
<executions>
238241
<execution>
239242
<phase>package</phase>
@@ -242,9 +245,12 @@
242245
</goals>
243246
<configuration>
244247
<transformers>
248+
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
249+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
245250
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
246251
<manifestEntries>
247252
<Name>rascal-lsp</Name>
253+
<Multi-Release>true</Multi-Release>
248254
<Main-Class>org.rascalmpl.vscode.lsp.RascalLanguageServer</Main-Class>
249255
<Specification-Version>${project.version}</Specification-Version>
250256
<Specification-Vendor>http://www.usethesource.io</Specification-Vendor>

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/BaseLanguageServer.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.eclipse.lsp4j.InitializeResult;
5252
import org.eclipse.lsp4j.ServerCapabilities;
5353
import org.eclipse.lsp4j.SetTraceParams;
54-
import org.eclipse.lsp4j.WorkspaceFolder;
54+
import org.eclipse.lsp4j.WorkDoneProgressCancelParams;
5555
import org.eclipse.lsp4j.jsonrpc.Launcher;
5656
import org.eclipse.lsp4j.jsonrpc.messages.Tuple.Two;
5757
import org.eclipse.lsp4j.services.LanguageClient;
@@ -67,8 +67,6 @@
6767
import org.rascalmpl.uri.URIUtil;
6868
import org.rascalmpl.values.IRascalValueFactory;
6969
import org.rascalmpl.vscode.lsp.terminal.ITerminalIDEServer.LanguageParameter;
70-
import org.rascalmpl.vscode.lsp.uri.ProjectURIResolver;
71-
import org.rascalmpl.vscode.lsp.uri.TargetURIResolver;
7270
import org.rascalmpl.vscode.lsp.uri.jsonrpc.impl.VSCodeVFSClient;
7371
import org.rascalmpl.vscode.lsp.uri.jsonrpc.messages.PathConfigParameter;
7472
import org.rascalmpl.vscode.lsp.uri.jsonrpc.messages.VFSRegister;
@@ -90,6 +88,7 @@ public abstract class BaseLanguageServer {
9088
private static final @Nullable PrintStream capturedOut;
9189
private static final @Nullable InputStream capturedIn;
9290
private static final boolean DEPLOY_MODE;
91+
private static final String LOG_CONFIGURATION_KEY = "log4j2.configurationFactory";
9392

9493
static {
9594
DEPLOY_MODE = System.getProperty("rascal.lsp.deploy", "false").equalsIgnoreCase("true");
@@ -105,6 +104,8 @@ public abstract class BaseLanguageServer {
105104
capturedOut = null;
106105
}
107106
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
107+
// Do not overwrite existing settings (e.g. passed by the extension)
108+
System.setProperty(LOG_CONFIGURATION_KEY, System.getProperty(LOG_CONFIGURATION_KEY, LogRedirectConfiguration.class.getName()));
108109
}
109110

110111
// hide implicit constructor
@@ -223,25 +224,6 @@ private ActualLanguageServer(Runnable onExit, IBaseTextDocumentService lspDocume
223224
this.onExit = onExit;
224225
this.lspDocumentService = lspDocumentService;
225226
this.lspWorkspaceService = lspWorkspaceService;
226-
reg.registerLogical(new ProjectURIResolver(this::resolveProjectLocation));
227-
reg.registerLogical(new TargetURIResolver(this::resolveProjectLocation));
228-
}
229-
230-
private ISourceLocation resolveProjectLocation(ISourceLocation loc) {
231-
try {
232-
for (WorkspaceFolder folder : lspWorkspaceService.workspaceFolders()) {
233-
if (folder.getName().equals(loc.getAuthority())) {
234-
ISourceLocation root = URIUtil.createFromURI(folder.getUri());
235-
return URIUtil.getChildLocation(root, loc.getPath());
236-
}
237-
}
238-
239-
return loc;
240-
}
241-
catch (URISyntaxException e) {
242-
logger.catching(e);
243-
return loc;
244-
}
245227
}
246228

247229
@Override
@@ -313,7 +295,7 @@ public CompletableFuture<Two<String, URI[]>[]> supplyPathConfig(PathConfigParame
313295
result[0] = new Two<>("Sources", toURIArray(pcfg.getSrcs()));
314296
result[1] = new Two<>("Libraries", toURIArray(pcfg.getLibs()));
315297
return result;
316-
} catch (IOException | URISyntaxException e) {
298+
} catch (URISyntaxException e) {
317299
logger.catching(e);
318300
throw new CompletionException(e);
319301
}
@@ -385,5 +367,10 @@ public void connect(LanguageClient client) {
385367
public void registerVFS(VFSRegister registration) {
386368
VSCodeVFSClient.buildAndRegister(registration.getPort());
387369
}
370+
371+
@Override
372+
public void cancelProgress(WorkDoneProgressCancelParams params) {
373+
lspDocumentService.cancelProgress(params.getToken().getLeft());
374+
}
388375
}
389376
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/IBaseTextDocumentService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
package org.rascalmpl.vscode.lsp;
2828

29+
import java.time.Duration;
2930
import java.util.Set;
3031
import java.util.concurrent.CompletableFuture;
3132

@@ -40,6 +41,9 @@
4041
import io.usethesource.vallang.IValue;
4142

4243
public interface IBaseTextDocumentService extends TextDocumentService {
44+
static final Duration NO_DEBOUNCE = Duration.ZERO;
45+
static final Duration NORMAL_DEBOUNCE = Duration.ofMillis(800);
46+
4347
void initializeServerCapabilities(ServerCapabilities result);
4448
void shutdown();
4549
void connect(LanguageClient client);
@@ -53,4 +57,5 @@ public interface IBaseTextDocumentService extends TextDocumentService {
5357
boolean isManagingFile(ISourceLocation file);
5458

5559
default void didRenameFiles(RenameFilesParams params, Set<ISourceLocation> workspaceFolders) {}
60+
void cancelProgress(String progressId);
5661
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/IRascalFileSystemServices.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ default CompletableFuture<String[]> fileSystemSchemes() {
287287
}
288288

289289
@JsonNotification("rascal/filesystem/onDidChangeFile")
290-
default void onDidChangeFile(FileChangeEvent event) { };
290+
default void onDidChangeFile(FileChangeEvent event) { }
291291

292292

293293
public static class DeleteParameters {
@@ -468,7 +468,7 @@ public ISourceLocation getLocation() throws URISyntaxException {
468468
}
469469
}
470470

471-
public static enum FileChangeType {
471+
public enum FileChangeType {
472472
Changed(1), Created(2), Deleted(3);
473473

474474
private final int value;
@@ -481,7 +481,7 @@ private FileChangeType(int val) {
481481
public int getValue() {
482482
return value;
483483
}
484-
};
484+
}
485485

486486
public static class FileStat {
487487
FileType type;
@@ -501,7 +501,7 @@ public FileStat(FileType type, long ctime, long mtime, long size, @Nullable File
501501

502502
}
503503

504-
public static enum FileType {
504+
public enum FileType {
505505
Unknown(0), File(1), Directory(2), SymbolicLink(64);
506506

507507
private final int value;
@@ -514,11 +514,11 @@ private FileType(int val) {
514514
public int getValue() {
515515
return value;
516516
}
517-
};
517+
}
518518

519519
// this enum models the enum inside vscode, which in the future might become an enum flag
520520
// in that case we have to solve that
521-
public static enum FilePermission {
521+
public enum FilePermission {
522522
Readonly(1);
523523
private final int value;
524524
private FilePermission(int val) {
@@ -632,6 +632,7 @@ private static ResponseError fileNotFound(Object data) {
632632
private static ResponseError noPermissions(Object data) {
633633
return new ResponseError(-5, "No permissions", data);
634634
}
635+
@SuppressWarnings("unused")
635636
private static ResponseError unavailable(Object data) {
636637
return new ResponseError(-6, "Unavailable", data);
637638
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/LSPIDEServices.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
package org.rascalmpl.vscode.lsp;
2828

29-
import java.io.IOException;
3029
import java.io.PrintWriter;
3130
import java.net.URI;
3231
import java.net.URISyntaxException;
@@ -91,19 +90,15 @@ public void browse(URI uri, String title, int viewColumn) {
9190

9291
@Override
9392
public void edit(ISourceLocation path) {
94-
try {
95-
ISourceLocation physical = Locations.toClientLocation(path);
96-
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
97-
params.setTakeFocus(true);
98-
99-
if (physical.hasOffsetLength()) {
100-
params.setSelection(Locations.toRange(physical, docService.getColumnMap(physical)));
101-
}
93+
ISourceLocation physical = Locations.toClientLocation(path);
94+
ShowDocumentParams params = new ShowDocumentParams(physical.getURI().toASCIIString());
95+
params.setTakeFocus(true);
10296

103-
languageClient.showDocument(params);
104-
} catch (IOException e) {
105-
logger.info("ignored edit of {}, because {}", path, e);
97+
if (physical.hasOffsetLength()) {
98+
params.setSelection(Locations.toRange(physical, docService.getColumnMap(physical)));
10699
}
100+
101+
languageClient.showDocument(params);
107102
}
108103

109104
@Override
@@ -200,4 +195,8 @@ public void warning(String message, ISourceLocation src) {
200195
monitor.warning(message, src);
201196
}
202197

198+
public IRascalMonitor getMonitor() {
199+
return monitor;
200+
}
201+
203202
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/RascalLSPMonitor.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
*/
2727
package org.rascalmpl.vscode.lsp;
2828

29+
import java.util.Map;
2930
import java.util.concurrent.CompletableFuture;
31+
import java.util.concurrent.ConcurrentHashMap;
3032
import java.util.function.Function;
33+
3134
import org.apache.logging.log4j.Logger;
3235
import org.eclipse.lsp4j.ProgressParams;
3336
import org.eclipse.lsp4j.WorkDoneProgressBegin;
@@ -37,6 +40,8 @@
3740
import org.eclipse.lsp4j.WorkDoneProgressReport;
3841
import org.eclipse.lsp4j.jsonrpc.messages.Either;
3942
import org.rascalmpl.debug.IRascalMonitor;
43+
import org.rascalmpl.vscode.lsp.util.concurrent.InterruptibleFuture;
44+
4045
import io.usethesource.vallang.ISourceLocation;
4146

4247
/**
@@ -78,7 +83,7 @@ public LSPProgressBar(String rootName, String progressId) {
7883

7984
var msg = new WorkDoneProgressBegin();
8085
msg.setTitle(progressPrefix + rootName);
81-
msg.setCancellable(false);
86+
msg.setCancellable(activeFutures.containsKey(progressId));
8287
notifyProgress(msg);
8388
}
8489

@@ -90,7 +95,7 @@ private void notifyProgress(WorkDoneProgressNotification value) {
9095
public void progress(String message) {
9196
var msg = new WorkDoneProgressReport();
9297
msg.setMessage(message);
93-
msg.setCancellable(false);
98+
msg.setCancellable(activeFutures.containsKey(progressId));
9499
notifyProgress(msg);
95100
}
96101

@@ -126,6 +131,26 @@ private CompletableFuture<Void> retry(Throwable first, int retry, String id) {
126131
}
127132

128133
private final ThreadLocal<LSPProgressBar> activeProgress = new ThreadLocal<>();
134+
private final Map<String, InterruptibleFuture<? extends Object>> activeFutures = new ConcurrentHashMap<>();
135+
136+
/**
137+
* Register a running {@link InterruptibleFuture}, so it can be interrupted later.
138+
* Must be called from the same thread as the corresponding {@link jobStarted}.
139+
* @param name The task name, equal to the one used for {@link jobStarted}.
140+
* @param future The future doing the work.
141+
*/
142+
public void registerActiveFuture(String name, InterruptibleFuture<?> future) {
143+
activeFutures.put(generateProgressId(name), future);
144+
}
145+
146+
/**
147+
* Unregister an {@link InterruptibleFuture} that has finished.
148+
* Must be called from the same thread as the corresponding {@link jobEnded}.
149+
* @param name The task name, equal to the one used for {@link jobEnded}.
150+
*/
151+
public void unregisterActiveFuture(String name) {
152+
activeFutures.remove(generateProgressId(name));
153+
}
129154

130155
@Override
131156
public void jobStart(String name, int workShare, int totalWork) {
@@ -147,7 +172,6 @@ public void jobStart(String name, int workShare, int totalWork) {
147172
private static String generateProgressId(String topLevelName) {
148173
Thread t = Thread.currentThread();
149174
return "T" + Integer.toHexString(t.hashCode()) + "" + Long.toHexString(t.getId()) + "" + Integer.toHexString(System.identityHashCode(topLevelName));
150-
151175
}
152176

153177

@@ -206,4 +230,15 @@ public boolean jobIsCanceled(String name) {
206230
public void warning(String message, ISourceLocation src) {
207231
logger.warn("{} : {}", src, message);
208232
}
233+
234+
/**
235+
* Cancel the running {@link InterruptibleFuture} corresponding to a specific progress bar.
236+
* @param progressId The identifier of the progress bar.
237+
*/
238+
public void cancelProgress(String progressId) {
239+
var future = activeFutures.get(progressId);
240+
if (future != null) {
241+
future.interrupt();
242+
}
243+
}
209244
}

0 commit comments

Comments
 (0)