mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
[ls] recompute workspace config on configuration change + fixes for build
This commit is contained in:
parent
c6f66ccf84
commit
29fe693b9f
13 changed files with 132 additions and 83 deletions
|
@ -10,6 +10,11 @@
|
|||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src-gen">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="testlang-src">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
|
|
|
@ -52,6 +52,15 @@ class BuildOrderTest {
|
|||
]))
|
||||
}
|
||||
|
||||
@Test
|
||||
def testJustOne() {
|
||||
val a = new ProjectDescription => [ name = 'a' dependencies=#['b'] ]
|
||||
val b = new ProjectDescription => [ name = 'b' ]
|
||||
assertEquals(#[a], new TopologicalSorter().sortByDependencies(#[a], [fail]))
|
||||
assertEquals(#[b], new TopologicalSorter().sortByDependencies(#[b], [fail]))
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
def testCycle() {
|
||||
val a = new ProjectDescription => [ name = 'a' dependencies=#['b', 'c'] ]
|
||||
|
@ -72,15 +81,6 @@ class BuildOrderTest {
|
|||
assertEquals(#[a], cyclic)
|
||||
}
|
||||
|
||||
@Test
|
||||
def testCycle2() {
|
||||
val a = new ProjectDescription => [ name = 'a' dependencies=#['b'] ]
|
||||
val b = new ProjectDescription => [ name = 'b' dependencies=#['a'] ]
|
||||
val cyclic = newArrayList
|
||||
assertEquals(#[], new TopologicalSorter().sortByDependencies(#[a,b], [cyclic.add(it)]))
|
||||
assertEquals(#[a,b], cyclic)
|
||||
}
|
||||
|
||||
def assertEquals(List<ProjectDescription> expected, List<ProjectDescription> actual) {
|
||||
assertEquals('''Expected: «expected.asString» but was «actual.asString»''', expected, actual)
|
||||
}
|
||||
|
|
|
@ -129,6 +129,33 @@ public class BuildOrderTest {
|
|||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(d, c, b, a)), _sortByDependencies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJustOne() {
|
||||
ProjectDescription _projectDescription = new ProjectDescription();
|
||||
final Procedure1<ProjectDescription> _function = (ProjectDescription it) -> {
|
||||
it.setName("a");
|
||||
it.setDependencies(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("b")));
|
||||
};
|
||||
final ProjectDescription a = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function);
|
||||
ProjectDescription _projectDescription_1 = new ProjectDescription();
|
||||
final Procedure1<ProjectDescription> _function_1 = (ProjectDescription it) -> {
|
||||
it.setName("b");
|
||||
};
|
||||
final ProjectDescription b = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription_1, _function_1);
|
||||
TopologicalSorter _topologicalSorter = new TopologicalSorter();
|
||||
final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it) -> {
|
||||
Assert.fail();
|
||||
};
|
||||
List<ProjectDescription> _sortByDependencies = _topologicalSorter.sortByDependencies(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(a)), _function_2);
|
||||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(a)), _sortByDependencies);
|
||||
TopologicalSorter _topologicalSorter_1 = new TopologicalSorter();
|
||||
final Procedure1<ProjectDescription> _function_3 = (ProjectDescription it) -> {
|
||||
Assert.fail();
|
||||
};
|
||||
List<ProjectDescription> _sortByDependencies_1 = _topologicalSorter_1.sortByDependencies(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(b)), _function_3);
|
||||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(b)), _sortByDependencies_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCycle() {
|
||||
ProjectDescription _projectDescription = new ProjectDescription();
|
||||
|
@ -189,30 +216,6 @@ public class BuildOrderTest {
|
|||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(a)), cyclic);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCycle2() {
|
||||
ProjectDescription _projectDescription = new ProjectDescription();
|
||||
final Procedure1<ProjectDescription> _function = (ProjectDescription it) -> {
|
||||
it.setName("a");
|
||||
it.setDependencies(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("b")));
|
||||
};
|
||||
final ProjectDescription a = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function);
|
||||
ProjectDescription _projectDescription_1 = new ProjectDescription();
|
||||
final Procedure1<ProjectDescription> _function_1 = (ProjectDescription it) -> {
|
||||
it.setName("b");
|
||||
it.setDependencies(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("a")));
|
||||
};
|
||||
final ProjectDescription b = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription_1, _function_1);
|
||||
final ArrayList<ProjectDescription> cyclic = CollectionLiterals.<ProjectDescription>newArrayList();
|
||||
TopologicalSorter _topologicalSorter = new TopologicalSorter();
|
||||
final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it) -> {
|
||||
cyclic.add(it);
|
||||
};
|
||||
List<ProjectDescription> _sortByDependencies = _topologicalSorter.sortByDependencies(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(a, b)), _function_2);
|
||||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList()), _sortByDependencies);
|
||||
this.assertEquals(Collections.<ProjectDescription>unmodifiableList(CollectionLiterals.<ProjectDescription>newArrayList(a, b)), cyclic);
|
||||
}
|
||||
|
||||
public void assertEquals(final List<ProjectDescription> expected, final List<ProjectDescription> actual) {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Expected: ");
|
||||
|
|
|
@ -47,10 +47,10 @@ class BuildManager {
|
|||
files += toAdd
|
||||
}
|
||||
|
||||
def void doFullBuild(CancelIndicator indicator) {
|
||||
val sortedDescriptions = sortByDependencies(workspaceManager.projectManagers.map[projectDescription])
|
||||
def void doInitialBuild(List<ProjectDescription> projects, CancelIndicator indicator) {
|
||||
val sortedDescriptions = sortByDependencies(projects)
|
||||
for(it: sortedDescriptions) {
|
||||
workspaceManager.getProjectManager(name).doFullBuild(indicator)
|
||||
workspaceManager.getProjectManager(name).doInitialBuild(indicator)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,12 @@ import static extension io.typefox.lsapi.util.LsapiFactories.*
|
|||
workspaceManager.doBuild(dirtyFiles, deletedFiles, cancelIndicator)
|
||||
]
|
||||
}
|
||||
|
||||
override didChangeConfiguraton(DidChangeConfigurationParams params) {
|
||||
requestManager.runWrite [ cancelIndicator |
|
||||
workspaceManager.refreshWorkspaceConfig(cancelIndicator)
|
||||
]
|
||||
}
|
||||
|
||||
// end file/content change events
|
||||
// validation stuff
|
||||
|
@ -397,10 +403,6 @@ import static extension io.typefox.lsapi.util.LsapiFactories.*
|
|||
|
||||
// end hover
|
||||
|
||||
override didChangeConfiguraton(DidChangeConfigurationParams params) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
||||
override resolveCompletionItem(CompletionItem unresolved) {
|
||||
return CompletableFuture.completedFuture(unresolved)
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class ProjectManager {
|
|||
this.indexProvider = indexProvider
|
||||
}
|
||||
|
||||
def Result doFullBuild(CancelIndicator cancelIndicator) {
|
||||
def Result doInitialBuild(CancelIndicator cancelIndicator) {
|
||||
val uris = newArrayList
|
||||
projectConfig.sourceFolders.forEach [
|
||||
fileSystemScanner.scan(path) [uris += it]
|
||||
|
|
|
@ -42,7 +42,8 @@ class TopologicalSorter {
|
|||
}
|
||||
current.marked = true
|
||||
for(it: current.description.dependencies) {
|
||||
if(!name2entry.get(it)?.visit) {
|
||||
val depEntry = name2entry.get(it)
|
||||
if(depEntry != null && !depEntry.visit) {
|
||||
current.markCyclic
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -37,8 +37,9 @@ class WorkspaceManager {
|
|||
Map<String, ProjectManager> projectName2ProjectManager = newHashMap
|
||||
|
||||
URI baseDir
|
||||
(URI, Iterable<Issue>)=>void issueAcceptor
|
||||
IWorkspaceConfig workspaceConfig
|
||||
|
||||
|
||||
Map<String, ResourceDescriptionsData> fullIndex = newHashMap()
|
||||
|
||||
Map<URI, Document> openDocuments = newHashMap()
|
||||
|
@ -57,16 +58,32 @@ class WorkspaceManager {
|
|||
}
|
||||
};
|
||||
|
||||
def void initialize(URI baseDir, (URI, Iterable<Issue>)=>void acceptor, CancelIndicator cancelIndicator) {
|
||||
def void initialize(URI baseDir, (URI, Iterable<Issue>)=>void issueAcceptor, CancelIndicator cancelIndicator) {
|
||||
this.baseDir = baseDir
|
||||
this.issueAcceptor = issueAcceptor
|
||||
refreshWorkspaceConfig(cancelIndicator)
|
||||
}
|
||||
|
||||
protected def refreshWorkspaceConfig(CancelIndicator cancelIndicator) {
|
||||
workspaceConfig = workspaceConfigFactory.getWorkspaceConfig(baseDir)
|
||||
val newProjects = newArrayList
|
||||
val remainingProjectNames = newHashSet(projectName2ProjectManager.keySet)
|
||||
workspaceConfig.projects.forEach [ projectConfig |
|
||||
val projectManager = projectManagerProvider.get
|
||||
val projectDescription = projectDescriptionFactory.getProjectDescription(projectConfig)
|
||||
projectManager.initialize(projectDescription, projectConfig, acceptor, openedDocumentsContentProvider, [fullIndex], cancelIndicator)
|
||||
projectName2ProjectManager.put(projectDescription.name, projectManager)
|
||||
if(projectName2ProjectManager.containsKey(projectConfig.name)) {
|
||||
remainingProjectNames.remove(projectConfig.name)
|
||||
} else {
|
||||
val projectManager = projectManagerProvider.get
|
||||
val projectDescription = projectDescriptionFactory.getProjectDescription(projectConfig)
|
||||
projectManager.initialize(projectDescription, projectConfig, issueAcceptor, openedDocumentsContentProvider, [fullIndex], cancelIndicator)
|
||||
projectName2ProjectManager.put(projectDescription.name, projectManager)
|
||||
newProjects.add(projectDescription)
|
||||
}
|
||||
]
|
||||
buildManager.doFullBuild(cancelIndicator)
|
||||
for(deletedProject: remainingProjectNames) {
|
||||
projectName2ProjectManager.remove(deletedProject)
|
||||
fullIndex.remove(deletedProject)
|
||||
}
|
||||
buildManager.doInitialBuild(newProjects, cancelIndicator)
|
||||
}
|
||||
|
||||
def void doBuild(List<URI> dirtyFiles, List<URI> deletedFiles, CancelIndicator cancelIndicator) {
|
||||
|
|
|
@ -130,17 +130,12 @@ public class BuildManager {
|
|||
Iterables.<URI>addAll(files, toAdd);
|
||||
}
|
||||
|
||||
public void doFullBuild(final CancelIndicator indicator) {
|
||||
List<ProjectManager> _projectManagers = this.workspaceManager.getProjectManagers();
|
||||
final Function1<ProjectManager, ProjectDescription> _function = (ProjectManager it) -> {
|
||||
return it.getProjectDescription();
|
||||
};
|
||||
List<ProjectDescription> _map = ListExtensions.<ProjectManager, ProjectDescription>map(_projectManagers, _function);
|
||||
final List<ProjectDescription> sortedDescriptions = this.sortByDependencies(_map);
|
||||
public void doInitialBuild(final List<ProjectDescription> projects, final CancelIndicator indicator) {
|
||||
final List<ProjectDescription> sortedDescriptions = this.sortByDependencies(projects);
|
||||
for (final ProjectDescription it : sortedDescriptions) {
|
||||
String _name = it.getName();
|
||||
ProjectManager _projectManager = this.workspaceManager.getProjectManager(_name);
|
||||
_projectManager.doFullBuild(indicator);
|
||||
_projectManager.doInitialBuild(indicator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -336,6 +336,14 @@ public class LanguageServerImpl implements LanguageServer, WorkspaceService, Win
|
|||
this.requestManager.runWrite(_function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didChangeConfiguraton(final DidChangeConfigurationParams params) {
|
||||
final Procedure1<CancelIndicator> _function = (CancelIndicator cancelIndicator) -> {
|
||||
this.workspaceManager.refreshWorkspaceConfig(cancelIndicator);
|
||||
};
|
||||
this.requestManager.runWrite(_function);
|
||||
}
|
||||
|
||||
private List<Consumer<PublishDiagnosticsParams>> diagnosticListeners = CollectionLiterals.<Consumer<PublishDiagnosticsParams>>newArrayList();
|
||||
|
||||
private WorkspaceResourceAccess resourceAccess;
|
||||
|
@ -673,11 +681,6 @@ public class LanguageServerImpl implements LanguageServer, WorkspaceService, Win
|
|||
return this.requestManager.<Hover>runRead(_function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didChangeConfiguraton(final DidChangeConfigurationParams params) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CompletionItem> resolveCompletionItem(final CompletionItem unresolved) {
|
||||
return CompletableFuture.<CompletionItem>completedFuture(unresolved);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ProjectManager {
|
|||
this.indexProvider = indexProvider;
|
||||
}
|
||||
|
||||
public IncrementalBuilder.Result doFullBuild(final CancelIndicator cancelIndicator) {
|
||||
public IncrementalBuilder.Result doInitialBuild(final CancelIndicator cancelIndicator) {
|
||||
final ArrayList<URI> uris = CollectionLiterals.<URI>newArrayList();
|
||||
Set<? extends ISourceFolder> _sourceFolders = this.projectConfig.getSourceFolders();
|
||||
final Consumer<ISourceFolder> _function = (ISourceFolder it) -> {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
package org.eclipse.xtext.ide.server;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
@ -89,15 +90,12 @@ public class TopologicalSorter {
|
|||
current.marked = true;
|
||||
List<String> _dependencies = current.description.getDependencies();
|
||||
for (final String it : _dependencies) {
|
||||
TopologicalSorter.Entry _get = this.name2entry.get(it);
|
||||
boolean _visit = false;
|
||||
if (_get!=null) {
|
||||
_visit=this.visit(_get);
|
||||
}
|
||||
boolean _not = (!_visit);
|
||||
if (_not) {
|
||||
this.markCyclic(current);
|
||||
return false;
|
||||
{
|
||||
final TopologicalSorter.Entry depEntry = this.name2entry.get(it);
|
||||
if (((!Objects.equal(depEntry, null)) && (!this.visit(depEntry)))) {
|
||||
this.markCyclic(current);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
current.marked = false;
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.typefox.lsapi.TextEdit;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -60,6 +61,8 @@ public class WorkspaceManager {
|
|||
|
||||
private URI baseDir;
|
||||
|
||||
private Procedure2<? super URI, ? super Iterable<Issue>> issueAcceptor;
|
||||
|
||||
private IWorkspaceConfig workspaceConfig;
|
||||
|
||||
private Map<String, ResourceDescriptionsData> fullIndex = CollectionLiterals.<String, ResourceDescriptionsData>newHashMap();
|
||||
|
@ -88,23 +91,45 @@ public class WorkspaceManager {
|
|||
}
|
||||
};
|
||||
|
||||
public void initialize(final URI baseDir, final Procedure2<? super URI, ? super Iterable<Issue>> acceptor, final CancelIndicator cancelIndicator) {
|
||||
public void initialize(final URI baseDir, final Procedure2<? super URI, ? super Iterable<Issue>> issueAcceptor, final CancelIndicator cancelIndicator) {
|
||||
this.baseDir = baseDir;
|
||||
IWorkspaceConfig _workspaceConfig = this.workspaceConfigFactory.getWorkspaceConfig(baseDir);
|
||||
this.issueAcceptor = issueAcceptor;
|
||||
this.refreshWorkspaceConfig(cancelIndicator);
|
||||
}
|
||||
|
||||
protected void refreshWorkspaceConfig(final CancelIndicator cancelIndicator) {
|
||||
IWorkspaceConfig _workspaceConfig = this.workspaceConfigFactory.getWorkspaceConfig(this.baseDir);
|
||||
this.workspaceConfig = _workspaceConfig;
|
||||
final ArrayList<ProjectDescription> newProjects = CollectionLiterals.<ProjectDescription>newArrayList();
|
||||
Set<String> _keySet = this.projectName2ProjectManager.keySet();
|
||||
final HashSet<Set<String>> remainingProjectNames = CollectionLiterals.<Set<String>>newHashSet(_keySet);
|
||||
Set<? extends IProjectConfig> _projects = this.workspaceConfig.getProjects();
|
||||
final Consumer<IProjectConfig> _function = (IProjectConfig projectConfig) -> {
|
||||
final ProjectManager projectManager = this.projectManagerProvider.get();
|
||||
final ProjectDescription projectDescription = this.projectDescriptionFactory.getProjectDescription(projectConfig);
|
||||
final Provider<Map<String, ResourceDescriptionsData>> _function_1 = () -> {
|
||||
return this.fullIndex;
|
||||
};
|
||||
projectManager.initialize(projectDescription, projectConfig, acceptor, this.openedDocumentsContentProvider, _function_1, cancelIndicator);
|
||||
String _name = projectDescription.getName();
|
||||
this.projectName2ProjectManager.put(_name, projectManager);
|
||||
String _name = projectConfig.getName();
|
||||
boolean _containsKey = this.projectName2ProjectManager.containsKey(_name);
|
||||
if (_containsKey) {
|
||||
String _name_1 = projectConfig.getName();
|
||||
remainingProjectNames.remove(_name_1);
|
||||
} else {
|
||||
final ProjectManager projectManager = this.projectManagerProvider.get();
|
||||
final ProjectDescription projectDescription = this.projectDescriptionFactory.getProjectDescription(projectConfig);
|
||||
final Provider<Map<String, ResourceDescriptionsData>> _function_1 = () -> {
|
||||
return this.fullIndex;
|
||||
};
|
||||
projectManager.initialize(projectDescription, projectConfig, this.issueAcceptor, this.openedDocumentsContentProvider, _function_1, cancelIndicator);
|
||||
String _name_2 = projectDescription.getName();
|
||||
this.projectName2ProjectManager.put(_name_2, projectManager);
|
||||
newProjects.add(projectDescription);
|
||||
}
|
||||
};
|
||||
_projects.forEach(_function);
|
||||
this.buildManager.doFullBuild(cancelIndicator);
|
||||
for (final Set<String> deletedProject : remainingProjectNames) {
|
||||
{
|
||||
this.projectName2ProjectManager.remove(deletedProject);
|
||||
this.fullIndex.remove(deletedProject);
|
||||
}
|
||||
}
|
||||
this.buildManager.doInitialBuild(newProjects, cancelIndicator);
|
||||
}
|
||||
|
||||
public void doBuild(final List<URI> dirtyFiles, final List<URI> deletedFiles, final CancelIndicator cancelIndicator) {
|
||||
|
|
Loading…
Reference in a new issue