Skip to content

Commit b79c77e

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/lsp-formatting
2 parents 811a618 + 6d41c46 commit b79c77e

36 files changed

+478
-102
lines changed

rascal-lsp/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<artifactId>log4j-jul</artifactId>
9999
<version>${log4j2.version}</version>
100100
</dependency>
101+
<dependency>
102+
<groupId>org.apache.logging.log4j</groupId>
103+
<artifactId>log4j-layout-template-json</artifactId>
104+
<version>${log4j2.version}</version>
105+
</dependency>
101106
<dependency>
102107
<groupId>org.eclipse.lsp4j</groupId>
103108
<artifactId>org.eclipse.lsp4j.debug</artifactId>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.rascalmpl.uri.URIResolverRegistry;
6767
import org.rascalmpl.uri.URIUtil;
6868
import org.rascalmpl.values.IRascalValueFactory;
69+
import org.rascalmpl.vscode.lsp.log.LogRedirectConfiguration;
6970
import org.rascalmpl.vscode.lsp.terminal.ITerminalIDEServer.LanguageParameter;
7071
import org.rascalmpl.vscode.lsp.uri.jsonrpc.impl.VSCodeVFSClient;
7172
import org.rascalmpl.vscode.lsp.uri.jsonrpc.messages.PathConfigParameter;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.eclipse.lsp4j.services.LanguageClient;
5858
import org.eclipse.lsp4j.services.LanguageClientAware;
5959
import org.eclipse.lsp4j.services.WorkspaceService;
60-
import org.rascalmpl.vscode.lsp.util.locations.Locations;
6160

