Skip to content

Commit 8994c00

Browse files
committed
Revert "LSP add definition links for Markdown (JabRef#14032)"
This reverts commit a985422.
1 parent bbd4e02 commit 8994c00

File tree

17 files changed

+53
-483
lines changed

17 files changed

+53
-483
lines changed

.jbang/JabLsLauncher.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticBuilder.java
1919
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java
2020
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspIntegrityCheck.java
21-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspLinkHandler.java
22-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspParserHandler.java
23-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/LspRangeUtil.java
24-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/definition/DefinitionProvider.java
25-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/definition/DefinitionProviderFactory.java
26-
//SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/definition/MarkdownDefinitionProvider.java
2721

2822
// REPOS mavencentral,snapshots=https://central.sonatype.com/repository/maven-snapshots/
2923
// REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots

jabgui/src/main/java/org/jabref/gui/JabRefGUI.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,20 @@ private boolean upperRightIsInBounds(CoreGuiPreferences coreGuiPreferences) {
424424
// Background tasks
425425
public void startBackgroundTasks() {
426426
RemotePreferences remotePreferences = preferences.getRemotePreferences();
427-
CLIMessageHandler cliMessageHandler = new CLIMessageHandler(mainFrame, preferences);
427+
428428
if (remotePreferences.useRemoteServer()) {
429429
remoteListenerServerManager.openAndStart(
430-
cliMessageHandler,
430+
new CLIMessageHandler(
431+
mainFrame,
432+
preferences),
431433
remotePreferences.getPort());
432434
}
433435

434436
if (remotePreferences.enableHttpServer()) {
435437
httpServerManager.start(stateManager, remotePreferences.getHttpServerUri());
436438
}
437439
if (remotePreferences.enableLanguageServer()) {
438-
languageServerController.start(cliMessageHandler, remotePreferences.getLanguageServerPort());
440+
languageServerController.start(remotePreferences.getLanguageServerPort());
439441
}
440442
}
441443

jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ public void storeSettings() {
285285
});
286286

