use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class ResourceTaskContext method updateIndex.
/**
* Update this context's internal index and trigger a refresh if required.
*/
protected void updateIndex(Collection<? extends IResourceDescription> changedDescs, Set<URI> removedURIs, WorkspaceConfigSnapshot newWorkspaceConfig, CancelIndicator cancelIndicator) {
WorkspaceConfigSnapshot oldWorkspaceConfig = workspaceConfig;
// update my cached state
List<IResourceDescription.Delta> allDeltas = createDeltas(changedDescs, removedURIs);
for (IResourceDescription.Delta delta : allDeltas) {
URI deltaURI = delta.getUri();
WorkspaceConfigSnapshot wcs = delta.getNew() != null ? newWorkspaceConfig : oldWorkspaceConfig;
ProjectConfigSnapshot project = wcs != null ? wcs.findProjectContaining(deltaURI) : null;
if (project != null) {
indexSnapshot.register(project.getName(), delta);
}
}
workspaceConfig = newWorkspaceConfig;
boolean workspaceConfigChanged = workspaceConfig != null ? !workspaceConfig.equals(oldWorkspaceConfig) : oldWorkspaceConfig != null;
if (workspaceConfigChanged) {
WorkspaceConfigAdapter.installWorkspaceConfig(mainResourceSet, workspaceConfig);
}
// refresh if I am affected by the changes
boolean isAffected = workspaceConfigChanged;
if (!isAffected) {
IResourceDescription.Manager rdm = getResourceDescriptionManager(mainURI);
IResourceDescription candidateDesc = indexSnapshot.getResourceDescription(mainURI);
if (rdm != null && candidateDesc != null) {
isAffected = isAffected(candidateDesc, rdm, allDeltas);
}
}
if (isAffected) {
refreshContext(cancelIndicator);
}
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class ResourceTaskManager method updatePersistedState.
/**
* Updates this manager and all its {@link ResourceTaskContext}s with the given changes to the persisted state
* index. Should be invoked from the outside whenever changes to the persisted state become available, e.g. because
* the {@link BuilderFrontend builder} has rebuilt some files.
*/
public synchronized void updatePersistedState(WorkspaceConfigSnapshot newWorkspaceConfig, Map<String, ? extends ResourceDescriptionsData> changedDescriptions, @SuppressWarnings("unused") List<? extends ProjectConfigSnapshot> changedProjects, Set<String> removedProjects) {
WorkspaceConfigSnapshot oldWC = workspaceConfig;
// compute "flat" modification info (not per project but on a global URI->description basis)
List<IResourceDescription> changed = new ArrayList<>();
Set<URI> removed = new HashSet<>();
for (Entry<String, ? extends ResourceDescriptionsData> entry : changedDescriptions.entrySet()) {
String projectName = entry.getKey();
ResourceDescriptionsData newData = entry.getValue();
ResourceDescriptionsData oldData = persistedIndex.getContainer(projectName);
if (oldData != null) {
removed.addAll(oldData.getAllURIs());
}
for (IResourceDescription desc : newData.getAllResourceDescriptions()) {
URI descURI = desc.getURI();
changed.add(desc);
removed.remove(descURI);
}
}
// update my internal state
for (String removedProject : removedProjects) {
persistedIndex.removeContainer(removedProject);
}
for (Entry<String, ? extends ResourceDescriptionsData> entry : changedDescriptions.entrySet()) {
persistedIndex.setContainer(entry.getKey(), entry.getValue());
}
workspaceConfig = newWorkspaceConfig;
// from this point forward: ignore changes/removals related to existing resource task contexts
changed.removeIf(desc -> uri2RTCsOnQueue.containsKey(desc.getURI()));
removed.removeAll(uri2RTCsOnQueue.keySet());
// update internal state of all contexts
if (Iterables.isEmpty(changed) && removed.isEmpty() && workspaceConfig.equals(oldWC)) {
return;
}
WorkspaceConfigSnapshot capturedWorkspaceConfig = workspaceConfig;
for (URI currURI : uri2RTCsOnQueue.keySet()) {
runInExistingContextVoid(currURI, "updatePersistedState of existing context", (rtc, ci) -> {
rtc.onPersistedStateChanged(changed, removed, capturedWorkspaceConfig, ci);
});
}
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class BuilderFrontend method didChangeWatchedFiles.
/**
* Trigger an incremental build in the background when files change on disk.
*/
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
List<URI> dirtyFiles = new ArrayList<>();
List<URI> deletedFiles = new ArrayList<>();
WorkspaceConfigSnapshot workspaceConfig = concurrentIndex.getWorkspaceConfigSnapshot();
for (FileEvent fileEvent : params.getChanges()) {
URI uri = paramHelper.getURI(fileEvent);
if (!isSourceFile(workspaceConfig, uri)) {
continue;
}
FileChangeType changeType = fileEvent.getType();
if (changeType == FileChangeType.Deleted) {
deletedFiles.add(uri);
} else {
dirtyFiles.add(uri);
}
}
if (!dirtyFiles.isEmpty() || !deletedFiles.isEmpty()) {
asyncRunBuildTask("didChangeWatchedFiles", () -> workspaceBuilder.createIncrementalBuildTask(dirtyFiles, deletedFiles, false));
}
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class XWorkspaceManager method applyWorkspaceChanges.
/**
* Apply the given workspace changes to this manager's internal state and notify the workspace index.
*/
protected UpdateResult applyWorkspaceChanges(WorkspaceChanges changes) {
// collects contents of removed projects before actually removing anything
List<IResourceDescription> removedProjectsContents = collectAllResourceDescriptions(changes.getRemovedProjects());
removeProjects(changes.getRemovedProjects());
updateProjects(changes.getChangedProjects());
addProjects(changes.getAddedProjects());
WorkspaceConfigSnapshot oldWCS = workspaceConfigSnapshot;
Collection<ImmutableList<String>> oldCycles = oldWCS.getBuildOrderInfo().getProjectCycles();
workspaceConfigSnapshot = workspaceIndex.changeOrRemoveProjects(Iterables.concat(changes.getAddedProjects(), changes.getChangedProjects()), Iterables.transform(changes.getRemovedProjects(), ProjectConfigSnapshot::getName));
Collection<ImmutableList<String>> newCycles = workspaceConfigSnapshot.getBuildOrderInfo().getProjectCycles();
Set<String> cyclicProjectChanges = new HashSet<>();
for (List<String> cycle : Iterables.concat(oldCycles, newCycles)) {
for (String projectName : cycle) {
cyclicProjectChanges.add(projectName);
}
}
return new UpdateResult(oldWCS, changes, removedProjectsContents, cyclicProjectChanges);
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class XWorkspaceBuilder method doInitialBuild.
/**
* Run a full build on the entire workspace, i.e. build all projects.
*
* @return the delta.
*/
private IResourceDescription.Event doInitialBuild() {
lspLogger.log("Initial build ...");
Stopwatch stopwatch = Stopwatch.createStarted();
WorkspaceConfigSnapshot workspaceConfig = workspaceManager.getWorkspaceConfig();
boolean hasDependencyCycle = workspaceConfig.hasDependencyCycle();
try {
Collection<? extends ProjectConfigSnapshot> allProjects = workspaceManager.getProjectConfigs();
BuildOrderIterator pboIterator = buildOrderFactory.createBuildOrderIterator(workspaceConfig, allProjects);
logBuildOrder(workspaceConfig);
List<IResourceDescription.Delta> allDeltas = new ArrayList<>();
while (pboIterator.hasNext()) {
ProjectConfigSnapshot projectConfig = pboIterator.next();
String projectID = projectConfig.getName();
ProjectBuilder projectBuilder = workspaceManager.getProjectBuilder(projectID);
XBuildResult partialresult = projectBuilder.doInitialBuild(buildRequestFactory, allDeltas);
allDeltas.addAll(partialresult.getAffectedResources());
}
onBuildDone(true, false, hasDependencyCycle, Optional.absent());
stopwatch.stop();
lspLogger.log("... initial build done (" + stopwatch.toString() + ").");
return new ResourceDescriptionChangeEvent(allDeltas);
} catch (Throwable th) {
boolean wasCanceled = operationCanceledManager.isOperationCanceledException(th);
onBuildDone(true, wasCanceled, hasDependencyCycle, Optional.of(th));
if (wasCanceled) {
lspLogger.log("... initial build canceled.");
operationCanceledManager.propagateIfCancelException(th);
}
lspLogger.error("... initial build ABORTED due to exception:", th);
throw th;
}
}
Aggregations