6261
public class BaseWorkspaceService implements WorkspaceService, LanguageClientAware {
6362
private static final Logger logger = LogManager.getLogger(BaseWorkspaceService.class);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.lsp4j.services.LanguageClient;
3838
import org.eclipse.lsp4j.services.TextDocumentService;
3939
import org.rascalmpl.vscode.lsp.terminal.ITerminalIDEServer.LanguageParameter;
40+
import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps;
4041
import org.rascalmpl.vscode.lsp.util.locations.LineColumnOffsetMap;
4142

4243
import io.usethesource.vallang.ISourceLocation;
@@ -54,11 +55,13 @@ public interface IBaseTextDocumentService extends TextDocumentService {
5455
void unregisterLanguage(LanguageParameter lang);
5556
CompletableFuture<IValue> executeCommand(String languageName, String command);
5657
LineColumnOffsetMap getColumnMap(ISourceLocation file);
58+
ColumnMaps getColumnMaps();
5759
TextDocumentState getDocumentState(ISourceLocation file);
5860

5961
boolean isManagingFile(ISourceLocation file);
6062

6163
void didRenameFiles(RenameFilesParams params, List<WorkspaceFolder> workspaceFolders);
6264
void didDeleteFiles(DeleteFilesParams params);
6365
void cancelProgress(String progressId);
66+
6467
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void registerLocations(IString scheme, IString auth, IMap map) {
148148

149149
@Override
150150
public void registerDiagnostics(IList messages) {
151-
Map<ISourceLocation, List<Diagnostic>> translated = Diagnostics.translateMessages(messages, docService);
151+
Map<ISourceLocation, List<Diagnostic>> translated = Diagnostics.translateMessages(messages, docService.getColumnMaps());
152152

153153
for (Entry<ISourceLocation, List<Diagnostic>> entry : translated.entrySet()) {
154154
String uri = entry.getKey().getURI().toString();
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2018-2025, NWO-I CWI and Swat.engineering
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
* POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package org.rascalmpl.vscode.lsp.log;
28+
29+
import java.net.URI;
30+
31+
import org.apache.logging.log4j.Level;
32+
import org.apache.logging.log4j.core.LoggerContext;
33+
import org.apache.logging.log4j.core.appender.ConsoleAppender;
34+
import org.apache.logging.log4j.core.config.Configuration;
35+
import org.apache.logging.log4j.core.config.ConfigurationFactory;
36+
import org.apache.logging.log4j.core.config.ConfigurationSource;
37+
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
38+
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
39+
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
40+
41+
public class LogJsonConfiguration extends ConfigurationFactory {
42+
43+
@Override
44+
protected String[] getSupportedTypes() {
45+
return new String[] {"*"};
46+
}
47+
48+
49+
50+
@Override
51+
public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation) {
52+
return buildConfiguration();
53+
}
54+
55+
@Override
56+
public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation,
57+
ClassLoader loader) {
58+
return buildConfiguration();
59+
}
60+
61+
@Override
62+
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
63+
return buildConfiguration();
64+
}
65+
66+
private Configuration buildConfiguration() {
67+
Level targetLevel = Level.getLevel(System.getProperty("log4j2.level", "INFO"));
68+
if (targetLevel == null) {
69+
targetLevel = Level.INFO;
70+
}
71+
72+
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
73+
builder.setConfigurationName("JsonLogger");
74+
builder.setStatusLevel(targetLevel);
75+
76+
builder.add(builder
77+
.newAppender("Console", ConsoleAppender.PLUGIN_NAME)
78+
.addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR)
79+
.add(builder.newLayout("JsonTemplateLayout")
80+
/* The JSON template has a max length (buffer size) of 8192 by default:
81+
https://logging.apache.org/log4j/2.x/manual/systemproperties.html#log4j2.encoderByteBufferSize
82+
If JSON documents are longer, the buffer will be flushed in between,
83+
and the JSON arrives truncated on the client side. To prevent his, we cap the max message length. */
84+
.addAttribute("maxStringLength", 6000)
85+
.addAttribute("eventTemplateUri", "classpath:JsonLogTemplate.json")
86+
)
87+
);
88+
89+
builder.add(builder
90+
.newRootLogger(targetLevel)
91+
.add(builder.newAppenderRef("Console"))
92+
);
93+
94+
return builder.build();
95+
}
96+
97+
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/LogRedirectConfiguration.java renamed to rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/log/LogRedirectConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2525
* POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
package org.rascalmpl.vscode.lsp;
27+
package org.rascalmpl.vscode.lsp.log;
2828

2929
import java.net.URI;
3030

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public ParametricTextDocumentService(ExecutorService exec, @Nullable LanguagePar
203203
FallbackResolver.getInstance().registerTextDocumentService(this);
204204
}
205205

206+
@Override
207+
public ColumnMaps getColumnMaps() {
208+
return columns;
209+
}
210+
206211
@Override
207212
public LineColumnOffsetMap getColumnMap(ISourceLocation file) {
208213
return columns.get(file);

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.eclipse.lsp4j.jsonrpc.messages.Either;
3939
import org.rascalmpl.interpreter.NullRascalMonitor;
4040
import org.rascalmpl.shell.ShellEvaluatorFactory;
41-
import org.rascalmpl.uri.URIUtil;
4241
import org.rascalmpl.values.IRascalValueFactory;
4342
import org.rascalmpl.values.RascalFunctionValueFactory;
4443
import org.rascalmpl.values.RascalValueFactory;
@@ -49,7 +48,6 @@
4948

5049
import io.usethesource.vallang.IConstructor;
5150
import io.usethesource.vallang.IList;
52-
import io.usethesource.vallang.IMap;
5351
import io.usethesource.vallang.ISet;
5452
import io.usethesource.vallang.ISourceLocation;
5553
import io.usethesource.vallang.ITuple;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public RascalTextDocumentService(ExecutorService exec) {
159159
FallbackResolver.getInstance().registerTextDocumentService(this);
160160
}
161161

162+
@Override
163+
public ColumnMaps getColumnMaps() {
164+
return columns;
165+
}
166+
162167
@Override
163168
public LineColumnOffsetMap getColumnMap(ISourceLocation file) {
164169
return columns.get(file);

0 commit comments

Comments
 (0)