Merge pull request #1420 from eclipse/jk-deprecation-cleanup

[lsp] Remove deprecated code for single root workspaces
This commit is contained in:
Jan Koehnlein 2020-03-16 10:04:17 +01:00 committed by GitHub
commit 5787c20bc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 82 additions and 138 deletions

View file

@ -8,21 +8,22 @@
*******************************************************************************/
package org.eclipse.xtext.ide.tests.server
import com.google.inject.Module
import java.io.File
import java.util.Set
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
import org.eclipse.lsp4j.FileChangeType
import org.eclipse.lsp4j.FileEvent
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.MultiRootWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.ServerModule
import org.eclipse.xtext.util.Modules2
import org.eclipse.xtext.workspace.FileProjectConfig
import org.eclipse.xtext.workspace.WorkspaceConfig
import org.junit.Test
import static org.junit.Assert.*
import com.google.inject.Module
import org.eclipse.xtext.util.Modules2
import org.eclipse.xtext.ide.server.ServerModule
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory
import org.eclipse.emf.common.util.URI
import org.eclipse.xtext.workspace.WorkspaceConfig
import org.eclipse.xtext.workspace.FileProjectConfig
import java.io.File
/**
* Checks functionality of method IProjectConfig#isIndexOnly()
@ -33,16 +34,14 @@ class IndexOnlyProjectTest extends AbstractTestLangLanguageServerTest {
override Module getServerModule() {
Modules2.mixin(new ServerModule, [
bind(IWorkspaceConfigFactory).toInstance(new ProjectWorkspaceConfigFactory() {
override findProjects(WorkspaceConfig workspaceConfig, URI location) {
if (location !== null) {
val FileProjectConfig project = new FileProjectConfig(location, workspaceConfig) {
bind(IMultiRootWorkspaceConfigFactory).toInstance(new MultiRootWorkspaceConfigFactory() {
override addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
if (workspaceFolder?.uri !== null) {
val project = new FileProjectConfig(uriExtensions.toUri(workspaceFolder.uri), getUniqueProjectName(workspaceFolder.name, existingNames)) {
override boolean isIndexOnly() {
return true;
}
};
project.addSourceFolder(".");
workspaceConfig.addProject(project);
}

View file

@ -17,7 +17,7 @@ import java.util.List
import java.util.Map
import org.eclipse.emf.common.util.URI
import org.eclipse.xtext.diagnostics.Diagnostic
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.MultiProjectWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.ServerModule
import org.eclipse.xtext.ide.server.WorkspaceManager
@ -71,7 +71,7 @@ class MultiProjectTest {
def void setup() {
val injector = Guice.createInjector(Modules2.mixin(new ServerModule, new AbstractModule() {
override protected configure() {
bind(IWorkspaceConfigFactory).to(MultiProjectWorkspaceConfigFactory)
bind(IMultiRootWorkspaceConfigFactory).to(MultiProjectWorkspaceConfigFactory)
}
}))
injector.injectMembers(this)

View file

@ -12,9 +12,11 @@ import com.google.inject.AbstractModule
import com.google.inject.Inject
import com.google.inject.Module
import com.google.inject.Scopes
import java.util.Set
import org.eclipse.emf.common.util.URI
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.MultiRootWorkspaceConfigFactory
import org.eclipse.xtext.ide.server.WorkspaceManager
import org.eclipse.xtext.util.IFileSystemScanner
import org.eclipse.xtext.util.Modules2
@ -53,13 +55,12 @@ class SourceFolderCustomImplTest extends AbstractTestLangLanguageServerTest {
assertEquals(allResources.size, 1);
}
static class CustomWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory {
override findProjects(WorkspaceConfig workspaceConfig, URI uri) {
if (uri !== null) {
val project = new CustomFileProjectConfig(uri, workspaceConfig)
project.addSourceFolder('.')
workspaceConfig.addProject(project)
static class CustomWorkspaceConfigFactory extends MultiRootWorkspaceConfigFactory {
override addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
if (workspaceFolder?.uri !== null) {
val project = new CustomFileProjectConfig(uriExtensions.toUri(workspaceFolder.uri), workspaceConfig)
project.addSourceFolder(".");
workspaceConfig.addProject(project);
}
}
}
@ -107,7 +108,7 @@ class SourceFolderCustomImplTest extends AbstractTestLangLanguageServerTest {
val Module customModule = new AbstractModule() {
override protected configure() {
bind(IWorkspaceConfigFactory).to(CustomWorkspaceConfigFactory)
bind(IMultiRootWorkspaceConfigFactory).to(CustomWorkspaceConfigFactory)
bind(WorkspaceManager).in(Scopes.SINGLETON);
}

View file

@ -12,14 +12,16 @@ import com.google.inject.Binder;
import com.google.inject.binder.AnnotatedBindingBuilder;
import java.io.File;
import java.util.Collections;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
import org.eclipse.lsp4j.FileChangeType;
import org.eclipse.lsp4j.FileEvent;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.MultiRootWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.ServerModule;
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
import org.eclipse.xtext.testing.ReferenceTestConfiguration;
@ -43,12 +45,19 @@ public class IndexOnlyProjectTest extends AbstractTestLangLanguageServerTest {
public com.google.inject.Module getServerModule() {
ServerModule _serverModule = new ServerModule();
final com.google.inject.Module _function = (Binder it) -> {
AnnotatedBindingBuilder<IWorkspaceConfigFactory> _bind = it.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class);
_bind.toInstance(new ProjectWorkspaceConfigFactory() {
AnnotatedBindingBuilder<IMultiRootWorkspaceConfigFactory> _bind = it.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class);
_bind.toInstance(new MultiRootWorkspaceConfigFactory() {
@Override
public void findProjects(final WorkspaceConfig workspaceConfig, final URI location) {
if ((location != null)) {
final FileProjectConfig project = new FileProjectConfig(location, workspaceConfig) {
public void addProjectsForWorkspaceFolder(final WorkspaceConfig workspaceConfig, final WorkspaceFolder workspaceFolder, final Set<String> existingNames) {
String _uri = null;
if (workspaceFolder!=null) {
_uri=workspaceFolder.getUri();
}
boolean _tripleNotEquals = (_uri != null);
if (_tripleNotEquals) {
URI _uri_1 = this.getUriExtensions().toUri(workspaceFolder.getUri());
String _uniqueProjectName = this.getUniqueProjectName(workspaceFolder.getName(), existingNames);
final FileProjectConfig project = new FileProjectConfig(_uri_1, _uniqueProjectName) {
@Override
public boolean isIndexOnly() {
return true;

View file

@ -20,7 +20,7 @@ import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.diagnostics.Diagnostic;
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.MultiProjectWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.ServerModule;
import org.eclipse.xtext.ide.server.WorkspaceManager;
@ -90,7 +90,7 @@ public class MultiProjectTest {
final Injector injector = Guice.createInjector(Modules2.mixin(_serverModule, new AbstractModule() {
@Override
protected void configure() {
this.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class).to(MultiProjectWorkspaceConfigFactory.class);
this.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class).to(MultiProjectWorkspaceConfigFactory.class);
}
}));
injector.injectMembers(this);

View file

@ -15,9 +15,10 @@ import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.xtext.ide.server.IMultiRootWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.MultiRootWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.ProjectManager;
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory;
import org.eclipse.xtext.ide.server.WorkspaceManager;
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
import org.eclipse.xtext.util.IFileSystemScanner;
@ -37,11 +38,17 @@ import org.junit.Test;
*/
@SuppressWarnings("all")
public class SourceFolderCustomImplTest extends AbstractTestLangLanguageServerTest {
public static class CustomWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory {
public static class CustomWorkspaceConfigFactory extends MultiRootWorkspaceConfigFactory {
@Override
public void findProjects(final WorkspaceConfig workspaceConfig, final URI uri) {
if ((uri != null)) {
final SourceFolderCustomImplTest.CustomFileProjectConfig project = new SourceFolderCustomImplTest.CustomFileProjectConfig(uri, workspaceConfig);
public void addProjectsForWorkspaceFolder(final WorkspaceConfig workspaceConfig, final WorkspaceFolder workspaceFolder, final Set<String> existingNames) {
String _uri = null;
if (workspaceFolder!=null) {
_uri=workspaceFolder.getUri();
}
boolean _tripleNotEquals = (_uri != null);
if (_tripleNotEquals) {
URI _uri_1 = this.getUriExtensions().toUri(workspaceFolder.getUri());
final SourceFolderCustomImplTest.CustomFileProjectConfig project = new SourceFolderCustomImplTest.CustomFileProjectConfig(_uri_1, workspaceConfig);
project.addSourceFolder(".");
workspaceConfig.addProject(project);
}
@ -136,7 +143,7 @@ public class SourceFolderCustomImplTest extends AbstractTestLangLanguageServerTe
final com.google.inject.Module customModule = new AbstractModule() {
@Override
protected void configure() {
this.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class).to(SourceFolderCustomImplTest.CustomWorkspaceConfigFactory.class);
this.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class).to(SourceFolderCustomImplTest.CustomWorkspaceConfigFactory.class);
this.<WorkspaceManager>bind(WorkspaceManager.class).in(Scopes.SINGLETON);
}
};

View file

@ -17,7 +17,7 @@ import org.eclipse.xtext.workspace.IWorkspaceConfig;
* @author Jan Koehnlein - Initial contribution and API
* @since 2.21
*/
public interface IMultiRootWorkspaceConfigFactory extends IWorkspaceConfigFactory {
public interface IMultiRootWorkspaceConfigFactory {
/**
* Create a workspace config at the given location.

View file

@ -1,30 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.server;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.workspace.IWorkspaceConfig;
/**
* @author Jan Koehnlein - Initial contribution and API
* @since 2.11
* @deprecated use the {@link IMultiRootWorkspaceConfigFactory} instead.
* This interface is scheduled to be removed with 2.22.
*/
@Deprecated//(forRemoval=true)
public interface IWorkspaceConfigFactory {
/**
* Create a workspace config at the given location.
*
* @param workspaceBaseURI
* the location
* @return the workspace configuration.
*/
IWorkspaceConfig getWorkspaceConfig(URI workspaceBaseURI);
}

View file

@ -9,8 +9,10 @@
package org.eclipse.xtext.ide.server;
import java.io.File;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.xtext.workspace.FileProjectConfig;
import org.eclipse.xtext.workspace.WorkspaceConfig;
@ -18,8 +20,14 @@ import org.eclipse.xtext.workspace.WorkspaceConfig;
* @author Jan Koehnlein - Initial contribution and API
* @since 2.11
*/
public class MultiProjectWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory {
public class MultiProjectWorkspaceConfigFactory extends MultiRootWorkspaceConfigFactory {
@Override
protected void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
if (workspaceFolder != null && workspaceFolder.getUri() != null)
findProjects(workspaceConfig, uriExtensions.toUri(workspaceFolder.getUri()));
}
public void findProjects(WorkspaceConfig workspaceConfig, URI uri) {
if (uri == null) {
return;

View file

@ -12,7 +12,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.xtext.workspace.FileProjectConfig;
import org.eclipse.xtext.workspace.IWorkspaceConfig;
@ -26,10 +25,10 @@ import com.google.inject.Inject;
* @author Jan Koehnlein - Initial contribution and API
* @since 2.21
*/
public class MultiRootWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory, IMultiRootWorkspaceConfigFactory {
public class MultiRootWorkspaceConfigFactory implements IMultiRootWorkspaceConfigFactory {
@Inject UriExtensions uriExtensions;
@Override
public IWorkspaceConfig getWorkspaceConfig(List<WorkspaceFolder> workspaceFolders) {
WorkspaceConfig workspaceConfig = new WorkspaceConfig();
@ -39,13 +38,6 @@ public class MultiRootWorkspaceConfigFactory extends ProjectWorkspaceConfigFacto
return workspaceConfig;
}
@Override
public IWorkspaceConfig getWorkspaceConfig(URI workspaceBaseURI) {
WorkspaceConfig workspaceConfig = new WorkspaceConfig();
addProjectsForWorkspaceFolder(workspaceConfig, new WorkspaceFolder(uriExtensions.toUriString(workspaceBaseURI), "workspace"), new HashSet<>());
return workspaceConfig;
}
protected void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
if (workspaceFolder != null && workspaceFolder.getUri() != null) {
FileProjectConfig project = new FileProjectConfig(uriExtensions.toUri(workspaceFolder.getUri()), getUniqueProjectName(workspaceFolder.getName(), existingNames));
@ -67,4 +59,11 @@ public class MultiRootWorkspaceConfigFactory extends ProjectWorkspaceConfigFacto
}
}
}
/**
* @since 2.20
*/
protected UriExtensions getUriExtensions() {
return uriExtensions;
}
}

View file

@ -1,43 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.server;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.workspace.FileProjectConfig;
import org.eclipse.xtext.workspace.IWorkspaceConfig;
import org.eclipse.xtext.workspace.WorkspaceConfig;
/**
* The workspace itself is a single project
*
* @author Jan Koehnlein - Initial contribution and API
* @since 2.11
* @deprecated use the {@link MultiRootWorkspaceConfigFactory} instead.
* This class is scheduled to be removed with 2.22.
*/
@Deprecated//(forRemoval=true)
public class ProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory {
@Override
public IWorkspaceConfig getWorkspaceConfig(URI workspaceBaseURI) {
WorkspaceConfig workspaceConfig = new WorkspaceConfig();
findProjects(workspaceConfig, workspaceBaseURI);
return workspaceConfig;
}
/**
* Find all projects at the given location. By default, only the a single project at the workspace root is created.
*/
protected void findProjects(WorkspaceConfig workspaceConfig, URI location) {
if (location != null) {
FileProjectConfig project = new FileProjectConfig(location, workspaceConfig);
project.addSourceFolder(".");
workspaceConfig.addProject(project);
}
}
}

View file

@ -29,8 +29,7 @@ public class ServerModule extends AbstractModule {
bind(LanguageServer.class).to(LanguageServerImpl.class);
bind(IResourceServiceProvider.Registry.class).toProvider(ResourceServiceProviderServiceLoader.class);
bind(IWorkspaceConfigFactory.class).to(ProjectWorkspaceConfigFactory.class);
bind(ProjectWorkspaceConfigFactory.class).to(MultiRootWorkspaceConfigFactory.class);
bind(IMultiRootWorkspaceConfigFactory.class).to(MultiRootWorkspaceConfigFactory.class);
bind(IProjectDescriptionFactory.class).to(DefaultProjectDescriptionFactory.class);
bind(IContainer.Manager.class).to(ProjectDescriptionBasedContainerManager.class);
}

View file

@ -59,7 +59,7 @@ public class WorkspaceManager {
private Provider<ProjectManager> projectManagerProvider;
@Inject
private IWorkspaceConfigFactory workspaceConfigFactory;
private IMultiRootWorkspaceConfigFactory workspaceConfigFactory;
@Inject
private IProjectDescriptionFactory projectDescriptionFactory;
@ -174,7 +174,7 @@ public class WorkspaceManager {
* @since 2.21
*/
public boolean isSupportsWorkspaceFolders() {
return workspaceConfigFactory instanceof IMultiRootWorkspaceConfigFactory;
return true;
}
protected List<WorkspaceFolder> getWorkspaceFolders() {
@ -200,12 +200,7 @@ public class WorkspaceManager {
}
protected IWorkspaceConfig createWorkspaceConfig() {
if (isSupportsWorkspaceFolders())
return ((IMultiRootWorkspaceConfigFactory) workspaceConfigFactory).getWorkspaceConfig(workspaceFolders);
URI workspaceUri = (!workspaceFolders.isEmpty())
? uriExtensions.toUri(workspaceFolders.get(0).getUri())
: null;
return workspaceConfigFactory.getWorkspaceConfig(workspaceUri);
return workspaceConfigFactory.getWorkspaceConfig(workspaceFolders);
}
/**