Search in sources :

Example 1 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI 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 2 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class RepoRelativePathHolder method get.

/**
 * The method returns the RepoRelativePath for a given SyntaxRelatedTElement. It caches the result for subsequent
 * queries.
 */
public RepoRelativePath get(IdentifiableElement idElement) {
    Resource res = evadeStaticPolyfillResource(idElement);
    if (res != null) {
        if (!modulesToRepoCache.containsKey(res)) {
            FileURI fileURI = new FileURI(fixupURI(res));
            RepoRelativePath rrpRes = RepoRelativePath.compute(fileURI, workspaceAccess, res);
            if (rrpRes != null) {
                modulesToRepoCache.put(res, rrpRes);
            }
        }
        RepoRelativePath rrpRes = modulesToRepoCache.get(res);
        if (rrpRes != null && idElement instanceof SyntaxRelatedTElement) {
            return rrpRes.withLine((SyntaxRelatedTElement) idElement);
        }
    }
    return null;
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) SyntaxRelatedTElement(org.eclipse.n4js.ts.types.SyntaxRelatedTElement) RepoRelativePath(org.eclipse.n4js.jsdoc2spec.RepoRelativePath) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 3 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class FindArtifactHelper method findArtifact.

/**
 * If the receiving source folder actually contains a file for the given fully qualified name and file extension on
 * disk, this method will return a URI for this file of the same format as the URIs returned by method
 * {@link N4JSSourceFolderSnapshot#getContents()}. Otherwise, this method returns <code>null</code>.
 * <p>
 * The file extension may but need not contain a leading '.'.
 * <p>
 * Implementations are expected to be optimized for fast look-up (in particular, they should avoid iterating over
 * all URIs returned by method {@link N4JSSourceFolderSnapshot#getContents()}).
 */
public FileURI findArtifact(N4JSSourceFolderSnapshot sourceFolder, QualifiedName name, Optional<String> fileExtension) {
    final List<String> nameSegments = name.getSegments();
    if (nameSegments.isEmpty()) {
        return null;
    }
    final String[] nameSegmentsCpy = nameSegments.toArray(new String[nameSegments.size()]);
    final String ext = fileExtension.or("").trim();
    final String extWithDot = !ext.isEmpty() && !ext.startsWith(".") ? "." + ext : ext;
    final int idxLast = nameSegmentsCpy.length - 1;
    nameSegmentsCpy[idxLast] = nameSegmentsCpy[idxLast] + extWithDot;
    FileURI sourceFolderPath = sourceFolder.getPathAsFileURI();
    FileURI result = sourceFolderPath.appendSegments(nameSegmentsCpy);
    if (result.exists()) {
        return result;
    }
    return null;
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 4 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class N4JSWorkspaceConfig method reloadAllProjectInformationFromDisk.

/**
 * Clears this workspace and re-initializes it by searching the file system for projects.
 */
protected void reloadAllProjectInformationFromDisk() {
    deregisterAllProjects();
    Path baseDir = getPathAsFileURI().toPath();
    Map<Path, ProjectDescription> projects = projectDiscoveryHelper.collectAllProjectDirs(Collections.singleton(baseDir));
    for (Path newProjectPath : projects.keySet()) {
        FileURI newProjectPathAsFileURI = new FileURI(newProjectPath);
        ProjectDescription pd = projects.get(newProjectPath);
        registerProject(newProjectPathAsFileURI, pd);
    }
}
Also used : Path(java.nio.file.Path) FileURI(org.eclipse.n4js.workspace.locations.FileURI) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 5 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class IdeTestLanguageClient method publishDiagnostics.

@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
    URI uriRaw = URI.createURI(diagnostics.getUri());
    if (N4Scheme.isN4Scheme(uriRaw)) {
        return;
    }
    if (!uriRaw.isFile()) {
        throw new IllegalArgumentException("not a file URI: " + uriRaw);
    }
    FileURI uri = new FileURI(uriRaw);
    issues.removeAll(uri);
    errors.removeAll(uri);
    warnings.removeAll(uri);
    List<Diagnostic> issueList = diagnostics.getDiagnostics();
    if (issueList.isEmpty()) {
        return;
    }
    for (Diagnostic diag : issueList) {
        issues.put(uri, diag);
        switch(diag.getSeverity()) {
            case Error:
                errors.put(uri, diag);
                break;
            case Warning:
                warnings.put(uri, diag);
                break;
            default:
                // ignore
                break;
        }
    }
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) Diagnostic(org.eclipse.lsp4j.Diagnostic) FileURI(org.eclipse.n4js.workspace.locations.FileURI) URI(org.eclipse.emf.common.util.URI)

Aggregations

FileURI (org.eclipse.n4js.workspace.locations.FileURI)49 List (java.util.List)13 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Position (org.eclipse.lsp4j.Position)9 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)9 IOException (java.io.IOException)7 CompletionList (org.eclipse.lsp4j.CompletionList)7 Collections (java.util.Collections)6 Range (org.eclipse.lsp4j.Range)6 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Files (java.nio.file.Files)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 URI (org.eclipse.emf.common.util.URI)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 Diagnostic (org.eclipse.lsp4j.Diagnostic)5