Search in sources :

Example 1 with N4JSWorkspaceConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.

the class ImportHelper method findResolutionsForAllUnresolvedReferences.

/**
 * Searches the entire AST for unresolved references and searches possible resolutions for each. Returns the
 * resolutions of those unresolved references that are unambiguous, i.e. that have only a single possible
 * resolution.
 *
 * @see ReferenceResolutionFinder#findResolutions(N4JSWorkspaceConfigSnapshot, ReferenceDescriptor, boolean,
 *      boolean, Predicate, Predicate, IResolutionAcceptor)
 */
public List<ReferenceResolution> findResolutionsForAllUnresolvedReferences(Script script, CancelIndicator cancelIndicator) {
    triggerProxyResolution(script, cancelIndicator);
    N4JSWorkspaceConfigSnapshot wc = workspaceAccess.getWorkspaceConfig(script);
    List<ReferenceResolution> result = new ArrayList<>();
    Set<String> donePrefixes = new HashSet<>();
    Iterator<EObject> iter = script.eAllContents();
    while (iter.hasNext()) {
        operationCanceledManager.checkCanceled(cancelIndicator);
        EObject curr = iter.next();
        ReferenceDescriptor reference = getUnresolvedReferenceForASTNode(curr);
        if (reference != null && donePrefixes.add(reference.text)) {
            ResolutionAcceptor acceptor = new ResolutionAcceptor(2, cancelIndicator);
            referenceResolutionFinder.findResolutions(wc, reference, true, true, Predicates.alwaysFalse(), Predicates.alwaysTrue(), acceptor);
            // only add a found resolution if we have exactly one resolution (i.e. if reference is unambiguous)
            List<ReferenceResolution> resolutions = acceptor.getResolutions();
            if (resolutions.size() == 1) {
                result.add(resolutions.get(0));
            }
        }
    }
    return result;
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) EObject(org.eclipse.emf.ecore.EObject) IResolutionAcceptor(org.eclipse.n4js.ide.imports.ReferenceResolutionFinder.IResolutionAcceptor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with N4JSWorkspaceConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.

the class N4JSProjectBuilder method writeTestCatalog.

/**
 * Generates the test catalog for the project.
 */
private void writeTestCatalog() {
    N4JSWorkspaceConfigSnapshot workspaceConfig = (N4JSWorkspaceConfigSnapshot) workspaceManager.getWorkspaceConfig();
    N4JSProjectConfigSnapshot projectConfig = getProjectConfig();
    File testCatalog = getTestCatalogFile(projectConfig);
    String catalog = testCatalogSupplier.get(workspaceConfig, getResourceSet(), projectConfig, // do not include "endpoint" property here
    true);
    if (catalog != null) {
        try (FileWriter fileWriter = new FileWriter(testCatalog)) {
            fileWriter.write(catalog);
        } catch (IOException e) {
            LOG.error("Error while writing test catalog file: " + testCatalog);
        }
    }
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 3 with N4JSWorkspaceConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.

the class N4JSCodeActionService method applyToProject.

/**
 * Applies all fixes of the same kind to the project containing the given URI.
 */
public WorkspaceEdit applyToProject(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {
    WorkspaceEdit result = new WorkspaceEdit();
    QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
    if (quickfix == null) {
        return result;
    }
    N4JSWorkspaceConfigSnapshot wc = (N4JSWorkspaceConfigSnapshot) concurrentIndex.getWorkspaceConfigSnapshot();
    N4JSProjectConfigSnapshot project = wc.findProjectContaining(uri);
    if (project == null) {
        return result;
    }
    List<URI> urisInProject = Lists.newArrayList(IterableExtensions.flatMap(project.getSourceFolders(), N4JSSourceFolderSnapshot::getContents));
    Map<String, List<TextEdit>> allEdits = new HashMap<>();
    for (URI currURI : urisInProject) {
        Map<String, List<TextEdit>> edits = doApplyToFile(currURI, issueCode, quickfix, cancelIndicator);
        allEdits.putAll(edits);
    }
    result.setChanges(allEdits);
    return result;
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) HashMap(java.util.HashMap) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ArrayList(java.util.ArrayList) List(java.util.List) URI(org.eclipse.emf.common.util.URI)

Example 4 with N4JSWorkspaceConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.

the class DtsSubGenerator method isActive.

@Override
public boolean isActive(Resource input) {
    boolean superIsActive = super.isActive(input);
    if (!superIsActive) {
        return false;
    }
    N4JSWorkspaceConfigSnapshot ws = workspaceAccess.getWorkspaceConfig(input);
    N4JSProjectConfigSnapshot project = ws.findProjectContaining(input.getURI());
    if (project != null) {
        ProjectDescription pd = project.getProjectDescription();
        return N4JSLanguageUtils.isDtsGenerationActive(pd);
    }
    return false;
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 5 with N4JSWorkspaceConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot in project n4js by eclipse.

the class MockWorkspaceSupplier method createWorkspaceConfig.

/**
 * Creates the configuration of the mocked test workspace.
 * <p>
 * The returned workspace configuration is expected to contain at least one project with at least one source folder
 * that isn't a {@link N4JSSourceFolderSnapshotForPackageJson}. The corresponding folders and files are not expected
 * to exist on disk.
 * <p>
 * Only invoked on demand and never more than once.
 */
protected N4JSWorkspaceConfigSnapshot createWorkspaceConfig() {
    N4JSProjectConfigSnapshot projectConfig = createProjectConfig();
    URI workspacePath = URIUtils.trimTrailingPathSeparator(projectConfig.getPath()).trimSegments(1);
    ProjectSet projects = new ProjectSet(Collections.singleton(projectConfig));
    BuildOrderInfo buildOrderInfo = new BuildOrderInfo(Collections.emptyList(), Collections.emptySet());
    return new N4JSWorkspaceConfigSnapshot(workspacePath, projects, buildOrderInfo);
}
Also used : BuildOrderInfo(org.eclipse.n4js.xtext.workspace.BuildOrderInfo) N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI) ProjectSet(org.eclipse.n4js.xtext.workspace.ProjectSet)

Aggregations

N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)11 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)7 URI (org.eclipse.emf.common.util.URI)4 ArrayList (java.util.ArrayList)3 IResolutionAcceptor (org.eclipse.n4js.ide.imports.ReferenceResolutionFinder.IResolutionAcceptor)3 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 N4JSResource (org.eclipse.n4js.resource.N4JSResource)2 N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)2 Predicate (com.google.common.base.Predicate)1 Inject (com.google.inject.Inject)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 EClass (org.eclipse.emf.ecore.EClass)1