Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added the Option to enable the language server in the preferences. [#13697](https://github.com/JabRef/jabref/pull/13697)
- We added tooltips (on hover) for 'Library-specific file directory', 'User-specific file directory' and 'LaTeX file directory' fields of the library properties window. [#12269](https://github.com/JabRef/jabref/issues/12269)
- A space is now added by default after citations inserted via the Libre/OpenOffice integration. [#13559](https://github.com/JabRef/jabref/issues/13559)
- We added the option to configure 'Add space after citation' in Libre/OpenOffice panel settings. [#13559](https://github.com/JabRef/jabref/issues/13559)
Expand Down
1 change: 1 addition & 0 deletions jabgui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation("org.openjfx:javafx-web")

implementation(project(":jabsrv"))
implementation(project(":jabls"))

implementation("com.pixelduke:fxthemes")

Expand Down
1 change: 1 addition & 0 deletions jabgui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
requires org.jabref.jablib;

requires org.jabref.jabsrv;
requires org.jabref.jabls;

// Swing
requires java.desktop;
Expand Down
17 changes: 16 additions & 1 deletion jabgui/src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.gui.util.WebViewStore;
import org.jabref.http.manager.HttpServerManager;
import org.jabref.languageserver.manager.LanguageServerController;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.citation.SearchCitationsRelationsService;
Expand Down Expand Up @@ -86,6 +87,7 @@ public class JabRefGUI extends Application {

private static RemoteListenerServerManager remoteListenerServerManager;
private static HttpServerManager httpServerManager;
private static LanguageServerController languageServerController;

private Stage mainStage;

Expand Down Expand Up @@ -156,8 +158,9 @@ public void initialize() {
Injector.setModelOrService(DirectoryMonitor.class, directoryMonitor);

BibEntryTypesManager entryTypesManager = preferences.getCustomEntryTypesRepository();
JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences());
Injector.setModelOrService(BibEntryTypesManager.class, entryTypesManager);
Injector.setModelOrService(JournalAbbreviationRepository.class, JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()));
Injector.setModelOrService(JournalAbbreviationRepository.class, journalAbbreviationRepository);
Injector.setModelOrService(ProtectedTermsLoader.class, new ProtectedTermsLoader(preferences.getProtectedTermsPreferences()));

IndexManager.clearOldSearchIndices();
Expand All @@ -168,6 +171,9 @@ public void initialize() {
JabRefGUI.httpServerManager = new HttpServerManager();
Injector.setModelOrService(HttpServerManager.class, JabRefGUI.httpServerManager);

JabRefGUI.languageServerController = new LanguageServerController(preferences, journalAbbreviationRepository);
Injector.setModelOrService(LanguageServerController.class, JabRefGUI.languageServerController);

JabRefGUI.stateManager = new JabRefGuiStateManager();
Injector.setModelOrService(StateManager.class, stateManager);

Expand Down Expand Up @@ -424,6 +430,9 @@ public void startBackgroundTasks() {
if (remotePreferences.enableHttpServer()) {
httpServerManager.start(stateManager, remotePreferences.getHttpServerUri());
}
if (remotePreferences.enableLanguageServer()) {
languageServerController.start(remotePreferences.getLanguageServerPort());
}
}

@Override
Expand Down Expand Up @@ -467,6 +476,12 @@ public void stop() {
LOGGER.trace("HttpServerManager shut down");
});

executor.submit(() -> {
LOGGER.trace("Shutting down language server manager");
languageServerController.stop();
LOGGER.trace("LanguageServerManager shut down");
});

executor.submit(() -> {
LOGGER.trace("Stopping background tasks");
Unirest.shutDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> i
@FXML private TextField remotePort;
@FXML private CheckBox enableHttpServer;
@FXML private TextField httpServerPort;
@FXML private CheckBox enableLanguageServer;
@FXML private TextField languageServerPort;
@FXML private Button remoteHelp;
@Inject private FileUpdateMonitor fileUpdateMonitor;
@Inject private BibEntryTypesManager entryTypesManager;
Expand Down Expand Up @@ -145,6 +147,7 @@ public void initialize() {
Platform.runLater(() -> {
validationVisualizer.initVisualization(viewModel.remotePortValidationStatus(), remotePort);
validationVisualizer.initVisualization(viewModel.httpPortValidationStatus(), httpServerPort);
validationVisualizer.initVisualization(viewModel.languageServerPortValidationStatus(), languageServerPort);
validationVisualizer.initVisualization(viewModel.fontSizeValidationStatus(), fontSize);
validationVisualizer.initVisualization(viewModel.customPathToThemeValidationStatus(), customThemePath);
});
Expand All @@ -156,6 +159,10 @@ public void initialize() {
enableHttpServer.selectedProperty().bindBidirectional(viewModel.enableHttpServerProperty());
httpServerPort.textProperty().bindBidirectional(viewModel.httpPortProperty());
httpServerPort.disableProperty().bind(enableHttpServer.selectedProperty().not());

enableLanguageServer.selectedProperty().bindBidirectional(viewModel.enableLanguageServerProperty());
languageServerPort.textProperty().bindBidirectional(viewModel.languageServerPortProperty());
languageServerPort.disableProperty().bind(enableLanguageServer.selectedProperty().not());
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.http.manager.HttpServerManager;
import org.jabref.languageserver.manager.LanguageServerController;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.LibraryPreferences;
import org.jabref.logic.l10n.Language;
Expand Down Expand Up @@ -111,6 +112,9 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty enableHttpServerProperty = new SimpleBooleanProperty();
private final StringProperty httpPortProperty = new SimpleStringProperty("");
private final Validator httpPortValidator;
private final Validator languageServerPortValidator;
private final BooleanProperty enableLanguageServerProperty = new SimpleBooleanProperty();
private final StringProperty languageServerPortProperty = new SimpleStringProperty("");
private final TrustStoreManager trustStoreManager;

private final FileUpdateMonitor fileUpdateMonitor;
Expand Down Expand Up @@ -148,29 +152,22 @@ public GeneralTabViewModel(DialogService dialogService, GuiPreferences preferenc

remotePortValidator = new FunctionBasedValidator<>(
remotePortProperty,
input -> {
try {
int portNumber = Integer.parseInt(remotePortProperty().getValue());
return RemoteUtil.isUserPort(portNumber);
} catch (NumberFormatException ex) {
return false;
}
},
RemoteUtil::isStringUserPort,
ValidationMessage.error("%s > %s %n %n %s".formatted(
Localization.lang("Network"),
Localization.lang("Remote operation"),
Localization.lang("You must enter an integer value in the interval 1025-65535"))));

httpPortValidator = new FunctionBasedValidator<>(
httpPortProperty,
input -> {
try {
int portNumber = Integer.parseInt(httpPortProperty().getValue());
return RemoteUtil.isUserPort(portNumber);
} catch (NumberFormatException ex) {
return false;
}
},
RemoteUtil::isStringUserPort,
ValidationMessage.error("%s".formatted(Localization.lang("You must enter an integer value in the interval 1025-65535"))));

languageServerPortValidator = new FunctionBasedValidator<>(
languageServerPortProperty,
RemoteUtil::isStringUserPort,
ValidationMessage.error(Localization.lang("You must enter an integer value in the interval 1025-65535")));

this.trustStoreManager = new TrustStoreManager(Path.of(preferences.getSSLPreferences().getTruststorePath()));
}

Expand All @@ -182,6 +179,10 @@ public ValidationStatus httpPortValidationStatus() {
return httpPortValidator.getValidationStatus();
}

public ValidationStatus languageServerPortValidationStatus() {
return languageServerPortValidator.getValidationStatus();
}

@Override
public void setValues() {
selectedLanguageProperty.setValue(workspacePreferences.getLanguage());
Expand Down Expand Up @@ -225,6 +226,9 @@ public void setValues() {

enableHttpServerProperty.setValue(remotePreferences.enableHttpServer());
httpPortProperty.setValue(String.valueOf(remotePreferences.getHttpPort()));

enableLanguageServerProperty.setValue(remotePreferences.enableLanguageServer());
languageServerPortProperty.setValue(String.valueOf(remotePreferences.getLanguageServerPort()));
}

@Override
Expand Down Expand Up @@ -297,6 +301,12 @@ public void storeSettings() {
}
});

getPortAsInt(languageServerPortProperty.getValue()).ifPresent(newPort -> {
if (remotePreferences.isDifferentLanguageServerPort(newPort)) {
remotePreferences.setLanguageServerPort(newPort);
}
});

HttpServerManager httpServerManager = Injector.instantiateModelOrService(HttpServerManager.class);
// stop in all cases, because the port might have changed
httpServerManager.stop();
Expand All @@ -309,6 +319,17 @@ public void storeSettings() {
httpServerManager.stop();
}

LanguageServerController languageServerController = Injector.instantiateModelOrService(LanguageServerController.class);
// stop in all cases, because the port might have changed (or other settings that can't be easily tracked https://github.com/JabRef/jabref/pull/13697#discussion_r2285997003)
languageServerController.stop();
if (enableLanguageServerProperty.getValue()) {
remotePreferences.setEnableLanguageServer(true);
languageServerController.start(remotePreferences.getLanguageServerPort());
} else {
remotePreferences.setEnableLanguageServer(false);
languageServerController.stop();
}

trustStoreManager.flush();
}

Expand All @@ -332,6 +353,10 @@ public boolean validateSettings() {
validator.addValidators(httpPortValidator);
}

if (enableLanguageServerProperty.getValue()) {
validator.addValidators(languageServerPortValidator);
}

if (fontOverrideProperty.getValue()) {
validator.addValidators(fontSizeValidator);
}
Expand Down Expand Up @@ -470,6 +495,14 @@ public StringProperty httpPortProperty() {
return httpPortProperty;
}

public BooleanProperty enableLanguageServerProperty() {
return enableLanguageServerProperty;
}

public StringProperty languageServerPortProperty() {
return languageServerPortProperty;
}

public void openBrowser() {
String url = "https://themes.jabref.org";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<TextField fx:id="httpServerPort" maxWidth="100.0" HBox.hgrow="ALWAYS" />
</HBox>

<Label styleClass="sectionHeader" text="%Language Server" />
<HBox alignment="CENTER_LEFT" spacing="10.0">
<CheckBox fx:id="enableLanguageServer" text="%Enable Language Server on port" />
<TextField fx:id="languageServerPort" maxWidth="100.0" HBox.hgrow="ALWAYS" />
</HBox>

<Label styleClass="sectionHeader" text="%Libraries"/>
<GridPane hgap="10.0" vgap="4.0">
<columnConstraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ public class JabRefCliPreferences implements CliPreferences {
private static final String REMOTE_SERVER_PORT = "remoteServerPort";
private static final String HTTP_SERVER_PORT = "httpServerPort";
private static final String ENABLE_HTTP_SERVER = "enableHttpServer";
private static final String ENABLE_LANGUAGE_SERVER = "enableLanguageServer";
private static final String LANGUAGE_SERVER_PORT = "languageServerPort";

private static final String AI_ENABLED = "aiEnabled";
private static final String AI_AUTO_GENERATE_EMBEDDINGS = "aiAutoGenerateEmbeddings";
Expand Down Expand Up @@ -672,6 +674,8 @@ public JabRefCliPreferences() {
defaults.put(REMOTE_SERVER_PORT, 6050);
defaults.put(ENABLE_HTTP_SERVER, Boolean.FALSE);
defaults.put(HTTP_SERVER_PORT, 23119);
defaults.put(ENABLE_LANGUAGE_SERVER, Boolean.FALSE);
defaults.put(LANGUAGE_SERVER_PORT, 2087);

defaults.put(EXTERNAL_JOURNAL_LISTS, "");
defaults.put(USE_AMS_FJOURNAL, true);
Expand Down Expand Up @@ -1382,12 +1386,16 @@ public RemotePreferences getRemotePreferences() {
getInt(REMOTE_SERVER_PORT),
getBoolean(USE_REMOTE_SERVER),
getInt(HTTP_SERVER_PORT),
getBoolean(ENABLE_HTTP_SERVER));
getBoolean(ENABLE_HTTP_SERVER),
getBoolean(ENABLE_LANGUAGE_SERVER),
getInt(LANGUAGE_SERVER_PORT));

EasyBind.listen(remotePreferences.portProperty(), (_, _, newValue) -> putInt(REMOTE_SERVER_PORT, newValue));
EasyBind.listen(remotePreferences.useRemoteServerProperty(), (_, _, newValue) -> putBoolean(USE_REMOTE_SERVER, newValue));
EasyBind.listen(remotePreferences.httpPortProperty(), (_, _, newValue) -> putInt(HTTP_SERVER_PORT, newValue));
EasyBind.listen(remotePreferences.enableHttpServerProperty(), (_, _, newValue) -> putBoolean(ENABLE_HTTP_SERVER, newValue));
EasyBind.listen(remotePreferences.languageServerPortProperty(), (_, _, newValue) -> putInt(LANGUAGE_SERVER_PORT, newValue));
EasyBind.listen(remotePreferences.enableLanguageServerProperty(), (_, _, newValue) -> putBoolean(ENABLE_LANGUAGE_SERVER, newValue));

return remotePreferences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ public class RemotePreferences {
private final IntegerProperty httpPort;
private final BooleanProperty enableHttpServer;

public RemotePreferences(int port, boolean useRemoteServer, int httpPort, boolean enableHttpServer) {
private final BooleanProperty enableLanguageServer;
private final IntegerProperty languageServerPort;

public RemotePreferences(int port, boolean useRemoteServer, int httpPort, boolean enableHttpServer, boolean enableLanguageServer, int languageServerPort) {
this.port = new SimpleIntegerProperty(port);
this.useRemoteServer = new SimpleBooleanProperty(useRemoteServer);
this.httpPort = new SimpleIntegerProperty(httpPort);
this.enableHttpServer = new SimpleBooleanProperty(enableHttpServer);
this.enableLanguageServer = new SimpleBooleanProperty(enableLanguageServer);
this.languageServerPort = new SimpleIntegerProperty(languageServerPort);
}

public int getPort() {
Expand Down Expand Up @@ -90,6 +95,34 @@ public void setEnableHttpServer(boolean enableHttpServer) {
this.enableHttpServer.setValue(enableHttpServer);
}

public int getLanguageServerPort() {
return languageServerPort.getValue();
}

public IntegerProperty languageServerPortProperty() {
return languageServerPort;
}

public void setLanguageServerPort(int languageServerPort) {
this.languageServerPort.setValue(languageServerPort);
}

public boolean isDifferentLanguageServerPort(int otherLanguageServerPort) {
return getLanguageServerPort() != otherLanguageServerPort;
}

public boolean enableLanguageServer() {
return enableLanguageServer.getValue();
}

public BooleanProperty enableLanguageServerProperty() {
return enableLanguageServer;
}

public void setEnableLanguageServer(boolean enableLanguageServer) {
this.enableLanguageServer.setValue(enableLanguageServer);
}

/// Gets the IP address where both the remote server and the http server are listening.
public static InetAddress getIpAddress() throws UnknownHostException {
return InetAddress.getByName("localhost");
Expand Down
9 changes: 9 additions & 0 deletions jablib/src/main/java/org/jabref/logic/remote/RemoteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ private RemoteUtil() {
public static boolean isUserPort(int portNumber) {
return (portNumber >= 1024) && (portNumber <= 65535);
}

public static boolean isStringUserPort(String portString) {
try {
int portNumber = Integer.parseInt(portString);
return isUserPort(portNumber);
} catch (NumberFormatException numberFormatException) {
return false;
}
}
}
4 changes: 4 additions & 0 deletions jablib/src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ Connect=Connect
Connection\ error=Connection error
Connection\ to\ %0\ server\ established.=Connection to %0 server established.
Required\ field\ "%0"\ is\ empty.=Required field "%0" is empty.
Optional\ field\ "%0"\ is\ empty.=Optional field "%0" is empty.
%0\ driver\ not\ available.=%0 driver not available.
The\ connection\ to\ the\ server\ has\ been\ terminated.=The connection to the server has been terminated.
Reconnect=Reconnect
Expand Down Expand Up @@ -1848,6 +1849,9 @@ Cannot\ use\ port\ %0\ for\ remote\ operation;\ another\ application\ may\ be\ u
Enable\ HTTP\ Server\ (e.g.,\ for\ JabMap)\ on\ port=Enable HTTP Server (e.g., for JabMap) on port
HTTP\ Server=HTTP Server

Enable\ Language\ Server\ on\ port=Enable Language Server on port
Language\ Server=Language Server

Grobid\ URL=Grobid URL
Allow\ sending\ PDF\ files\ and\ raw\ citation\ strings\ to\ a\ JabRef\ online\ service\ (Grobid)\ to\ determine\ Metadata.\ This\ produces\ better\ results.=Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results.
Send\ to\ Grobid=Send to Grobid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RemotePreferencesTest {

@BeforeEach
void setUp() {
preferences = new RemotePreferences(1000, true, 3000, false);
preferences = new RemotePreferences(1000, true, 3000, false, false, 2087);
}

@Test
Expand Down
Loading
Loading