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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.lsp4mp.ls.commons.ParentProcessWatcher.ProcessLanguageServer;
import org.eclipse.lsp4mp.ls.commons.client.ExtendedClientCapabilities;
import org.eclipse.lsp4mp.ls.commons.client.InitializationOptionsExtendedClientCapabilities;
import org.eclipse.lsp4mp.services.properties.PropertiesFileLanguageService;
import org.eclipse.lsp4mp.settings.AllMicroProfileSettings;
import org.eclipse.lsp4mp.settings.InitializationOptionsSettings;
import org.eclipse.lsp4mp.settings.MicroProfileCodeLensSettings;
Expand All @@ -61,8 +60,6 @@ public class MicroProfileLanguageServer implements LanguageServer, ProcessLangua
MicroProfileJavaProjectLabelsProvider, MicroProfileJavaFileInfoProvider {

private static final Logger LOGGER = Logger.getLogger(MicroProfileLanguageServer.class.getName());

private final PropertiesFileLanguageService propertiesFileLanguageService;
private final MicroProfileTextDocumentService textDocumentService;
private final WorkspaceService workspaceService;

Expand All @@ -73,7 +70,6 @@ public class MicroProfileLanguageServer implements LanguageServer, ProcessLangua
private MicroProfileCapabilityManager capabilityManager;

public MicroProfileLanguageServer() {
propertiesFileLanguageService = new PropertiesFileLanguageService();
textDocumentService = new MicroProfileTextDocumentService(this);
workspaceService = new MicroProfileWorkspaceService(this);
this.extensionSettings = new MicroProfileExtensionSettings();
Expand Down Expand Up @@ -189,10 +185,6 @@ public long getParentProcessId() {
return parentProcessId != null ? parentProcessId : 0;
}

public PropertiesFileLanguageService getPropertiesFileLanguageService() {
return propertiesFileLanguageService;
}

@Override
public void propertiesChanged(MicroProfilePropertiesChangeEvent event) {
textDocumentService.propertiesChanged(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.CompletableFutures;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4mp.commons.DocumentFormat;
import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeLensParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaDefinitionParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaHoverParams;
import org.eclipse.lsp4mp.commons.MicroProfilePropertiesChangeEvent;
import org.eclipse.lsp4mp.ls.AbstractTextDocumentService;
import org.eclipse.lsp4mp.ls.MicroProfileLanguageServer;
Expand All @@ -61,14 +57,10 @@
import org.eclipse.lsp4mp.ls.commons.client.CommandKind;
import org.eclipse.lsp4mp.ls.java.JavaTextDocuments.JavaTextDocument;
import org.eclipse.lsp4mp.ls.properties.IPropertiesModelProvider;
import org.eclipse.lsp4mp.model.Node;
import org.eclipse.lsp4mp.model.PropertiesModel;
import org.eclipse.lsp4mp.model.Property;
import org.eclipse.lsp4mp.services.java.JavaFileLanguageService;
import org.eclipse.lsp4mp.settings.MicroProfileCodeLensSettings;
import org.eclipse.lsp4mp.settings.SharedSettings;
import org.eclipse.lsp4mp.snippets.SnippetContextForJava;
import org.eclipse.lsp4mp.utils.PropertiesFileUtils;
import org.eclipse.lsp4mp.utils.PositionUtils;

/**
* LSP text document service for Java file.
Expand All @@ -83,9 +75,12 @@ public class JavaFileTextDocumentService extends AbstractTextDocumentService {
private final IPropertiesModelProvider propertiesModelProvider;
private final JavaTextDocuments documents;

private final JavaFileLanguageService javaFileLanguageService;

public JavaFileTextDocumentService(MicroProfileLanguageServer microprofileLanguageServer,
IPropertiesModelProvider propertiesModelProvider, SharedSettings sharedSettings) {
super(microprofileLanguageServer, sharedSettings);
this.javaFileLanguageService = new JavaFileLanguageService();
this.propertiesModelProvider = propertiesModelProvider;
this.documents = new JavaTextDocuments(microprofileLanguageServer, microprofileLanguageServer);
}
Expand Down Expand Up @@ -207,54 +202,8 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio
DefinitionParams params) {
JavaTextDocument document = documents.get(params.getTextDocument().getUri());
return document.executeIfInMicroProfileProject((projectinfo) -> {
MicroProfileJavaDefinitionParams javaParams = new MicroProfileJavaDefinitionParams(
params.getTextDocument().getUri(), params.getPosition());
return microprofileLanguageServer.getLanguageClient().getJavaDefinition(javaParams)
.thenApply(definitions -> {
List<LocationLink> locations = definitions.stream() //
.filter(definition -> definition.getLocation() != null) //
.map(definition -> {
LocationLink location = definition.getLocation();
String propertyName = definition.getSelectPropertyName();
if (propertyName != null) {
Range targetRange = null;
// The target range must be resolved
String documentURI = location.getTargetUri();
if (documentURI.endsWith(".properties")) {
PropertiesModel model = propertiesModelProvider
.getPropertiesModel(documentURI);
if (model == null) {
model = PropertiesFileUtils.loadProperties(documentURI);
}
if (model != null) {
for (Node node : model.getChildren()) {
if (node.getNodeType() == Node.NodeType.PROPERTY) {
Property property = (Property) node;
if (propertyName
.equals(property.getPropertyNameWithProfile())) {
targetRange = PositionUtils.createRange(property.getKey());
}
}
}
}
}
if (targetRange == null) {
targetRange = new Range(new Position(0, 0), new Position(0, 0));
}
location.setTargetRange(targetRange);
location.setTargetSelectionRange(targetRange);
}
return location;
}).collect(Collectors.toList());
if (isDefinitionLinkSupport()) {
// I don't understand
// return Either.forRight(locations);
}
return Either.forLeft(locations.stream() //
.map((link) -> {
return new Location(link.getTargetUri(), link.getTargetRange());
}).collect(Collectors.toList()));
});
return javaFileLanguageService.findDefinition(document, params.getPosition(),
microprofileLanguageServer.getLanguageClient(), propertiesModelProvider, isDefinitionLinkSupport());
}, null);
}

Expand All @@ -264,12 +213,8 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio
public CompletableFuture<Hover> hover(HoverParams params) {
JavaTextDocument document = documents.get(params.getTextDocument().getUri());
return document.executeIfInMicroProfileProject((projectinfo) -> {
boolean markdownSupported = sharedSettings.getHoverSettings().isContentFormatSupported(MarkupKind.MARKDOWN);
boolean surroundEqualsWithSpaces = sharedSettings.getFormattingSettings().isSurroundEqualsWithSpaces();
DocumentFormat documentFormat = markdownSupported ? DocumentFormat.Markdown : DocumentFormat.PlainText;
MicroProfileJavaHoverParams javaParams = new MicroProfileJavaHoverParams(params.getTextDocument().getUri(),
params.getPosition(), documentFormat, surroundEqualsWithSpaces);
return microprofileLanguageServer.getLanguageClient().getJavaHover(javaParams);
return javaFileLanguageService.doHover(document, params.getPosition(),
microprofileLanguageServer.getLanguageClient(), sharedSettings);
}, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ public class PropertiesFileTextDocumentService extends AbstractTextDocumentServi

private MicroProfileProjectInfoCache projectInfoCache;

private final PropertiesFileLanguageService propertiesFileLanguageService;

public PropertiesFileTextDocumentService(MicroProfileLanguageServer microprofileLanguageServer,
SharedSettings sharedSettings) {
super(microprofileLanguageServer, sharedSettings);
this.propertiesFileLanguageService = new PropertiesFileLanguageService();
this.documents = new ModelTextDocuments<PropertiesModel>((document, cancelChecker) -> {
return PropertiesModel.parse(document);
});
Expand Down Expand Up @@ -244,7 +247,7 @@ private MicroProfileProjectInfoParams createProjectInfoParams(String uri) {
}

private PropertiesFileLanguageService getPropertiesFileLanguageService() {
return microprofileLanguageServer.getPropertiesFileLanguageService();
return propertiesFileLanguageService;
}

private void triggerValidationFor(ModelTextDocument<PropertiesModel> document) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lsp4mp.services.java;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4mp.commons.MicroProfileJavaDefinitionParams;
import org.eclipse.lsp4mp.ls.api.MicroProfileJavaDefinitionProvider;
import org.eclipse.lsp4mp.ls.commons.TextDocument;
import org.eclipse.lsp4mp.ls.properties.IPropertiesModelProvider;
import org.eclipse.lsp4mp.model.Node;
import org.eclipse.lsp4mp.model.PropertiesModel;
import org.eclipse.lsp4mp.model.Property;
import org.eclipse.lsp4mp.utils.PositionUtils;
import org.eclipse.lsp4mp.utils.PropertiesFileUtils;

/**
* Java file definition support.
*
* @author Angelo ZERR
*
*/
class JavaFileDefinition {

public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> findDefinition(
TextDocument document, Position position, MicroProfileJavaDefinitionProvider definitionProvider,
IPropertiesModelProvider propertiesModelProvider, boolean definitionLinkSupport) {
MicroProfileJavaDefinitionParams javaParams = new MicroProfileJavaDefinitionParams(document.getUri(), position);
return definitionProvider.getJavaDefinition(javaParams).thenApply(definitions -> {
List<LocationLink> locations = definitions.stream() //
.filter(definition -> definition.getLocation() != null) //
.map(definition -> {
LocationLink location = definition.getLocation();
String propertyName = definition.getSelectPropertyName();
if (propertyName != null) {
Range targetRange = null;
// The target range must be resolved
String documentURI = location.getTargetUri();
if (documentURI.endsWith(".properties")) {
PropertiesModel model = propertiesModelProvider.getPropertiesModel(documentURI);
if (model == null) {
model = PropertiesFileUtils.loadProperties(documentURI);
}
if (model != null) {
for (Node node : model.getChildren()) {
if (node.getNodeType() == Node.NodeType.PROPERTY) {
Property property = (Property) node;
if (propertyName.equals(property.getPropertyNameWithProfile())) {
targetRange = PositionUtils.createRange(property.getKey());
}
}
}
}
}
if (targetRange == null) {
targetRange = new Range(new Position(0, 0), new Position(0, 0));
}
location.setTargetRange(targetRange);
location.setTargetSelectionRange(targetRange);
}
return location;
}).collect(Collectors.toList());
if (definitionLinkSupport) {
// I don't understand
// return Either.forRight(locations);
}
return Either.forLeft(locations.stream() //
.map((link) -> {
return new Location(link.getTargetUri(), link.getTargetRange());
}).collect(Collectors.toList()));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lsp4mp.services.java;

import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4mp.commons.DocumentFormat;
import org.eclipse.lsp4mp.commons.MicroProfileJavaHoverParams;
import org.eclipse.lsp4mp.ls.api.MicroProfileJavaHoverProvider;
import org.eclipse.lsp4mp.ls.commons.TextDocument;
import org.eclipse.lsp4mp.settings.SharedSettings;

/**
* Java file hover support.
*
* @author Angelo ZERR
*
*/
class JavaFileHover {

public CompletableFuture<Hover> doHover(TextDocument document, Position position,
MicroProfileJavaHoverProvider hoverProvider, SharedSettings sharedSettings) {
boolean markdownSupported = sharedSettings.getHoverSettings().isContentFormatSupported(MarkupKind.MARKDOWN);
boolean surroundEqualsWithSpaces = sharedSettings.getFormattingSettings().isSurroundEqualsWithSpaces();
DocumentFormat documentFormat = markdownSupported ? DocumentFormat.Markdown : DocumentFormat.PlainText;
MicroProfileJavaHoverParams javaParams = new MicroProfileJavaHoverParams(document.getUri(), position,
documentFormat, surroundEqualsWithSpaces);
return hoverProvider.getJavaHover(javaParams);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lsp4mp.services.java;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4mp.ls.api.MicroProfileJavaDefinitionProvider;
import org.eclipse.lsp4mp.ls.api.MicroProfileJavaHoverProvider;
import org.eclipse.lsp4mp.ls.commons.TextDocument;
import org.eclipse.lsp4mp.ls.properties.IPropertiesModelProvider;
import org.eclipse.lsp4mp.settings.SharedSettings;

/**
* The Java file language service.
*
* @author Angelo ZERR
*
*/
public class JavaFileLanguageService {

private final JavaFileHover hover;

private final JavaFileDefinition definition;

public JavaFileLanguageService() {
this.definition = new JavaFileDefinition();
this.hover = new JavaFileHover();
}

public CompletableFuture<Hover> doHover(TextDocument document, Position position,
MicroProfileJavaHoverProvider hoverProvider, SharedSettings sharedSettings) {
return hover.doHover(document, position, hoverProvider, sharedSettings);
}

public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> findDefinition(
TextDocument document, Position position, MicroProfileJavaDefinitionProvider definitionProvider,
IPropertiesModelProvider propertiesModelProvider, boolean definitionLinkSupport) {
return definition.findDefinition(document, position, definitionProvider, propertiesModelProvider,
definitionLinkSupport);
}

}