Skip to content

Commit aea07c9

Browse files
committed
Move classes related to MagpieServer to magpiebridge package
1 parent 36241d9 commit aea07c9

File tree

4 files changed

+110
-101
lines changed

4 files changed

+110
-101
lines changed

src/main/java/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import gobpie.GobPieException;
1414
import magpiebridge.core.MagpieServer;
1515
import magpiebridge.core.ServerAnalysis;
16+
import magpiebridge.GoblintLanguageExtensionHandler;
17+
import magpiebridge.GoblintMagpieServer;
18+
import magpiebridge.GoblintServerConfiguration;
1619
import org.apache.logging.log4j.LogManager;
1720
import org.apache.logging.log4j.Logger;
1821
import org.eclipse.lsp4j.MessageParams;
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
import magpiebridge.core.LanguageExtensionHandler;
2-
3-
import java.util.Set;
4-
5-
/**
6-
* Custom LanguageExtensionHandler for MagpieBridge that overrides the extensions associated with C to include .h and .i.
7-
* For other languages falls back to the provided fallback LanguageExtensionHandler.
8-
*/
9-
public class GoblintLanguageExtensionHandler implements LanguageExtensionHandler {
10-
11-
private final LanguageExtensionHandler fallbackLanguageExtensionHandler;
12-
13-
public GoblintLanguageExtensionHandler(LanguageExtensionHandler fallbackLanguageExtensionHandler) {
14-
this.fallbackLanguageExtensionHandler = fallbackLanguageExtensionHandler;
15-
}
16-
17-
@Override
18-
public String getLanguageForExtension(String extension) {
19-
if (".c".equals(extension) || ".i".equals(extension) || ".h".equals(extension)) {
20-
return "c";
21-
}
22-
return fallbackLanguageExtensionHandler.getLanguageForExtension(extension);
23-
}
24-
25-
@Override
26-
public Set<String> getExtensionsForLanguage(String language) {
27-
if ("c".equals(language)) {
28-
return Set.of(".c", ".i", ".h");
29-
}
30-
return fallbackLanguageExtensionHandler.getExtensionsForLanguage(language);
31-
}
32-
33-
}
1+
package magpiebridge;
2+
3+
import magpiebridge.core.LanguageExtensionHandler;
4+
5+
import java.util.Set;
6+
7+
/**
8+
* Custom LanguageExtensionHandler for MagpieBridge that overrides the extensions associated with C to include .h and .i.
9+
* For other languages falls back to the provided fallback LanguageExtensionHandler.
10+
*/
11+
public class GoblintLanguageExtensionHandler implements LanguageExtensionHandler {
12+
13+
private final LanguageExtensionHandler fallbackLanguageExtensionHandler;
14+
15+
public GoblintLanguageExtensionHandler(LanguageExtensionHandler fallbackLanguageExtensionHandler) {
16+
this.fallbackLanguageExtensionHandler = fallbackLanguageExtensionHandler;
17+
}
18+
19+
@Override
20+
public String getLanguageForExtension(String extension) {
21+
if (".c".equals(extension) || ".i".equals(extension) || ".h".equals(extension)) {
22+
return "c";
23+
}
24+
return fallbackLanguageExtensionHandler.getLanguageForExtension(extension);
25+
}
26+
27+
@Override
28+
public Set<String> getExtensionsForLanguage(String language) {
29+
if ("c".equals(language)) {
30+
return Set.of(".c", ".i", ".h");
31+
}
32+
return fallbackLanguageExtensionHandler.getExtensionsForLanguage(language);
33+
}
34+
35+
}
Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
1-
import magpiebridge.core.*;
2-
import magpiebridge.file.SourceFileManager;
3-
import org.eclipse.lsp4j.InitializeParams;
4-
import org.eclipse.lsp4j.InitializeResult;
5-
import org.eclipse.lsp4j.jsonrpc.messages.Either;
6-
7-
import java.util.concurrent.CompletableFuture;
8-
9-
public class GoblintMagpieServer extends MagpieServer {
10-
11-
/**
12-
* Future that is completed once the configuration of the server has completed i.e. all analyses have been added.
13-
*/
14-
private final CompletableFuture<Void> configurationDoneFuture = new CompletableFuture<>();
15-
16-
/**
17-
* Instantiates a new MagpieServer using default {@link MagpieTextDocumentService} and {@link
18-
* MagpieWorkspaceService} with given {@link ServerConfiguration}.
19-
*
20-
* @param config the config
21-
*/
22-
public GoblintMagpieServer(ServerConfiguration config) {
23-
super(config);
24-
}
25-
26-
/**
27-
* Marks this server instance as fully configured, which allows the initialize request to complete.
28-
* The server will receive no communication other than the initialize request from the client before this is called.
29-
*/
30-
public void configurationDone() {
31-
configurationDoneFuture.complete(null);
32-
}
33-
34-
@Override
35-
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
36-
return configurationDoneFuture.thenCompose(_r -> super.initialize(params));
37-
}
38-
39-
@Override
40-
protected void doSingleAnalysis(String language, Either<ServerAnalysis, ToolAnalysis> analysis, boolean rerun) {
41-
SourceFileManager fileManager = getSourceFileManager(language);
42-
Analysis<AnalysisConsumer> a = analysis.isLeft() ? analysis.getLeft() : analysis.getRight();
43-
if (a != null) {
44-
a.analyze(fileManager.getSourceFileModules().values(), this, rerun);
45-
}
46-
}
47-
48-
}
1+
package magpiebridge;
2+
3+
import magpiebridge.core.*;
4+
import magpiebridge.file.SourceFileManager;
5+
import org.eclipse.lsp4j.InitializeParams;
6+
import org.eclipse.lsp4j.InitializeResult;
7+
import org.eclipse.lsp4j.jsonrpc.messages.Either;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
11+
public class GoblintMagpieServer extends MagpieServer {
12+
13+
/**
14+
* Future that is completed once the configuration of the server has completed i.e. all analyses have been added.
15+
*/
16+
private final CompletableFuture<Void> configurationDoneFuture = new CompletableFuture<>();
17+
18+
/**
19+
* Instantiates a new MagpieServer using default {@link MagpieTextDocumentService} and {@link
20+
* MagpieWorkspaceService} with given {@link ServerConfiguration}.
21+
*
22+
* @param config the config
23+
*/
24+
public GoblintMagpieServer(ServerConfiguration config) {
25+
super(config);
26+
}
27+
28+
/**
29+
* Marks this server instance as fully configured, which allows the initialize request to complete.
30+
* The server will receive no communication other than the initialize request from the client before this is called.
31+
*/
32+
public void configurationDone() {
33+
configurationDoneFuture.complete(null);
34+
}
35+
36+
@Override
37+
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
38+
return configurationDoneFuture.thenCompose(_r -> super.initialize(params));
39+
}
40+
41+
@Override
42+
protected void doSingleAnalysis(String language, Either<ServerAnalysis, ToolAnalysis> analysis, boolean rerun) {
43+
SourceFileManager fileManager = getSourceFileManager(language);
44+
Analysis<AnalysisConsumer> a = analysis.isLeft() ? analysis.getLeft() : analysis.getRight();
45+
if (a != null) {
46+
a.analyze(fileManager.getSourceFileModules().values(), this, rerun);
47+
}
48+
}
49+
50+
}
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import magpiebridge.core.LanguageExtensionHandler;
2-
import magpiebridge.core.ServerConfiguration;
3-
4-
/**
5-
* ServerConfiguration subclass that allows setting a custom language extension handler.
6-
*/
7-
public class GoblintServerConfiguration extends ServerConfiguration {
8-
9-
private LanguageExtensionHandler customLanguageExtensionHandler = null;
10-
11-
public void setLanguageExtensionHandler(LanguageExtensionHandler languageExtensionHandler) {
12-
customLanguageExtensionHandler = languageExtensionHandler;
13-
}
14-
15-
@Override
16-
public LanguageExtensionHandler getLanguageExtensionHandler() {
17-
return customLanguageExtensionHandler != null ? customLanguageExtensionHandler : super.getLanguageExtensionHandler();
18-
}
19-
20-
}
1+
package magpiebridge;
2+
3+
import magpiebridge.core.LanguageExtensionHandler;
4+
import magpiebridge.core.ServerConfiguration;
5+
6+
/**
7+
* ServerConfiguration subclass that allows setting a custom language extension handler.
8+
*/
9+
public class GoblintServerConfiguration extends ServerConfiguration {
10+
11+
private LanguageExtensionHandler customLanguageExtensionHandler = null;
12+
13+
public void setLanguageExtensionHandler(LanguageExtensionHandler languageExtensionHandler) {
14+
customLanguageExtensionHandler = languageExtensionHandler;
15+
}
16+
17+
@Override
18+
public LanguageExtensionHandler getLanguageExtensionHandler() {
19+
return customLanguageExtensionHandler != null ? customLanguageExtensionHandler : super.getLanguageExtensionHandler();
20+
}
21+
22+
}

0 commit comments

Comments
 (0)