Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codequality #117

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/main/java/Client/ConsoleClientLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ConsoleClientLauncher {

private static Socket socket;
public static MopeLSPClient client;
private Launcher<ModelicaLanguageServer> cLauncher;
private static ExecutorService executor;
private static String host;
private static int port;
Expand All @@ -36,9 +35,9 @@ public ConsoleClientLauncher(String host, int port) throws IOException {
menu = new ConsoleMenu(client);
}

public Future<Void> launchClient() throws IOException {
public static Future<Void> launchClient() throws IOException {
executor = Executors.newFixedThreadPool(2);
cLauncher = new LSPLauncher.Builder<ModelicaLanguageServer>()
Launcher<ModelicaLanguageServer> cLauncher = new LSPLauncher.Builder<ModelicaLanguageServer>()
.setLocalService(client)
.setRemoteInterface(ModelicaLanguageServer.class)
.setInput(socket.getInputStream())
Expand Down Expand Up @@ -74,6 +73,12 @@ public static void stopClient() throws ExecutionException{
logger.info("Client Finished");
}

public static void connectToServer() {
System.out.println("Serverip: ");
host= sc.next();
System.out.println("Serverport: ");
port = sc.nextInt();
}


public static void shutdownServer() throws ExecutionException {
Expand All @@ -86,11 +91,7 @@ public static void shutdownServer() throws ExecutionException {
}

public static void main(String[] args) throws Exception {
System.out.println("Serverip:");
host= sc.next();
System.out.println("Serverport:");
port = sc.nextInt();

connectToServer();
ConsoleClientLauncher launcher = new ConsoleClientLauncher(host, port);

clientListening = launcher.launchClient();
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/Server/MopeDocumentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class MopeDocumentService implements TextDocumentService {
private ICompilerAdapter compiler;
private static final Logger logger = LoggerFactory.getLogger(MopeDocumentService.class);
private UnsupportedOperationException unsupOpEx = null;

@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams completionParams) {
Expand All @@ -41,17 +42,20 @@ public void didOpen(DidOpenTextDocumentParams params) {

@Override
public void didChange(DidChangeTextDocumentParams params) {

// not yet implemented
throw unsupOpEx;
}

@Override
public void didClose(DidCloseTextDocumentParams params) {

// not yet implemented
throw unsupOpEx;
}

@Override
public void didSave(DidSaveTextDocumentParams params) {

// not yet implemented
throw unsupOpEx;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Server/MopeLSPServerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MopeLSPServerLauncher {
private static MopeLSPServer server;
private static ExecutorService executor;
private static Socket socket;
private static Logger logger = LoggerFactory.getLogger(MopeLSPServerLauncher.class);
public static Logger logger = LoggerFactory.getLogger(MopeLSPServerLauncher.class);
private static ConfigObject configObject;

public MopeLSPServerLauncher() throws IOException {
Expand All @@ -36,7 +36,7 @@ public MopeLSPServerLauncher() throws IOException {
serverSocket = new ServerSocket(configObject.port);
}

public void launchServer() {
public static void launchServer() {

System.setProperty(Log4jLoggerAdapter.ROOT_LOGGER_NAME, "TRACE");

Expand Down
30 changes: 21 additions & 9 deletions src/main/java/Server/MopeWorkspaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static Server.MopeLSPServerLauncher.logger;

public class MopeWorkspaceService implements WorkspaceService {

public String error = "invalid command";
private final ModelicaService modelicaService;
private UnsupportedOperationException unsupOpEx = null;

@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams workspaceSymbolParams) {
return null;
}

@Override
public void didChangeConfiguration(DidChangeConfigurationParams didChangeConfigurationParams) {

// not yet implemented
throw unsupOpEx;
}

@Override
public void didChangeWatchedFiles(DidChangeWatchedFilesParams didChangeWatchedFilesParams) {

//not yet implemented
throw unsupOpEx;
}

@Override
Expand All @@ -34,27 +42,31 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params){
String argument = "";
if(!args.isEmpty()) argument = args.get(0).toString().replaceAll("\"", "");
switch(command){
case "ExecuteCommand":
case "executeCommand":
result = modelicaService.sendExpression(argument);
break;
case "LoadFile":
case "loadFile":
result = modelicaService.loadFile(argument);
break;
case "CheckModel":
case "checkModel":
result = modelicaService.checkModel(argument);
break;
case "AddPath":
case "addPath":
result = modelicaService.addModelicaPath(argument);
break;
case "GetPath":
case "getPath":
result = modelicaService.getModelicaPath();
break;
case "LoadModel":
case "loadModel":
result = modelicaService.loadModel(argument);
break;
case "Version":
case "version":
result = modelicaService.getCompilerVersion();
break;
default:
result = CompletableFuture.completedFuture(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really what you want? It is a design choice, but inside a Java environment I would opt for a more rigid approach: When you get an unexpected input, you throw a InputMismatchException.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint!

logger.error("Command is invalid, output is: " + result);
break;
}

try {
Expand Down