Skip to content
Draft
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
14 changes: 0 additions & 14 deletions rascal-lsp/src/main/checkerframework/lsp4j.astub
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@ public class DocumentSymbol {
}


package org.eclipse.lsp4j.services;


import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.services.*;
import org.checkerframework.checker.nullness.qual.*;

@JsonSegment("textDocument")
public interface TextDocumentService {
@JsonRequest
default CompletableFuture<@Nullable Hover> hover(HoverParams params) { }
}


package org.eclipse.lsp4j;

import org.checkerframework.checker.nullness.qual.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -131,23 +130,25 @@ private static void printClassPath() {
}

@SuppressWarnings({"java:S2189", "java:S106"})
public static void startLanguageServer(ExecutorService requestPool, ExecutorService workerPool, Function<ExecutorService, IBaseTextDocumentService> docServiceProvider, BiFunction<ExecutorService, IBaseTextDocumentService, BaseWorkspaceService> workspaceServiceProvider, int portNumber) {
public static void startLanguageServer(ExecutorService requestPool, ExecutorService workerPool, Function<ExecutorService, IBaseTextDocumentService> docServiceProvider, Function<ExecutorService, BaseWorkspaceService> workspaceServiceProvider, int portNumber) {
logger.info("Starting Rascal Language Server: {}", getVersion());
printClassPath();

if (DEPLOY_MODE) {
var docService = docServiceProvider.apply(workerPool);
var wsService = workspaceServiceProvider.apply(workerPool, docService);
var wsService = workspaceServiceProvider.apply(workerPool);
docService.pair(wsService);
wsService.pair(docService);
startLSP(constructLSPClient(capturedIn, capturedOut, new ActualLanguageServer(() -> System.exit(0), workerPool, docService, wsService), requestPool));
}
else {
try (ServerSocket serverSocket = new ServerSocket(portNumber, 0, InetAddress.getByName("127.0.0.1"))) {
logger.info("Rascal LSP server listens on port number: {}", portNumber);
while (true) {
var docService = docServiceProvider.apply(workerPool);
var wsService = workspaceServiceProvider.apply(workerPool, docService);
var wsService = workspaceServiceProvider.apply(workerPool);
docService.pair(wsService);
wsService.pair(docService);
startLSP(constructLSPClient(serverSocket.accept(), new ActualLanguageServer(() -> {}, workerPool, docService, wsService), requestPool));
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
*/
package org.rascalmpl.vscode.lsp;

import com.google.gson.JsonPrimitive;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Expand All @@ -55,7 +55,6 @@
import org.eclipse.lsp4j.services.LanguageClientAware;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.rascalmpl.vscode.lsp.util.Nullables;
import org.rascalmpl.vscode.lsp.util.concurrent.CompletableFutureUtils;
import org.rascalmpl.vscode.lsp.util.locations.Locations;

public abstract class BaseWorkspaceService implements WorkspaceService, LanguageClientAware {
Expand All @@ -67,17 +66,20 @@ public abstract class BaseWorkspaceService implements WorkspaceService, Language
public static final String RASCAL_META_COMMAND = "rascal-meta-command";
public static final String RASCAL_COMMAND = "rascal-command";

private final ExecutorService exec;
protected final ExecutorService exec;

private final IBaseTextDocumentService documentService;
private @MonotonicNonNull IBaseTextDocumentService documentService;
private final CopyOnWriteArrayList<WorkspaceFolder> workspaceFolders = new CopyOnWriteArrayList<>();


protected BaseWorkspaceService(ExecutorService exec, IBaseTextDocumentService documentService) {
this.documentService = documentService;
protected BaseWorkspaceService(ExecutorService exec) {
this.exec = exec;
}

public void pair(IBaseTextDocumentService documentService) {
this.documentService = documentService;
}

public void initialize(ClientCapabilities clientCap, @Nullable List<WorkspaceFolder> currentWorkspaceFolders, ServerCapabilities capabilities) {
this.workspaceFolders.clear();
if (currentWorkspaceFolders != null) {
Expand All @@ -93,6 +95,21 @@ public void initialize(ClientCapabilities clientCap, @Nullable List<WorkspaceFol
}
}

IBaseTextDocumentService availableDocumentService() {
if (this.documentService == null) {
throw new IllegalStateException("Document service not initialized");
}

return this.documentService;
}

protected LanguageClient availableClient() {
if (this.client == null) {
throw new IllegalStateException("Language client not initialized");
}
return this.client;
}

public List<WorkspaceFolder> workspaceFolders() {
return Collections.unmodifiableList(workspaceFolders);
}
Expand Down Expand Up @@ -126,60 +143,64 @@ public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
if (removed != null) {
workspaceFolders.removeAll(removed);
for (WorkspaceFolder folder : removed) {
documentService.projectRemoved(folder.getName(), Locations.toLoc(folder.getUri()));
availableDocumentService().projectRemoved(folder.getName(), Locations.toLoc(folder.getUri()));
}
}

var added = params.getEvent().getAdded();
if (added != null) {
workspaceFolders.addAll(added);
for (WorkspaceFolder folder : added) {
documentService.projectAdded(folder.getName(), Locations.toLoc(folder.getUri()));
availableDocumentService().projectAdded(folder.getName(), Locations.toLoc(folder.getUri()));
}
}
}

@Override
public void didCreateFiles(CreateFilesParams params) {
logger.debug("workspace/didCreateFiles: {}", params.getFiles());
exec.submit(() -> documentService.didCreateFiles(params));
exec.submit(() -> availableDocumentService().didCreateFiles(params));
}

@Override
public void didRenameFiles(RenameFilesParams params) {
logger.debug("workspace/didRenameFiles: {}", params.getFiles());

exec.submit(() -> documentService.didRenameFiles(params, workspaceFolders()));
exec.submit(() -> availableDocumentService().didRenameFiles(params, workspaceFolders()));

exec.submit(() -> {
// cleanup the old files (we do not get a `didDelete` event)
var oldFiles = params.getFiles().stream()
.map(f -> f.getOldUri())
.map(FileDelete::new)
.collect(Collectors.toList());
documentService.didDeleteFiles(new DeleteFilesParams(oldFiles));
availableDocumentService().didDeleteFiles(new DeleteFilesParams(oldFiles));
});
}

@Override
public void didDeleteFiles(DeleteFilesParams params) {
logger.debug("workspace/didDeleteFiles: {}", params.getFiles());
exec.submit(() -> documentService.didDeleteFiles(params));
exec.submit(() -> availableDocumentService().didDeleteFiles(params));
}

@Override
public CompletableFuture<Object> executeCommand(ExecuteCommandParams commandParams) {
logger.debug("workspace/executeCommand: {}", commandParams);
// TODO Split for Rascal and parametric
throw new NotImplementedException("BaseWorkspaceService::executeCommand");
/*
return CompletableFutureUtils.completedFuture(commandParams, exec)
.thenCompose(params -> {
if (params.getCommand().startsWith(RASCAL_META_COMMAND) || params.getCommand().startsWith(RASCAL_COMMAND)) {
String languageName = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
String command = ((JsonPrimitive) params.getArguments().get(1)).getAsString();
return documentService.executeCommand(languageName, command).thenApply(v -> v);
return availableDocumentService().executeCommand(languageName, command).thenApply(v -> v);
}

return CompletableFutureUtils.completedFuture(params.getCommand() + " was ignored.", exec);
});
*/
}

protected final ExecutorService getExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.CreateFilesParams;
Expand All @@ -43,7 +42,6 @@
import org.rascalmpl.vscode.lsp.parametric.LanguageRegistry.LanguageParameter;

import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;

public interface IBaseTextDocumentService extends TextDocumentService {
static final Duration NO_DEBOUNCE = Duration.ZERO;
Expand All @@ -60,9 +58,9 @@ public interface IBaseTextDocumentService extends TextDocumentService {
void projectAdded(String name, ISourceLocation projectRoot);
void projectRemoved(String name, ISourceLocation projectRoot);

CompletableFuture<IValue> executeCommand(String languageName, String command);
LineColumnOffsetMap getColumnMap(ISourceLocation file);
ColumnMaps getColumnMaps();
// TODO Simplify return type to something that can be serialized over JSON-RPC
@Nullable TextDocumentState getDocumentState(ISourceLocation file);

boolean isManagingFile(ISourceLocation file);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, NWO-I CWI and Swat.engineering
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.rascalmpl.vscode.lsp.parametric;

import org.eclipse.lsp4j.services.LanguageClientAware;
import org.eclipse.lsp4j.services.TextDocumentService;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.rascalmpl.vscode.lsp.parametric.LanguageRegistry.LanguageParameter;

public interface ISingleLanguageService extends TextDocumentService, WorkspaceService, LanguageClientAware {
void cancelProgress(String progressId);
void registerLanguage(LanguageParameter lang);
void unregisterLanguage(LanguageParameter lang);
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public boolean removeContributor(String contribKey) {
return true;
}

/**
* Remove all contributors.
*/
public void clearContributors() {
contributions.clear();
calculateRouting();
}

private synchronized void calculateRouting() {
// after contributions have changed, we calculate the routing
// this is to avoid doing this lookup every time we get a request
Expand Down
Loading
Loading