287287
UiMessageHandler uiMessageHandler = Injector.instantiateModelOrService(UiMessageHandler.class);
288-
CLIMessageHandler messageHandler = new CLIMessageHandler(uiMessageHandler, preferences);
289288
RemoteListenerServerManager remoteListenerServerManager = Injector.instantiateModelOrService(RemoteListenerServerManager.class);
290289
// stop in all cases, because the port might have changed
291290
remoteListenerServerManager.stop();
292291
if (remoteServerProperty.getValue()) {
293292
remotePreferences.setUseRemoteServer(true);
294-
remoteListenerServerManager.openAndStart(messageHandler,
293+
remoteListenerServerManager.openAndStart(
294+
new CLIMessageHandler(uiMessageHandler, preferences),
295295
remotePreferences.getPort());
296296
} else {
297297
remotePreferences.setUseRemoteServer(false);
@@ -327,7 +327,7 @@ public void storeSettings() {
327327
languageServerController.stop();
328328
if (enableLanguageServerProperty.getValue()) {
329329
remotePreferences.setEnableLanguageServer(true);
330-
languageServerController.start(messageHandler, remotePreferences.getLanguageServerPort());
330+
languageServerController.start(remotePreferences.getLanguageServerPort());
331331
} else {
332332
remotePreferences.setEnableLanguageServer(false);
333333
languageServerController.stop();

jablib/src/main/java/org/jabref/logic/importer/ParserResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public void setPath(Path path) {
105105
*
106106
* @param s String Warning text. Must be pre-translated. Only added if there isn't already a dupe.
107107
*/
108-
public void addWarning(@NonNull String s) {
108+
public void addWarning(String s) {
109109
addWarning(Range.NULL_RANGE, s);
110110
}
111111

112-
public void addWarning(Range range, @NonNull String s) {
112+
public void addWarning(Range range, String s) {
113113
warnings.put(range, s);
114114
}
115115

jabls/src/main/java/org/jabref/languageserver/BibtexTextDocumentService.java

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,30 @@
11
package org.jabref.languageserver;
22

33
import java.util.List;
4-
import java.util.Map;
54
import java.util.concurrent.CompletableFuture;
6-
import java.util.concurrent.ConcurrentHashMap;
75

86
import org.jabref.languageserver.util.LspDiagnosticHandler;
9-
import org.jabref.languageserver.util.LspLinkHandler;
10-
import org.jabref.logic.remote.server.RemoteMessageHandler;
117

12-
import com.google.gson.JsonArray;
138
import org.eclipse.lsp4j.CompletionItem;
149
import org.eclipse.lsp4j.CompletionList;
1510
import org.eclipse.lsp4j.CompletionParams;
16-
import org.eclipse.lsp4j.DefinitionParams;
1711
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
1812
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
1913
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
2014
import org.eclipse.lsp4j.DidSaveTextDocumentParams;
21-
import org.eclipse.lsp4j.DocumentLink;
22-
import org.eclipse.lsp4j.DocumentLinkParams;
23-
import org.eclipse.lsp4j.Location;
24-
import org.eclipse.lsp4j.LocationLink;
25-
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
26-
import org.eclipse.lsp4j.TextDocumentItem;
27-
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
2815
import org.eclipse.lsp4j.jsonrpc.messages.Either;
2916
import org.eclipse.lsp4j.services.LanguageClient;
3017
import org.eclipse.lsp4j.services.TextDocumentService;
3118
import org.jspecify.annotations.NonNull;
32-
import org.slf4j.Logger;
33-
import org.slf4j.LoggerFactory;
3419

3520
public class BibtexTextDocumentService implements TextDocumentService {
3621

37-
private static final Logger LOGGER = LoggerFactory.getLogger(BibtexTextDocumentService.class);
38-
39-
private final LspClientHandler clientHandler;
4022
private final LspDiagnosticHandler diagnosticHandler;
41-
private final LspLinkHandler linkHandler;
42-
private final RemoteMessageHandler messageHandler;
43-
private final Map<String, String> fileUriToLanguageId;
44-
private final Map<String, String> contentCache;
23+
4524
private LanguageClient client;
4625

47-
public BibtexTextDocumentService(@NonNull RemoteMessageHandler messageHandler, @NonNull LspClientHandler clientHandler, @NonNull LspDiagnosticHandler diagnosticHandler, @NonNull LspLinkHandler linkHandler) {
48-
this.clientHandler = clientHandler;
26+
public BibtexTextDocumentService(@NonNull LspDiagnosticHandler diagnosticHandler) {
4927
this.diagnosticHandler = diagnosticHandler;
50-
this.linkHandler = linkHandler;
51-
this.fileUriToLanguageId = new ConcurrentHashMap<>();
52-
this.contentCache = new ConcurrentHashMap<>();
53-
this.messageHandler = messageHandler;
5428
}
5529

5630
public void setClient(LanguageClient client) {
@@ -59,73 +33,22 @@ public void setClient(LanguageClient client) {
5933

6034
@Override
6135
public void didOpen(DidOpenTextDocumentParams params) {
62-
TextDocumentItem textDocument = params.getTextDocument();
63-
LOGGER.debug("didOpen {}", textDocument.getUri());
64-
fileUriToLanguageId.putIfAbsent(textDocument.getUri(), textDocument.getLanguageId());
65-
66-
if ("bibtex".equals(textDocument.getLanguageId())) {
67-
diagnosticHandler.computeAndPublishDiagnostics(client, textDocument.getUri(), textDocument.getText(), textDocument.getVersion());
68-
} else {
69-
contentCache.put(textDocument.getUri(), textDocument.getText());
70-
}
36+
diagnosticHandler.computeAndPublishDiagnostics(client, params.getTextDocument().getUri(), params.getTextDocument().getText(), params.getTextDocument().getVersion());
7137
}
7238

7339
@Override
7440
public void didChange(DidChangeTextDocumentParams params) {
75-
VersionedTextDocumentIdentifier textDocument = params.getTextDocument();
76-
TextDocumentContentChangeEvent contentChange = params.getContentChanges().getFirst();
77-
LOGGER.debug("didChange {}", textDocument.getUri());
78-
String languageId = fileUriToLanguageId.get(textDocument.getUri());
79-
80-
if ("bibtex".equalsIgnoreCase(languageId)) {
81-
diagnosticHandler.computeAndPublishDiagnostics(client, textDocument.getUri(), contentChange.getText(), textDocument.getVersion());
82-
} else {
83-
contentCache.put(textDocument.getUri(), contentChange.getText());
84-
}
41+
diagnosticHandler.computeAndPublishDiagnostics(client, params.getTextDocument().getUri(), params.getContentChanges().getFirst().getText(), params.getTextDocument().getVersion());
8542
}
8643

8744
@Override
8845
public void didClose(DidCloseTextDocumentParams params) {
89-
fileUriToLanguageId.remove(params.getTextDocument().getUri());
90-
contentCache.remove(params.getTextDocument().getUri());
9146
}
9247

9348
@Override
9449
public void didSave(DidSaveTextDocumentParams params) {
9550
}
9651

97-
@Override
98-
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams params) {
99-
if (!clientHandler.isStandalone()) {
100-
return CompletableFuture.completedFuture(Either.forLeft(List.of()));
101-
}
102-
if (fileUriToLanguageId.containsKey(params.getTextDocument().getUri())) {
103-
String fileUri = params.getTextDocument().getUri();
104-
return linkHandler.provideDefinition(fileUriToLanguageId.get(fileUri), fileUri, contentCache.get(fileUri), params.getPosition());
105-
}
106-
return CompletableFuture.completedFuture(Either.forLeft(List.of()));
107-
}
108-
109-
@Override
110-
public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) {
111-
if (clientHandler.isStandalone()) {
112-
return CompletableFuture.completedFuture(List.of());
113-
}
114-
String fileUri = params.getTextDocument().getUri();
115-
return linkHandler.provideDocumentLinks(fileUriToLanguageId.get(fileUri), contentCache.get(fileUri));
116-
}
117-
118-
@Override
119-
public CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params) {
120-
if (clientHandler.isStandalone()) {
121-
return CompletableFuture.completedFuture(null);
122-
}
123-
if (params.getData() instanceof JsonArray data) {
124-
messageHandler.handleCommandLineArguments(new String[] {data.asList().getFirst().getAsString(), data.asList().getLast().getAsString()});
125-
}
126-
return CompletableFuture.completedFuture(null);
127-
}
128-
12952
@Override
13053
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
13154
return TextDocumentService.super.completion(position);

jabls/src/main/java/org/jabref/languageserver/BibtexWorkspaceService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public BibtexWorkspaceService(LspClientHandler clientHandler, LspDiagnosticHandl
2424
this.diagnosticHandler = diagnosticHandler;
2525
}
2626

27+
// Todo: handle event
2728
@Override
2829
public void didChangeConfiguration(DidChangeConfigurationParams didChangeConfigurationParams) {
2930
if (didChangeConfigurationParams.getSettings() instanceof JsonObject settings) {

jabls/src/main/java/org/jabref/languageserver/LspClientHandler.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
import java.util.concurrent.CompletableFuture;
44

55
import org.jabref.languageserver.util.LspDiagnosticHandler;
6-
import org.jabref.languageserver.util.LspLinkHandler;
7-
import org.jabref.languageserver.util.LspParserHandler;
86
import org.jabref.logic.journals.JournalAbbreviationRepository;
97
import org.jabref.logic.preferences.CliPreferences;
10-
import org.jabref.logic.remote.server.RemoteMessageHandler;
118

12-
import org.eclipse.lsp4j.DocumentLinkOptions;
139
import org.eclipse.lsp4j.InitializeParams;
1410
import org.eclipse.lsp4j.InitializeResult;
1511
import org.eclipse.lsp4j.MessageParams;
@@ -31,24 +27,17 @@ public class LspClientHandler implements LanguageServer, LanguageClientAware {
3127
private static final Logger LOGGER = LoggerFactory.getLogger(LspClientHandler.class);
3228

3329
private final LspDiagnosticHandler diagnosticHandler;
34-
private final LspParserHandler parserHandler;
35-
private final LspLinkHandler linkHandler;
3630
private final BibtexWorkspaceService workspaceService;
3731
private final BibtexTextDocumentService textDocumentService;
3832
private final ExtensionSettings settings;
39-
private final RemoteMessageHandler messageHandler;
4033

4134
private LanguageClient client;
42-
private boolean standalone = false;
4335

44-
public LspClientHandler(RemoteMessageHandler messageHandler, CliPreferences cliPreferences, JournalAbbreviationRepository abbreviationRepository) {
36+
public LspClientHandler(CliPreferences cliPreferences, JournalAbbreviationRepository abbreviationRepository) {
4537
this.settings = ExtensionSettings.getDefaultSettings();
46-
this.parserHandler = new LspParserHandler();
47-
this.diagnosticHandler = new LspDiagnosticHandler(this, parserHandler, cliPreferences, abbreviationRepository);
48-
this.linkHandler = new LspLinkHandler(parserHandler);
38+
this.diagnosticHandler = new LspDiagnosticHandler(this, cliPreferences, abbreviationRepository);
4939
this.workspaceService = new BibtexWorkspaceService(this, diagnosticHandler);
50-
this.textDocumentService = new BibtexTextDocumentService(messageHandler, this, diagnosticHandler, linkHandler);
51-
this.messageHandler = messageHandler;
40+
this.textDocumentService = new BibtexTextDocumentService(diagnosticHandler);
5241
}
5342

5443
@Override
@@ -62,11 +51,6 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
6251

6352
capabilities.setTextDocumentSync(syncOptions);
6453
capabilities.setWorkspace(new WorkspaceServerCapabilities());
65-
capabilities.setDefinitionProvider(true);
66-
67-
DocumentLinkOptions linkOptions = new DocumentLinkOptions();
68-
linkOptions.setResolveProvider(true);
69-
capabilities.setDocumentLinkProvider(linkOptions);
7054

7155
return CompletableFuture.completedFuture(new InitializeResult(capabilities));
7256
}
@@ -104,12 +88,4 @@ public void connect(LanguageClient client) {
10488
textDocumentService.setClient(client);
10589
client.logMessage(new MessageParams(MessageType.Warning, "BibtexLSPServer connected."));
10690
}
107-
108-
public void setStandalone(boolean standalone) {
109-
this.standalone = standalone;
110-
}
111-
112-
public boolean isStandalone() {
113-
return standalone;
114-
}
11591
}

jabls/src/main/java/org/jabref/languageserver/LspLauncher.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
import org.jabref.logic.journals.JournalAbbreviationLoader;
1313
import org.jabref.logic.journals.JournalAbbreviationRepository;
1414
import org.jabref.logic.preferences.CliPreferences;
15-
import org.jabref.logic.preferences.JabRefCliPreferences;
16-
import org.jabref.logic.remote.server.RemoteMessageHandler;
1715

1816
import org.eclipse.lsp4j.jsonrpc.Launcher;
19-
import org.eclipse.lsp4j.launch.LSPLauncher;
2017
import org.eclipse.lsp4j.services.LanguageClient;
2118
import org.slf4j.Logger;
2219
import org.slf4j.LoggerFactory;
@@ -28,29 +25,21 @@ public class LspLauncher extends Thread {
2825
private final CliPreferences cliPreferences;
2926
private final JournalAbbreviationRepository abbreviationRepository;
3027
private final ExecutorService threadPool;
31-
private final RemoteMessageHandler messageHandler;
3228

3329
private final int port;
34-
private boolean standalone = false;
3530
private volatile boolean running;
3631
private ServerSocket serverSocket;
3732

38-
public LspLauncher(RemoteMessageHandler messageHandler, CliPreferences cliPreferences, JournalAbbreviationRepository abbreviationRepository, int port) {
33+
public LspLauncher(CliPreferences cliPreferences, JournalAbbreviationRepository abbreviationRepository, int port) {
3934
this.cliPreferences = cliPreferences;
4035
this.abbreviationRepository = abbreviationRepository;
4136
this.threadPool = Executors.newCachedThreadPool();
4237
this.port = port;
4338
this.setName("JabLs - JabRef Language Server on: " + port);
44-
this.messageHandler = messageHandler;
4539
}
4640

47-
public LspLauncher(RemoteMessageHandler messageHandler, CliPreferences cliPreferences, int port) {
48-
this(messageHandler, cliPreferences, JournalAbbreviationLoader.loadRepository(cliPreferences.getJournalAbbreviationPreferences()), port);
49-
}
50-
51-
public LspLauncher(JabRefCliPreferences instance, Integer port) {
52-
this(_ -> LOGGER.warn("LSP cannot handle UICommands in standalone mode."), instance, port);
53-
this.standalone = true;
41+
public LspLauncher(CliPreferences cliPreferences, int port) {
42+
this(cliPreferences, JournalAbbreviationLoader.loadRepository(cliPreferences.getJournalAbbreviationPreferences()), port);
5443
}
5544

5645
@Override
@@ -80,13 +69,12 @@ public void run() {
8069
}
8170

8271
private void handleClient(Socket socket) {
83-
LspClientHandler clientHandler = new LspClientHandler(messageHandler, cliPreferences, abbreviationRepository);
84-
clientHandler.setStandalone(standalone);
72+
LspClientHandler clientHandler = new LspClientHandler(cliPreferences, abbreviationRepository);
8573
LOGGER.debug("LSP clientHandler started.");
8674
try (socket; // socket should be closed on error
8775
InputStream in = socket.getInputStream();
8876
OutputStream out = socket.getOutputStream()) {
89-
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(clientHandler, in, out, Executors.newCachedThreadPool(), Function.identity());
77+
Launcher<LanguageClient> launcher = org.eclipse.lsp4j.launch.LSPLauncher.createServerLauncher(clientHandler, in, out, Executors.newCachedThreadPool(), Function.identity());
9078
LOGGER.debug("LSP clientHandler launched.");
9179
clientHandler.connect(launcher.getRemoteProxy());
9280
LOGGER.debug("LSP clientHandler connected.");
@@ -117,8 +105,4 @@ public void interrupt() {
117105
public boolean isRunning() {
118106
return running;
119107
}
120-
121-
public boolean isStandalone() {
122-
return standalone;
123-
}
124108
}

jabls/src/main/java/org/jabref/languageserver/controller/LanguageServerController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.jabref.languageserver.LspLauncher;
44
import org.jabref.logic.journals.JournalAbbreviationRepository;
55
import org.jabref.logic.preferences.CliPreferences;
6-
import org.jabref.logic.remote.server.RemoteMessageHandler;
76

87
import org.jspecify.annotations.Nullable;
98
import org.slf4j.Logger;
@@ -25,13 +24,13 @@ public LanguageServerController(CliPreferences cliPreferences, JournalAbbreviati
2524
LOGGER.debug("LanguageServerController initialized.");
2625
}
2726

28-
public synchronized void start(RemoteMessageHandler messageHandler, int port) {
27+
public synchronized void start(int port) {
2928
if (lspLauncher != null) {
3029
LOGGER.warn("Language server controller already started, cannot start again.");
3130
return;
3231
}
3332

34-
lspLauncher = new LspLauncher(messageHandler, cliPreferences, abbreviationRepository, port);
33+
lspLauncher = new LspLauncher(cliPreferences, abbreviationRepository, port);
3534
// This enqueues the thread to run in the background
3635
// The JVM will take care of running it at some point in time in the future
3736
// Thus, we cannot check directly if it really runs

0 commit comments

Comments
 (0)