Search in sources :

Example 6 with N4JSProjectConfigSnapshot

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

the class N4JSTextDocumentFrontend method implementation.

@Override
protected Either<List<? extends Location>, List<? extends LocationLink>> implementation(ResourceTaskContext rtc, ImplementationParams params, CancelIndicator cancelIndicator) {
    URI uri = rtc.getURI();
    N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(rtc.getResource());
    String targetFileName = resourceNameComputer.generateFileDescriptor(rtc.getResource(), uri, JS_FILE_EXTENSION);
    List<Location> locations = new ArrayList<>();
    if (project != null && !Strings.isNullOrEmpty(targetFileName)) {
        String outputPath = project.getOutputPath();
        Path projectLocation = project.getPathAsFileURI().toFileSystemPath();
        Path genFilePath = projectLocation.resolve(outputPath + "/" + targetFileName);
        Range range = findRange(params, genFilePath);
        Location location = new Location();
        location.setUri(new FileURI(genFilePath.toFile()).toString());
        location.setRange(range);
        locations.add(location);
    }
    return Either.forLeft(locations);
}
Also used : Path(java.nio.file.Path) FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Location(org.eclipse.lsp4j.Location)

Example 7 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot 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 8 with N4JSProjectConfigSnapshot

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

the class N4JSDReader method readN4JSDs.

/**
 * Reads all N4JSD files in project, scans for types and links the tests.
 *
 * @return all types in a mapped with fully qualified type name (inclusive module spec) as key, the type info only
 *         contains the types, no other information yet.
 * @throws InterruptedException
 *             thrown when user cancels the operation
 */
public Collection<SpecInfo> readN4JSDs(Collection<N4JSProjectConfigSnapshot> projects, Function<N4JSProjectConfigSnapshot, ResourceSet> resSetProvider, SubMonitorMsg monitor) throws InterruptedException {
    SpecInfosByName specInfosByName = new SpecInfosByName(issueAcceptor, globalScopeProvider, containerTypesHelper, workspaceAccess);
    ResourceSet resSet = null;
    SubMonitorMsg sub = monitor.convert(2 * 100 * projects.size());
    for (N4JSProjectConfigSnapshot project : projects) {
        if (resSet == null) {
            resSet = resSetProvider.apply(project);
        }
        readScripts(specInfosByName, project, resSet, sub.newChild(100));
    }
    for (N4JSProjectConfigSnapshot project : projects) {
        if (resSet == null) {
            resSet = resSetProvider.apply(project);
        }
        linkTests(specInfosByName, project, resSet, sub.newChild(100));
    }
    return specInfosByName.values();
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 9 with N4JSProjectConfigSnapshot

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

the class JSONIdeContentProposalProvider method proposeVersions.

private void proposeVersions(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) {
    if (namePath.size() >= 2) {
        // somewhat poor heuristic: propose all projects that are known in the current workspace
        String devOrDep = namePath.get(namePath.size() - 2);
        if (PackageJsonProperties.DEPENDENCIES.name.equals(devOrDep) || PackageJsonProperties.DEV_DEPENDENCIES.name.equals(devOrDep)) {
            NameValuePair pair = (NameValuePair) context.getCurrentModel();
            N4JSProjectConfigSnapshot project = workspaceAccess.findProjectByName(context.getResource(), pair.getName());
            if (project != null) {
                VersionNumber version = project.getVersion();
                ContentAssistEntry versionEntry = getProposalCreator().createProposal('"' + version.toString() + '"', context, ContentAssistEntry.KIND_VALUE, null);
                acceptor.accept(versionEntry, getProposalPriorities().getDefaultPriority(versionEntry));
            }
            ContentAssistEntry wildcard = getProposalCreator().createProposal("\"*\"", context, ContentAssistEntry.KIND_VALUE, null);
            acceptor.accept(wildcard, getProposalPriorities().getDefaultPriority(wildcard));
        }
    }
}
Also used : NameValuePair(org.eclipse.n4js.json.JSON.NameValuePair) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber)

Example 10 with N4JSProjectConfigSnapshot

use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot 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)

Aggregations

N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)50 URI (org.eclipse.emf.common.util.URI)15 N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)9 N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)8 Path (java.nio.file.Path)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)7 FileURI (org.eclipse.n4js.workspace.locations.FileURI)7 ArrayList (java.util.ArrayList)6 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)6 File (java.io.File)5 HashMap (java.util.HashMap)5 N4JSResource (org.eclipse.n4js.resource.N4JSResource)5 LinkedHashMap (java.util.LinkedHashMap)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)4 TModule (org.eclipse.n4js.ts.types.TModule)4 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)4