Search in sources :

Example 11 with WorkspaceConfigSnapshot

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);
    }
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) URI(org.eclipse.emf.common.util.URI)

Example 12 with WorkspaceConfigSnapshot

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);
        });
    }
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) URI(org.eclipse.emf.common.util.URI) HashSet(java.util.HashSet)

Example 13 with WorkspaceConfigSnapshot

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));
    }
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ArrayList(java.util.ArrayList) FileChangeType(org.eclipse.lsp4j.FileChangeType) URI(org.eclipse.emf.common.util.URI)

Example 14 with WorkspaceConfigSnapshot

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);
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ImmutableList(com.google.common.collect.ImmutableList) HashSet(java.util.HashSet)

Example 15 with WorkspaceConfigSnapshot

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;
    }
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Aggregations

WorkspaceConfigSnapshot (org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot)20 ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)10 URI (org.eclipse.emf.common.util.URI)7 ArrayList (java.util.ArrayList)5 BuildOrderIterator (org.eclipse.n4js.xtext.workspace.BuildOrderIterator)5 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 FluentIterable (com.google.common.collect.FluentIterable)2 Iterables (com.google.common.collect.Iterables)2 Sets (com.google.common.collect.Sets)2 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)2