mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
[ls] unifies workspace configs
Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
This commit is contained in:
parent
45f3064d67
commit
987146a77f
14 changed files with 325 additions and 595 deletions
|
@ -14,10 +14,10 @@ import org.eclipse.lsp4j.TextDocumentItem
|
|||
import org.eclipse.lsp4j.TextDocumentPositionParams
|
||||
import org.junit.Test
|
||||
|
||||
class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
||||
class UnknownProjectConfigTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testCompletionWithInmemoryScheme() {
|
||||
def void testCompletionWithInmemoryScheme_01() {
|
||||
initialize[rootUri = null]
|
||||
val inmemoryUri = 'inmemory:/mydoc.testlang'
|
||||
languageServer.didOpen(new DidOpenTextDocumentParams => [
|
||||
|
@ -32,7 +32,22 @@ class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
def void testCompletionWithFileScheme() {
|
||||
def void testCompletionWithInmemoryScheme_02() {
|
||||
initialize
|
||||
val inmemoryUri = 'inmemory:/mydoc.testlang'
|
||||
languageServer.didOpen(new DidOpenTextDocumentParams => [
|
||||
textDocument = new TextDocumentItem => [
|
||||
uri = inmemoryUri
|
||||
text = '''
|
||||
type Foo {}
|
||||
'''
|
||||
]
|
||||
])
|
||||
checkCompletion(inmemoryUri)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletionWithFileScheme_01() {
|
||||
initialize[rootUri = null]
|
||||
val fileUri = 'file:/home/test/workspace/mydoc.testlang'
|
||||
languageServer.didOpen(new DidOpenTextDocumentParams => [
|
||||
|
@ -45,6 +60,21 @@ class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
|||
])
|
||||
checkCompletion(fileUri)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletionWithFileScheme_02() {
|
||||
initialize
|
||||
val fileUri = 'file:/home/test/workspace/mydoc.testlang'
|
||||
languageServer.didOpen(new DidOpenTextDocumentParams => [
|
||||
textDocument = new TextDocumentItem => [
|
||||
uri = fileUri
|
||||
text = '''
|
||||
type Foo {}
|
||||
'''
|
||||
]
|
||||
])
|
||||
checkCompletion(fileUri)
|
||||
}
|
||||
|
||||
protected def checkCompletion(String uri) {
|
||||
val completionItems = languageServer.completion(new TextDocumentPositionParams => [
|
|
@ -26,9 +26,9 @@ import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
|||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
||||
public class UnknownProjectConfigTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testCompletionWithInmemoryScheme() {
|
||||
public void testCompletionWithInmemoryScheme_01() {
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
|
||||
it.setRootUri(null);
|
||||
};
|
||||
|
@ -53,7 +53,29 @@ public class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCompletionWithFileScheme() {
|
||||
public void testCompletionWithInmemoryScheme_02() {
|
||||
this.initialize();
|
||||
final String inmemoryUri = "inmemory:/mydoc.testlang";
|
||||
DidOpenTextDocumentParams _didOpenTextDocumentParams = new DidOpenTextDocumentParams();
|
||||
final Procedure1<DidOpenTextDocumentParams> _function = (DidOpenTextDocumentParams it) -> {
|
||||
TextDocumentItem _textDocumentItem = new TextDocumentItem();
|
||||
final Procedure1<TextDocumentItem> _function_1 = (TextDocumentItem it_1) -> {
|
||||
it_1.setUri(inmemoryUri);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
it_1.setText(_builder.toString());
|
||||
};
|
||||
TextDocumentItem _doubleArrow = ObjectExtensions.<TextDocumentItem>operator_doubleArrow(_textDocumentItem, _function_1);
|
||||
it.setTextDocument(_doubleArrow);
|
||||
};
|
||||
DidOpenTextDocumentParams _doubleArrow = ObjectExtensions.<DidOpenTextDocumentParams>operator_doubleArrow(_didOpenTextDocumentParams, _function);
|
||||
this.languageServer.didOpen(_doubleArrow);
|
||||
this.checkCompletion(inmemoryUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletionWithFileScheme_01() {
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
|
||||
it.setRootUri(null);
|
||||
};
|
||||
|
@ -77,6 +99,28 @@ public class InMemoryWorkspaceTest extends AbstractTestLangLanguageServerTest {
|
|||
this.checkCompletion(fileUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletionWithFileScheme_02() {
|
||||
this.initialize();
|
||||
final String fileUri = "file:/home/test/workspace/mydoc.testlang";
|
||||
DidOpenTextDocumentParams _didOpenTextDocumentParams = new DidOpenTextDocumentParams();
|
||||
final Procedure1<DidOpenTextDocumentParams> _function = (DidOpenTextDocumentParams it) -> {
|
||||
TextDocumentItem _textDocumentItem = new TextDocumentItem();
|
||||
final Procedure1<TextDocumentItem> _function_1 = (TextDocumentItem it_1) -> {
|
||||
it_1.setUri(fileUri);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
it_1.setText(_builder.toString());
|
||||
};
|
||||
TextDocumentItem _doubleArrow = ObjectExtensions.<TextDocumentItem>operator_doubleArrow(_textDocumentItem, _function_1);
|
||||
it.setTextDocument(_doubleArrow);
|
||||
};
|
||||
DidOpenTextDocumentParams _doubleArrow = ObjectExtensions.<DidOpenTextDocumentParams>operator_doubleArrow(_didOpenTextDocumentParams, _function);
|
||||
this.languageServer.didOpen(_doubleArrow);
|
||||
this.checkCompletion(fileUri);
|
||||
}
|
||||
|
||||
protected void checkCompletion(final String uri) {
|
||||
try {
|
||||
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
|
|
@ -9,18 +9,17 @@ package org.eclipse.xtext.ide.server
|
|||
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig
|
||||
import org.eclipse.xtext.workspace.FileSourceFolder
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig
|
||||
import org.eclipse.xtext.workspace.InMemoryProjectConfig
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig
|
||||
|
||||
/**
|
||||
* @author Jan Koehnlein - Initial contribution and API
|
||||
* @since 2.11
|
||||
*/
|
||||
interface IWorkspaceConfigFactory {
|
||||
|
||||
def IWorkspaceConfig getWorkspaceConfig(URI workspaceBaseURI)
|
||||
|
||||
|
||||
def IWorkspaceConfig getWorkspaceConfig(URI workspaceBaseURI)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,16 +29,20 @@ interface IWorkspaceConfigFactory {
|
|||
* @since 2.11
|
||||
*/
|
||||
class ProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory {
|
||||
|
||||
override getWorkspaceConfig(URI workspaceBaseURI) {
|
||||
if (workspaceBaseURI === null) {
|
||||
val projectConfig = new InMemoryProjectConfig
|
||||
return projectConfig.workspaceConfig
|
||||
} else {
|
||||
val projectConfig = new FileProjectConfig(workspaceBaseURI)
|
||||
projectConfig.sourceFolders += new FileSourceFolder(projectConfig, '.')
|
||||
return projectConfig.workspaceConfig
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override getWorkspaceConfig(URI workspaceBaseURI) {
|
||||
val workspaceConfig = new WorkspaceConfig
|
||||
workspaceConfig.findProjects(workspaceBaseURI)
|
||||
return workspaceConfig
|
||||
}
|
||||
|
||||
def void findProjects(WorkspaceConfig workspaceConfig, URI uri) {
|
||||
if (uri !== null) {
|
||||
val project = new FileProjectConfig(uri, workspaceConfig)
|
||||
project.addSourceFolder('.')
|
||||
workspaceConfig.addProject(project)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,93 +8,27 @@
|
|||
package org.eclipse.xtext.ide.server
|
||||
|
||||
import java.io.File
|
||||
import java.util.HashSet
|
||||
import java.util.Map
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.util.IAcceptor
|
||||
import org.eclipse.xtext.workspace.IProjectConfig
|
||||
import org.eclipse.xtext.workspace.ISourceFolder
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig
|
||||
import org.eclipse.xtext.workspace.InMemoryProjectConfig
|
||||
|
||||
import static extension org.eclipse.xtext.util.UriUtil.*
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig
|
||||
|
||||
/**
|
||||
* @author Jan Koehnlein - Initial contribution and API
|
||||
* @since 2.11
|
||||
*/
|
||||
class MultiProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory {
|
||||
|
||||
override getWorkspaceConfig(URI workspaceBaseURI) {
|
||||
if (workspaceBaseURI === null) {
|
||||
val projectConfig = new InMemoryProjectConfig
|
||||
return projectConfig.workspaceConfig
|
||||
} else {
|
||||
val baseFile = new File(workspaceBaseURI.toFileString)
|
||||
if (baseFile.isDirectory) {
|
||||
val name2config = <String, IProjectConfig> newHashMap
|
||||
val result = new MultiProjectWorkspaceConfig(name2config)
|
||||
val IAcceptor<IProjectConfig> acceptor = [
|
||||
name2config.put(name, it)
|
||||
]
|
||||
baseFile.listFiles.filter[directory].forEach [
|
||||
addProjectConfigs(URI.createFileURI(absolutePath), result, acceptor)
|
||||
]
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addProjectConfigs(URI projectBaseURI, IWorkspaceConfig workspaceConfig, IAcceptor<IProjectConfig> acceptor) {
|
||||
acceptor.accept(new RootSourceFolderProjectConfig(projectBaseURI.appendSegment(''), projectBaseURI.lastSegment, workspaceConfig))
|
||||
}
|
||||
class MultiProjectWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory {
|
||||
|
||||
override void findProjects(WorkspaceConfig workspaceConfig, URI uri) {
|
||||
if(uri === null) return;
|
||||
|
||||
val baseFile = new File(uri.toFileString)
|
||||
if(!baseFile.isDirectory) return;
|
||||
|
||||
for (file : baseFile.listFiles.filter[directory]) {
|
||||
val project = new FileProjectConfig(file, workspaceConfig)
|
||||
project.addSourceFolder('.')
|
||||
workspaceConfig.addProject(project)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FinalFieldsConstructor
|
||||
class MultiProjectWorkspaceConfig implements IWorkspaceConfig {
|
||||
|
||||
val Map<String, IProjectConfig> name2config
|
||||
|
||||
override getProjects() {
|
||||
new HashSet(name2config.values)
|
||||
}
|
||||
|
||||
override findProjectByName(String name) {
|
||||
name2config.get(name)
|
||||
}
|
||||
|
||||
override findProjectContaining(URI member) {
|
||||
val candidates = name2config.values.filter[
|
||||
findSourceFolderContaining(member) !== null
|
||||
]
|
||||
if (!candidates.empty)
|
||||
return candidates.maxBy[path.segmentCount]
|
||||
else
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Jan Koehnlein - Initial contribution and API
|
||||
* @since 2.11
|
||||
*/
|
||||
@Data
|
||||
class RootSourceFolderProjectConfig implements IProjectConfig, ISourceFolder {
|
||||
val URI path
|
||||
val String name
|
||||
val IWorkspaceConfig workspaceConfig
|
||||
|
||||
override findSourceFolderContaining(URI member) {
|
||||
if(path.isPrefixOf(member))
|
||||
this
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
override getSourceFolders() {
|
||||
#{this}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,10 @@
|
|||
package org.eclipse.xtext.ide.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
|
||||
import org.eclipse.xtext.ide.server.MultiProjectWorkspaceConfig;
|
||||
import org.eclipse.xtext.ide.server.RootSourceFolderProjectConfig;
|
||||
import org.eclipse.xtext.util.IAcceptor;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.InMemoryProjectConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory;
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
@ -28,40 +21,29 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
|||
* @since 2.11
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class MultiProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory {
|
||||
public class MultiProjectWorkspaceConfigFactory extends ProjectWorkspaceConfigFactory {
|
||||
@Override
|
||||
public IWorkspaceConfig getWorkspaceConfig(final URI workspaceBaseURI) {
|
||||
if ((workspaceBaseURI == null)) {
|
||||
final InMemoryProjectConfig projectConfig = new InMemoryProjectConfig();
|
||||
return projectConfig.getWorkspaceConfig();
|
||||
} else {
|
||||
String _fileString = workspaceBaseURI.toFileString();
|
||||
final File baseFile = new File(_fileString);
|
||||
boolean _isDirectory = baseFile.isDirectory();
|
||||
if (_isDirectory) {
|
||||
final HashMap<String, IProjectConfig> name2config = CollectionLiterals.<String, IProjectConfig>newHashMap();
|
||||
final MultiProjectWorkspaceConfig result = new MultiProjectWorkspaceConfig(name2config);
|
||||
final IAcceptor<IProjectConfig> _function = (IProjectConfig it) -> {
|
||||
name2config.put(it.getName(), it);
|
||||
};
|
||||
final IAcceptor<IProjectConfig> acceptor = _function;
|
||||
final Function1<File, Boolean> _function_1 = (File it) -> {
|
||||
return Boolean.valueOf(it.isDirectory());
|
||||
};
|
||||
final Consumer<File> _function_2 = (File it) -> {
|
||||
this.addProjectConfigs(URI.createFileURI(it.getAbsolutePath()), result, acceptor);
|
||||
};
|
||||
IterableExtensions.<File>filter(((Iterable<File>)Conversions.doWrapArray(baseFile.listFiles())), _function_1).forEach(_function_2);
|
||||
return result;
|
||||
public void findProjects(final WorkspaceConfig workspaceConfig, final URI uri) {
|
||||
if ((uri == null)) {
|
||||
return;
|
||||
}
|
||||
String _fileString = uri.toFileString();
|
||||
final File baseFile = new File(_fileString);
|
||||
boolean _isDirectory = baseFile.isDirectory();
|
||||
boolean _not = (!_isDirectory);
|
||||
if (_not) {
|
||||
return;
|
||||
}
|
||||
final Function1<File, Boolean> _function = (File it) -> {
|
||||
return Boolean.valueOf(it.isDirectory());
|
||||
};
|
||||
Iterable<File> _filter = IterableExtensions.<File>filter(((Iterable<File>)Conversions.doWrapArray(baseFile.listFiles())), _function);
|
||||
for (final File file : _filter) {
|
||||
{
|
||||
final FileProjectConfig project = new FileProjectConfig(file, workspaceConfig);
|
||||
project.addSourceFolder(".");
|
||||
workspaceConfig.addProject(project);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addProjectConfigs(final URI projectBaseURI, final IWorkspaceConfig workspaceConfig, final IAcceptor<IProjectConfig> acceptor) {
|
||||
URI _appendSegment = projectBaseURI.appendSegment("");
|
||||
String _lastSegment = projectBaseURI.lastSegment();
|
||||
RootSourceFolderProjectConfig _rootSourceFolderProjectConfig = new RootSourceFolderProjectConfig(_appendSegment, _lastSegment, workspaceConfig);
|
||||
acceptor.accept(_rootSourceFolderProjectConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
*/
|
||||
package org.eclipse.xtext.ide.server;
|
||||
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig;
|
||||
import org.eclipse.xtext.workspace.FileSourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.InMemoryProjectConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
|
||||
/**
|
||||
* The workspace itself is a single project
|
||||
|
@ -25,15 +23,16 @@ import org.eclipse.xtext.workspace.InMemoryProjectConfig;
|
|||
public class ProjectWorkspaceConfigFactory implements IWorkspaceConfigFactory {
|
||||
@Override
|
||||
public IWorkspaceConfig getWorkspaceConfig(final URI workspaceBaseURI) {
|
||||
if ((workspaceBaseURI == null)) {
|
||||
final InMemoryProjectConfig projectConfig = new InMemoryProjectConfig();
|
||||
return projectConfig.getWorkspaceConfig();
|
||||
} else {
|
||||
final FileProjectConfig projectConfig_1 = new FileProjectConfig(workspaceBaseURI);
|
||||
Set<FileSourceFolder> _sourceFolders = projectConfig_1.getSourceFolders();
|
||||
FileSourceFolder _fileSourceFolder = new FileSourceFolder(projectConfig_1, ".");
|
||||
_sourceFolders.add(_fileSourceFolder);
|
||||
return projectConfig_1.getWorkspaceConfig();
|
||||
final WorkspaceConfig workspaceConfig = new WorkspaceConfig();
|
||||
this.findProjects(workspaceConfig, workspaceBaseURI);
|
||||
return workspaceConfig;
|
||||
}
|
||||
|
||||
public void findProjects(final WorkspaceConfig workspaceConfig, final URI uri) {
|
||||
if ((uri != null)) {
|
||||
final FileProjectConfig project = new FileProjectConfig(uri, workspaceConfig);
|
||||
project.addSourceFolder(".");
|
||||
workspaceConfig.addProject(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.ide.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.Data;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Jan Koehnlein - Initial contribution and API
|
||||
* @since 2.11
|
||||
*/
|
||||
@Data
|
||||
@SuppressWarnings("all")
|
||||
public class RootSourceFolderProjectConfig implements IProjectConfig, ISourceFolder {
|
||||
private final URI path;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final IWorkspaceConfig workspaceConfig;
|
||||
|
||||
@Override
|
||||
public ISourceFolder findSourceFolderContaining(final URI member) {
|
||||
RootSourceFolderProjectConfig _xifexpression = null;
|
||||
boolean _isPrefixOf = UriUtil.isPrefixOf(this.path, member);
|
||||
if (_isPrefixOf) {
|
||||
_xifexpression = this;
|
||||
} else {
|
||||
_xifexpression = null;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends ISourceFolder> getSourceFolders() {
|
||||
return Collections.<ISourceFolder>unmodifiableSet(CollectionLiterals.<ISourceFolder>newHashSet(this));
|
||||
}
|
||||
|
||||
public RootSourceFolderProjectConfig(final URI path, final String name, final IWorkspaceConfig workspaceConfig) {
|
||||
super();
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.workspaceConfig = workspaceConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.path== null) ? 0 : this.path.hashCode());
|
||||
result = prime * result + ((this.name== null) ? 0 : this.name.hashCode());
|
||||
result = prime * result + ((this.workspaceConfig== null) ? 0 : this.workspaceConfig.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RootSourceFolderProjectConfig other = (RootSourceFolderProjectConfig) obj;
|
||||
if (this.path == null) {
|
||||
if (other.path != null)
|
||||
return false;
|
||||
} else if (!this.path.equals(other.path))
|
||||
return false;
|
||||
if (this.name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!this.name.equals(other.name))
|
||||
return false;
|
||||
if (this.workspaceConfig == null) {
|
||||
if (other.workspaceConfig != null)
|
||||
return false;
|
||||
} else if (!this.workspaceConfig.equals(other.workspaceConfig))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.add("path", this.path);
|
||||
b.add("name", this.name);
|
||||
b.add("workspaceConfig", this.workspaceConfig);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return this.workspaceConfig;
|
||||
}
|
||||
}
|
|
@ -10,32 +10,51 @@ package org.eclipse.xtext.workspace
|
|||
import java.io.File
|
||||
import java.util.Set
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.util.UriUtil
|
||||
|
||||
import static extension org.eclipse.xtext.util.UriUtil.*
|
||||
import org.eclipse.xtext.util.UriUtil
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
|
||||
@Accessors
|
||||
class FileProjectConfig implements IProjectConfig {
|
||||
val URI path
|
||||
val String name
|
||||
val Set<FileSourceFolder> sourceFolders = newHashSet
|
||||
val IWorkspaceConfig workspaceConfig
|
||||
|
||||
new (URI path) {
|
||||
this(path, path.lastSegment)
|
||||
this(path, null as IWorkspaceConfig)
|
||||
}
|
||||
|
||||
new (URI path, String name) {
|
||||
this.path = path
|
||||
this.name = name
|
||||
this(path, name, null as IWorkspaceConfig)
|
||||
}
|
||||
|
||||
new (File root, String name) {
|
||||
this(UriUtil.createFolderURI(root), name)
|
||||
this(root, name, null as IWorkspaceConfig)
|
||||
}
|
||||
|
||||
new (File root) {
|
||||
this(UriUtil.createFolderURI(root), root.name)
|
||||
this(root, null as IWorkspaceConfig)
|
||||
}
|
||||
|
||||
new (URI path, IWorkspaceConfig workspaceConfig) {
|
||||
this(path, path.lastSegment, workspaceConfig)
|
||||
}
|
||||
|
||||
new (URI path, String name, IWorkspaceConfig workspaceConfig) {
|
||||
this.path = path
|
||||
this.name = name
|
||||
this.workspaceConfig = workspaceConfig ?: new WorkspaceConfig(this)
|
||||
}
|
||||
|
||||
new (File root, String name, IWorkspaceConfig workspaceConfig) {
|
||||
this(UriUtil.createFolderURI(root), name, workspaceConfig)
|
||||
}
|
||||
|
||||
new (File root, IWorkspaceConfig workspaceConfig) {
|
||||
this(UriUtil.createFolderURI(root), root.name, workspaceConfig)
|
||||
}
|
||||
|
||||
def FileSourceFolder addSourceFolder(String relativePath) {
|
||||
|
@ -48,18 +67,6 @@ class FileProjectConfig implements IProjectConfig {
|
|||
sourceFolders.findFirst[source|source.path.isPrefixOf(member)]
|
||||
}
|
||||
|
||||
override getName() {
|
||||
name
|
||||
}
|
||||
|
||||
override getPath() {
|
||||
path
|
||||
}
|
||||
|
||||
override Set<FileSourceFolder> getSourceFolders() {
|
||||
sourceFolders
|
||||
}
|
||||
|
||||
override equals(Object obj) {
|
||||
if (obj instanceof FileProjectConfig) {
|
||||
return path == obj.path
|
||||
|
@ -74,10 +81,6 @@ class FileProjectConfig implements IProjectConfig {
|
|||
override toString() {
|
||||
'''Project «name» («path»)'''
|
||||
}
|
||||
|
||||
override getWorkspaceConfig() {
|
||||
return new SingleProjectWorkspaceConfig(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,28 +118,3 @@ class FileSourceFolder implements ISourceFolder {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
class SingleProjectWorkspaceConfig implements IWorkspaceConfig {
|
||||
|
||||
IProjectConfig projectConfig
|
||||
|
||||
override findProjectByName(String name) {
|
||||
if (projectConfig.name == name)
|
||||
return projectConfig
|
||||
else
|
||||
return null
|
||||
}
|
||||
|
||||
override findProjectContaining(URI member) {
|
||||
if (projectConfig.path.isPrefixOf(member))
|
||||
return projectConfig
|
||||
else
|
||||
return null
|
||||
}
|
||||
|
||||
override getProjects() {
|
||||
return #{projectConfig}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,58 +11,61 @@ import org.eclipse.emf.common.util.URI
|
|||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
|
||||
import static extension org.eclipse.xtext.util.UriUtil.*
|
||||
/**
|
||||
* The default workspace consists of multiple projects and always contains the unknown project that is used for projectless files.
|
||||
*
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class WorkspaceConfig implements IWorkspaceConfig {
|
||||
|
||||
@FinalFieldsConstructor
|
||||
class InMemoryWorkspaceConfig implements IWorkspaceConfig {
|
||||
|
||||
val IProjectConfig projectConfig
|
||||
|
||||
override findProjectByName(String name) {
|
||||
if (projectConfig.name == name)
|
||||
return projectConfig
|
||||
else
|
||||
return null
|
||||
val unknown = new UnknownProjectConfig(this)
|
||||
val projects = <String, IProjectConfig>newHashMap
|
||||
|
||||
new(IProjectConfig... initialProjects) {
|
||||
addProject(unknown)
|
||||
initialProjects.forEach[addProject]
|
||||
}
|
||||
|
||||
override findProjectContaining(URI member) {
|
||||
if (projectConfig.path.isPrefixOf(member))
|
||||
return projectConfig
|
||||
else
|
||||
return new InMemoryProjectConfig(member.trimFragment.trimQuery.trimSegments(1))
|
||||
}
|
||||
|
||||
|
||||
override getProjects() {
|
||||
#{projectConfig}
|
||||
projects.values.toSet
|
||||
}
|
||||
|
||||
def void addProject(IProjectConfig project) {
|
||||
projects.put(project.name, project)
|
||||
}
|
||||
|
||||
override findProjectByName(String name) {
|
||||
projects.get(name)
|
||||
}
|
||||
|
||||
override findProjectContaining(URI member) {
|
||||
val candidates = projects.values.filter [
|
||||
findSourceFolderContaining(member) !== null
|
||||
]
|
||||
if (!candidates.empty)
|
||||
return candidates.maxBy[path.segmentCount]
|
||||
else
|
||||
return unknown
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Accessors
|
||||
class InMemoryProjectConfig implements IProjectConfig {
|
||||
|
||||
val URI path
|
||||
|
||||
@FinalFieldsConstructor
|
||||
class UnknownProjectConfig implements IProjectConfig {
|
||||
|
||||
val String name = '__unknown_project'
|
||||
val IWorkspaceConfig workspaceConfig
|
||||
|
||||
String name = 'inmemory'
|
||||
|
||||
new() {
|
||||
this(URI.createURI('inmemory:/'))
|
||||
}
|
||||
|
||||
new(URI path) {
|
||||
this.path = path
|
||||
this.workspaceConfig = new InMemoryWorkspaceConfig(this)
|
||||
}
|
||||
|
||||
override getSourceFolders() {
|
||||
emptySet
|
||||
}
|
||||
|
||||
|
||||
override findSourceFolderContaining(URI member) {
|
||||
null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override getPath() {
|
||||
null
|
||||
}
|
||||
|
||||
override getSourceFolders() {
|
||||
emptySet
|
||||
}
|
||||
|
||||
}
|
|
@ -11,16 +11,19 @@ import com.google.common.base.Objects;
|
|||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.FileSourceFolder;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.SingleProjectWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public class FileProjectConfig implements IProjectConfig {
|
||||
private final URI path;
|
||||
|
@ -29,21 +32,47 @@ public class FileProjectConfig implements IProjectConfig {
|
|||
|
||||
private final Set<FileSourceFolder> sourceFolders = CollectionLiterals.<FileSourceFolder>newHashSet();
|
||||
|
||||
private final IWorkspaceConfig workspaceConfig;
|
||||
|
||||
public FileProjectConfig(final URI path) {
|
||||
this(path, path.lastSegment());
|
||||
this(path, ((IWorkspaceConfig) null));
|
||||
}
|
||||
|
||||
public FileProjectConfig(final URI path, final String name) {
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this(path, name, ((IWorkspaceConfig) null));
|
||||
}
|
||||
|
||||
public FileProjectConfig(final File root, final String name) {
|
||||
this(UriUtil.createFolderURI(root), name);
|
||||
this(root, name, ((IWorkspaceConfig) null));
|
||||
}
|
||||
|
||||
public FileProjectConfig(final File root) {
|
||||
this(UriUtil.createFolderURI(root), root.getName());
|
||||
this(root, ((IWorkspaceConfig) null));
|
||||
}
|
||||
|
||||
public FileProjectConfig(final URI path, final IWorkspaceConfig workspaceConfig) {
|
||||
this(path, path.lastSegment(), workspaceConfig);
|
||||
}
|
||||
|
||||
public FileProjectConfig(final URI path, final String name, final IWorkspaceConfig workspaceConfig) {
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
IWorkspaceConfig _elvis = null;
|
||||
if (workspaceConfig != null) {
|
||||
_elvis = workspaceConfig;
|
||||
} else {
|
||||
WorkspaceConfig _workspaceConfig = new WorkspaceConfig(this);
|
||||
_elvis = _workspaceConfig;
|
||||
}
|
||||
this.workspaceConfig = _elvis;
|
||||
}
|
||||
|
||||
public FileProjectConfig(final File root, final String name, final IWorkspaceConfig workspaceConfig) {
|
||||
this(UriUtil.createFolderURI(root), name, workspaceConfig);
|
||||
}
|
||||
|
||||
public FileProjectConfig(final File root, final IWorkspaceConfig workspaceConfig) {
|
||||
this(UriUtil.createFolderURI(root), root.getName(), workspaceConfig);
|
||||
}
|
||||
|
||||
public FileSourceFolder addSourceFolder(final String relativePath) {
|
||||
|
@ -64,21 +93,6 @@ public class FileProjectConfig implements IProjectConfig {
|
|||
return IterableExtensions.<FileSourceFolder>findFirst(this.sourceFolders, _function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<FileSourceFolder> getSourceFolders() {
|
||||
return this.sourceFolders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if ((obj instanceof FileProjectConfig)) {
|
||||
|
@ -103,8 +117,23 @@ public class FileProjectConfig implements IProjectConfig {
|
|||
return _builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Set<FileSourceFolder> getSourceFolders() {
|
||||
return this.sourceFolders;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return new SingleProjectWorkspaceConfig(this);
|
||||
return this.workspaceConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.workspace;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.InMemoryProjectConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class InMemoryWorkspaceConfig implements IWorkspaceConfig {
|
||||
private final IProjectConfig projectConfig;
|
||||
|
||||
@Override
|
||||
public IProjectConfig findProjectByName(final String name) {
|
||||
String _name = this.projectConfig.getName();
|
||||
boolean _equals = Objects.equal(_name, name);
|
||||
if (_equals) {
|
||||
return this.projectConfig;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProjectConfig findProjectContaining(final URI member) {
|
||||
boolean _isPrefixOf = UriUtil.isPrefixOf(this.projectConfig.getPath(), member);
|
||||
if (_isPrefixOf) {
|
||||
return this.projectConfig;
|
||||
} else {
|
||||
URI _trimSegments = member.trimFragment().trimQuery().trimSegments(1);
|
||||
return new InMemoryProjectConfig(_trimSegments);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends IProjectConfig> getProjects() {
|
||||
return Collections.<IProjectConfig>unmodifiableSet(CollectionLiterals.<IProjectConfig>newHashSet(this.projectConfig));
|
||||
}
|
||||
|
||||
public InMemoryWorkspaceConfig(final IProjectConfig projectConfig) {
|
||||
super();
|
||||
this.projectConfig = projectConfig;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.workspace;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.Data;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
@Data
|
||||
@SuppressWarnings("all")
|
||||
public class SingleProjectWorkspaceConfig implements IWorkspaceConfig {
|
||||
private final IProjectConfig projectConfig;
|
||||
|
||||
@Override
|
||||
public IProjectConfig findProjectByName(final String name) {
|
||||
String _name = this.projectConfig.getName();
|
||||
boolean _equals = Objects.equal(_name, name);
|
||||
if (_equals) {
|
||||
return this.projectConfig;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProjectConfig findProjectContaining(final URI member) {
|
||||
boolean _isPrefixOf = UriUtil.isPrefixOf(this.projectConfig.getPath(), member);
|
||||
if (_isPrefixOf) {
|
||||
return this.projectConfig;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends IProjectConfig> getProjects() {
|
||||
return Collections.<IProjectConfig>unmodifiableSet(CollectionLiterals.<IProjectConfig>newHashSet(this.projectConfig));
|
||||
}
|
||||
|
||||
public SingleProjectWorkspaceConfig(final IProjectConfig projectConfig) {
|
||||
super();
|
||||
this.projectConfig = projectConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.projectConfig== null) ? 0 : this.projectConfig.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SingleProjectWorkspaceConfig other = (SingleProjectWorkspaceConfig) obj;
|
||||
if (this.projectConfig == null) {
|
||||
if (other.projectConfig != null)
|
||||
return false;
|
||||
} else if (!this.projectConfig.equals(other.projectConfig))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.add("projectConfig", this.projectConfig);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IProjectConfig getProjectConfig() {
|
||||
return this.projectConfig;
|
||||
}
|
||||
}
|
|
@ -10,30 +10,29 @@ package org.eclipse.xtext.workspace;
|
|||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.InMemoryWorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
@Accessors
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class InMemoryProjectConfig implements IProjectConfig {
|
||||
private final URI path;
|
||||
public class UnknownProjectConfig implements IProjectConfig {
|
||||
private final String name = "__unknown_project";
|
||||
|
||||
private final IWorkspaceConfig workspaceConfig;
|
||||
|
||||
private String name = "inmemory";
|
||||
|
||||
public InMemoryProjectConfig() {
|
||||
this(URI.createURI("inmemory:/"));
|
||||
@Override
|
||||
public ISourceFolder findSourceFolderContaining(final URI member) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public InMemoryProjectConfig(final URI path) {
|
||||
this.path = path;
|
||||
InMemoryWorkspaceConfig _inMemoryWorkspaceConfig = new InMemoryWorkspaceConfig(this);
|
||||
this.workspaceConfig = _inMemoryWorkspaceConfig;
|
||||
@Override
|
||||
public URI getPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,19 +40,9 @@ public class InMemoryProjectConfig implements IProjectConfig {
|
|||
return CollectionLiterals.<ISourceFolder>emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceFolder findSourceFolderContaining(final URI member) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return this.workspaceConfig;
|
||||
public UnknownProjectConfig(final IWorkspaceConfig workspaceConfig) {
|
||||
super();
|
||||
this.workspaceConfig = workspaceConfig;
|
||||
}
|
||||
|
||||
@Pure
|
||||
|
@ -61,7 +50,8 @@ public class InMemoryProjectConfig implements IProjectConfig {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
@Pure
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return this.workspaceConfig;
|
||||
}
|
||||
}
|
|
@ -1,38 +1,57 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.ide.server;
|
||||
package org.eclipse.xtext.workspace;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.UnknownProjectConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
/**
|
||||
* The default workspace consists of multiple projects and always contains the unknown project that is used for projectless files.
|
||||
*
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class MultiProjectWorkspaceConfig implements IWorkspaceConfig {
|
||||
private final Map<String, IProjectConfig> name2config;
|
||||
public class WorkspaceConfig implements IWorkspaceConfig {
|
||||
private final UnknownProjectConfig unknown = new UnknownProjectConfig(this);
|
||||
|
||||
private final HashMap<String, IProjectConfig> projects = CollectionLiterals.<String, IProjectConfig>newHashMap();
|
||||
|
||||
public WorkspaceConfig(final IProjectConfig... initialProjects) {
|
||||
this.addProject(this.unknown);
|
||||
final Consumer<IProjectConfig> _function = (IProjectConfig it) -> {
|
||||
this.addProject(it);
|
||||
};
|
||||
((List<IProjectConfig>)Conversions.doWrapArray(initialProjects)).forEach(_function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends IProjectConfig> getProjects() {
|
||||
Collection<IProjectConfig> _values = this.name2config.values();
|
||||
return new HashSet<IProjectConfig>(_values);
|
||||
return IterableExtensions.<IProjectConfig>toSet(this.projects.values());
|
||||
}
|
||||
|
||||
public void addProject(final IProjectConfig project) {
|
||||
this.projects.put(project.getName(), project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProjectConfig findProjectByName(final String name) {
|
||||
return this.name2config.get(name);
|
||||
return this.projects.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +60,7 @@ public class MultiProjectWorkspaceConfig implements IWorkspaceConfig {
|
|||
ISourceFolder _findSourceFolderContaining = it.findSourceFolderContaining(member);
|
||||
return Boolean.valueOf((_findSourceFolderContaining != null));
|
||||
};
|
||||
final Iterable<IProjectConfig> candidates = IterableExtensions.<IProjectConfig>filter(this.name2config.values(), _function);
|
||||
final Iterable<IProjectConfig> candidates = IterableExtensions.<IProjectConfig>filter(this.projects.values(), _function);
|
||||
boolean _isEmpty = IterableExtensions.isEmpty(candidates);
|
||||
boolean _not = (!_isEmpty);
|
||||
if (_not) {
|
||||
|
@ -50,12 +69,7 @@ public class MultiProjectWorkspaceConfig implements IWorkspaceConfig {
|
|||
};
|
||||
return IterableExtensions.<IProjectConfig, Integer>maxBy(candidates, _function_1);
|
||||
} else {
|
||||
return null;
|
||||
return this.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public MultiProjectWorkspaceConfig(final Map<String, IProjectConfig> name2config) {
|
||||
super();
|
||||
this.name2config = name2config;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue