Skip to content

Commit ab71fe8

Browse files
committed
Release 0.0.38
1 parent 5ef404c commit ab71fe8

File tree

8 files changed

+39
-63
lines changed

8 files changed

+39
-63
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LiquidJava VS Code Extension
22

3-
The **LiquidJava VS Code extension** adds support for **refinement types**, extending the Java standard type system directly inside VS Code, using the [LiquidJava](https://github.com/CatarinaGamboa/liquidjava) verifier. It provides error diagnostics and syntax highlighting for refinements.
3+
The **LiquidJava VS Code extension** adds support for **refinement types**, extending the Java standard type system directly inside VS Code, using the [LiquidJava](https://github.com/liquid-java/liquidjava) verifier. It provides error diagnostics and syntax highlighting for refinements.
44

55
## Getting Started
66

@@ -14,7 +14,7 @@ To try out the extension on an example project without setting up your local env
1414

1515
The codespace will open in your browser and automatically install the LiquidJava extension shortly.
1616

17-
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/CatarinaGamboa/liquidjava-examples)
17+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/liquid-java/liquidjava-examples)
1818

1919
### Local Setup
2020

client/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LiquidJava - Extending Java with Liquid Types
22

3-
![](https://raw.githubusercontent.com/CatarinaGamboa/liquidjava/refs/heads/main/docs/design/figs/banner.gif)
3+
![](https://raw.githubusercontent.com/liquid-java/liquidjava/refs/heads/main/docs/design/figs/banner.gif)
44

55
### Extend your Java code with Liquid Types and catch bugs earlier!
66

@@ -15,7 +15,7 @@ a = -8; // type error!
1515
### Installation
1616

1717
This extension depends on the [Language Support for Java(TM) by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) VS Code extension.
18-
Additionally, to use LiquidJava in your project, you'll need the following dependency, which includes the LiquidJava API annotations:
18+
Additionally, to use LiquidJava in your project, you'll need the following dependency, which includes the LiquidJava annotations:
1919

2020
#### Maven
2121
```xml
@@ -45,7 +45,7 @@ Liquid types, or refinement types, extend a language with **logical predicates**
4545

4646
#### Refinements
4747

48-
To refine a variable, parameter or return value, use the annotation `@Refinement` with a predicate as argument. The predicate must be a boolean expression that uses the name of the variable being refined (or `_`) to refer to its value. Some examples include:
48+
To refine a variable, parameter or return value, use the `@Refinement` annotation with a predicate as an argument. The predicate must be a boolean expression that uses the name of the variable being refined (or `_`) to refer to its value. Some examples include:
4949

5050
```java
5151
// x must be greater than 0
@@ -137,8 +137,10 @@ s.pop(); // type error!
137137

138138
```
139139

140-
You can find more examples of how to use LiquidJava on the [LiquidJava Website](https://catarinagamboa.github.io/liquidjava.html). For more information, check the following repositories:
141-
- [liquidjava](https://github.com/CatarinaGamboa/liquidjava): Main repository with API, verifier and some examples
142-
- [vscode-liquidjava](https://github.com/CatarinaGamboa/vscode-liquidjava): Source code of this VS Code extension
143-
- [liquidjava-examples](https://github.com/CatarinaGamboa/liquidjava-examples): Repository with more usage examples of LiquidJava
144-
- [liquid-java-external-libs](https://github.com/CatarinaGamboa/liquid-java-external-libs): Examples of how to use LiquidJava with external libraries
140+
You can find more examples of how to use LiquidJava on the [LiquidJava Website](https://liquid-java.github.io). To learn how to use LiquidJava, you can also follow the [LiquidJava tutorial](https://github.com/liquid-java/liquidjava-tutorial).
141+
142+
For more information, check the following repositories:
143+
- [liquidjava](https://github.com/liquid-java/liquidjava): Includes the API, verifier and some examples
144+
- [vscode-liquidjava](https://github.com/liquid-java/vscode-liquidjava): Source code of this VS Code extension
145+
- [liquidjava-examples](https://github.com/liquid-java/liquidjava-examples): Examples of how to use LiquidJava
146+
- [liquid-java-external-libs](https://github.com/liquid-java/liquid-java-external-libs): Examples of how to use LiquidJava to refine external libraries

client/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "liquid-java",
33
"displayName": "LiquidJava",
4-
"description": "LiquidJava - Extending Java with Liquid Types",
5-
"version": "0.0.37",
4+
"description": "Extending Java with Liquid Types",
5+
"version": "0.0.38",
66
"publisher": "AlcidesFonseca",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/CatarinaGamboa/vscode-liquidjava"
9+
"url": "https://github.com/liquid-java/vscode-liquidjava"
1010
},
11-
"homepage": "https://catarinagamboa.github.io/liquidjava",
11+
"homepage": "https://liquid-java.github.io",
1212
"engines": {
1313
"vscode": "^1.70.0"
1414
},
@@ -27,6 +27,8 @@
2727
"keywords": [
2828
"java",
2929
"liquidjava",
30+
"liquid java",
31+
"liquid-java",
3032
"liquid types",
3133
"refinement types",
3234
"static analysis",
-441 Bytes
Binary file not shown.

server/src/main/java/App.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ public class App {
1212

1313
final static int DEFAULT_PORT = 50000;
1414

15-
public static void main(String[] args) throws Exception {
15+
public static void main(String[] args) {
1616
final int port = args.length > 0 ? Integer.parseInt(args[0]) : DEFAULT_PORT;
1717
System.out.println("Starting server on port: " + port);
1818
new App().startNetworkedLanguageServer(port);
1919
}
2020

2121
/**
2222
* Starts the language server on the given port in a new thread
23-
*
24-
* @param port
23+
* @param port the port to start the server on
2524
*/
2625
private void startNetworkedLanguageServer(int port) {
2726
new Thread(() -> {
@@ -34,7 +33,7 @@ private void startNetworkedLanguageServer(int port) {
3433
OutputStream out = socket.getOutputStream();
3534
LJLanguageServer server = new LJLanguageServer();
3635
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, in, out);
37-
server.connect(launcher.getRemoteProxy(), launcher.getRemoteEndpoint());
36+
server.connect(launcher.getRemoteProxy());
3837
launcher.startListening();
3938
} catch (IOException e) {
4039
System.out.println("Error: " + e.getMessage());

server/src/main/java/LJDiagnostics.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import java.io.UnsupportedEncodingException;
21
import java.nio.charset.StandardCharsets;
32
import java.util.ArrayList;
43
import java.util.Collections;
@@ -34,13 +33,13 @@ public static List<PublishDiagnosticsParams> generateDiagnostics(String uri) {
3433
if (diagnostics.foundError()) {
3534
System.out.println("Failed verification");
3635
List<LJDiagnostic> errors = new ArrayList<>(diagnostics.getErrors());
37-
result.addAll(getDiagnostics(uri, errors, DiagnosticSeverity.Error));
36+
result.addAll(getDiagnostics(errors, DiagnosticSeverity.Error));
3837
} else {
3938
System.out.println("Passed verification");
4039
}
4140
if (diagnostics.foundWarning()) {
4241
List<LJDiagnostic> warnings = new ArrayList<>(diagnostics.getWarnings());
43-
result.addAll(getDiagnostics(uri, warnings, DiagnosticSeverity.Warning));
42+
result.addAll(getDiagnostics(warnings, DiagnosticSeverity.Warning));
4443
}
4544
return result.isEmpty() ? List.of(getEmptyDiagnostics(uri)) : result;
4645
} catch (Exception e) {
@@ -51,10 +50,9 @@ public static List<PublishDiagnosticsParams> generateDiagnostics(String uri) {
5150

5251
/**
5352
* Generates error and warning diagnostics
54-
* @param uri the uri used for the verification
5553
* @return diagnostics
5654
*/
57-
public static List<PublishDiagnosticsParams> getDiagnostics(String uri, List<LJDiagnostic> diagnostics,
55+
public static List<PublishDiagnosticsParams> getDiagnostics(List<LJDiagnostic> diagnostics,
5856
DiagnosticSeverity severity) {
5957
return diagnostics.stream().map(d -> {
6058
String filePath = FILE_PREFIX + d.getFile();
@@ -77,7 +75,7 @@ public static PublishDiagnosticsParams getEmptyDiagnostics(String uri) {
7775
/**
7876
* Extracts the base path from the given full path
7977
* e.g. file://path/to/project/src/main/path/to/File.java => /path/to/project/src/main
80-
* @param fullPath
78+
* @param fullPath the full path
8179
* @return base path
8280
*/
8381
private static String extractBasePath(String fullPath) {
@@ -91,21 +89,16 @@ private static String extractBasePath(String fullPath) {
9189

9290
/**
9391
* Converts a UTF-8 encoded string to a regular string
94-
* @param source
92+
* @param source the UTF-8 encoded string
9593
* @return converted string
9694
*/
9795
private static String convertUTFtoCharacters(String source) {
98-
try {
99-
return java.net.URLDecoder.decode(source, StandardCharsets.UTF_8.name());
100-
} catch (UnsupportedEncodingException e) {
101-
// not going to happen - value came from JDK's own StandardCharsets
102-
return null;
103-
}
96+
return java.net.URLDecoder.decode(source, StandardCharsets.UTF_8);
10497
}
10598

10699
/**
107100
* Gets the Range from the given ErrorPosition If the position is null, returns a default Range at (0,0)-(0,0)
108-
* @param pos
101+
* @param pos the ErrorPosition
109102
* @return Range
110103
*/
111104
private static Range getRangeFromErrorPosition(ErrorPosition pos) {

server/src/main/java/LJDiagnosticsService.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import java.io.File;
22
import java.net.URI;
3-
import java.util.HashSet;
4-
import java.util.Set;
53

64
import org.eclipse.lsp4j.DidChangeConfigurationParams;
75
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
@@ -15,51 +13,36 @@
1513

1614
public class LJDiagnosticsService implements TextDocumentService, WorkspaceService {
1715
private LanguageClient client;
18-
private Set<String> checkedUris = new HashSet<>();
1916

2017
/**
2118
* Sets the language client
22-
*
23-
* @param client
19+
* @param client the language client
2420
*/
2521
public void setClient(LanguageClient client) {
2622
this.client = client;
2723
}
2824

2925
/**
3026
* Generates diagnostics for the given URI and publishes them to the client
31-
*
32-
* @param uri
27+
* @param uri the URI of the document
3328
*/
3429
public void generateDiagnostics(String uri) {
3530
var paramsList = LJDiagnostics.generateDiagnostics(uri);
3631
paramsList.forEach(params -> {
3732
this.client.publishDiagnostics(params);
38-
this.checkedUris.add(params.getUri());
3933
});
4034
}
4135

42-
/**
43-
* Clears all published diagnostics
44-
*/
45-
public void clearDiagnostics() {
46-
this.checkedUris.forEach(uri -> this.client.publishDiagnostics(LJDiagnostics.getEmptyDiagnostics(uri)));
47-
this.checkedUris.clear();
48-
}
49-
5036
/**
5137
* Clear a diagnostic for a specific URI
52-
*
53-
* @param uri
38+
* @param uri the URI of the document
5439
*/
5540
public void clearDiagnostic(String uri) {
5641
this.client.publishDiagnostics(LJDiagnostics.getEmptyDiagnostics(uri));
57-
this.checkedUris.remove(uri);
5842
}
5943

6044
/**
6145
* Checks diagnostics when a document is opened
62-
*
6346
* @param params
6447
*/
6548
@Override
@@ -70,19 +53,18 @@ public void didOpen(DidOpenTextDocumentParams params) {
7053

7154
/**
7255
* Checks diagnostics when a document is saved
73-
*
7456
* @param params
7557
*/
7658
@Override
7759
public void didSave(DidSaveTextDocumentParams params) {
7860
System.out.println("Document saved — checking diagnostics");
79-
clearDiagnostics();
80-
generateDiagnostics(params.getTextDocument().getUri());
61+
String uri = params.getTextDocument().getUri();
62+
clearDiagnostic(uri);
63+
generateDiagnostics(uri);
8164
}
8265

8366
/**
8467
* Clears diagnostics for a deleted document
85-
*
8668
* @param params
8769
*/
8870
@Override

server/src/main/java/LJLanguageServer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.eclipse.lsp4j.TextDocumentSyncKind;
77
import org.eclipse.lsp4j.WorkspaceFoldersOptions;
88
import org.eclipse.lsp4j.WorkspaceServerCapabilities;
9-
import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint;
109
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
1110
import org.eclipse.lsp4j.services.LanguageClient;
1211
import org.eclipse.lsp4j.services.LanguageServer;
@@ -15,21 +14,19 @@
1514

1615
public class LJLanguageServer implements LanguageServer {
1716

18-
private LJDiagnosticsService diagnosticsService;
17+
private final LJDiagnosticsService diagnosticsService;
1918

2019
public LJLanguageServer() {
2120
this.diagnosticsService = new LJDiagnosticsService();
2221
}
2322

2423
/**
2524
* Initializes the language server with the given parameters
26-
*
27-
* @param params
28-
*
25+
* @param params the initialize parameters
2926
* @return CompletableFuture with the InitializeResult
3027
*/
3128
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
32-
CompletableFuture<InitializeResult> completableFuture = new CompletableFuture<InitializeResult>();
29+
CompletableFuture<InitializeResult> completableFuture = new CompletableFuture<>();
3330
ServerCapabilities capabilities = new ServerCapabilities();
3431
WorkspaceServerCapabilities workspaceServerCapabilities = new WorkspaceServerCapabilities();
3532
WorkspaceFoldersOptions workspaceFoldersOptions = new WorkspaceFoldersOptions();
@@ -65,10 +62,11 @@ public WorkspaceService getWorkspaceService() {
6562
return diagnosticsService;
6663
}
6764

68-
public void connect(LanguageClient remoteProxy, RemoteEndpoint remoteEndpoint) {
65+
public void connect(LanguageClient remoteProxy) {
6966
diagnosticsService.setClient(remoteProxy);
7067
}
7168

69+
@SuppressWarnings("unused")
7270
@JsonNotification("$/setTraceNotification")
7371
public void setTrace(Object params) {
7472
// suppress notification

0 commit comments

Comments
 (0)