Search in sources :

Example 46 with FileURI

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

the class XtIdeTest method completion.

/**
 * Calls LSP endpoint 'completion'.
 *
 * <pre>
 * // Xpect completion at '&ltLOCATION&gt' --&gt; &ltCOMPLETIONS&gt
 * </pre>
 *
 * COMPLETIONS is a comma separated list.
 */
// NOTE: This annotation is used only to enable validation and navigation of .xt files.
@Xpect
public void completion(XtMethodData data) throws InterruptedException, ExecutionException {
    Position position = eobjProvider.checkAndGetPosition(data, "completion", "at");
    FileURI uri = getFileURIFromModuleName(xtData.workspace.moduleNameOfXtFile);
    CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = callCompletion(uri.toString(), position.getLine(), position.getCharacter());
    Either<List<CompletionItem>, CompletionList> result = future.get();
    List<CompletionItem> items = result.isLeft() ? result.getLeft() : result.getRight().getItems();
    List<String> ciItems = Lists.transform(items, ci -> getStringLSP4J().toString(ci));
    assertEqualIterables(data.expectation, ciItems);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) ArrayList(java.util.ArrayList) CompletionList(org.eclipse.lsp4j.CompletionList) Xpect(org.eclipse.xpect.runner.Xpect)

Example 47 with FileURI

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

the class MockWorkspaceSupplier method loadProjectDescription.

/**
 * See {@link #createWorkspaceConfig()}.
 */
protected Optional<Pair<FileURI, ProjectDescription>> loadProjectDescription() {
    FileURI candidateProjectPath = new FileURI(new File("").getAbsoluteFile());
    ProjectDescription pd = projectDescriptionLoader.loadProjectDescriptionAtLocation(candidateProjectPath, null);
    return Optional.fromNullable(pd != null ? Pair.of(candidateProjectPath, pd) : null);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) File(java.io.File) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 48 with FileURI

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

the class DtsParsesDefinitelyTypedTest method assertParseCounts.

static void assertParseCounts(Path repoRoot, int minPass, int maxFail, int maxError) throws IOException {
    Path typesFolder = repoRoot.resolve("types");
    List<Path> files = Files.walk(typesFolder, FileVisitOption.FOLLOW_LINKS).filter(file -> {
        if (!file.toString().endsWith(".d.ts")) {
            return false;
        }
        String relPath = typesFolder.relativize(file).toString();
        for (String exclude : EXCLUDES) {
            if (exclude != null && !exclude.isBlank() && relPath.startsWith(exclude)) {
                return false;
            }
        }
        return true;
    }).collect(Collectors.toList());
    Collections.sort(files, (p1, p2) -> p1.toString().compareTo(p2.toString()));
    int filesCount = files.size();
    int pass = 0;
    int fail = 0;
    int error = 0;
    System.out.println("Processing " + filesCount + " files ...");
    Stopwatch sw = Stopwatch.createStarted();
    for (Path file : files) {
        try (BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile())))) {
            N4JSResource resource = new N4JSResource();
            resource.setURI(new FileURI(file).toURI());
            DtsParseResult parseResult = new DtsParser().parse(buf, resource);
            if (parseResult.hasSyntaxErrors()) {
                fail++;
            } else {
                pass++;
            }
        } catch (Throwable e) {
            e.printStackTrace();
            if (e instanceof Error) {
                throw e;
            }
            error++;
        }
    }
    System.out.println("Done processing " + filesCount + " files in " + sw.elapsed(TimeUnit.SECONDS) + "s");
    System.out.println("  passed:  " + pass + " (" + percent(pass, filesCount) + ")");
    System.out.println("  failed:  " + fail + " (" + percent(fail, filesCount) + ")");
    System.out.println("  errors:  " + error + " (" + percent(error, filesCount) + ")");
    if (error > maxError) {
        Assert.fail("More errors detected than expected: " + error);
    }
    if (fail > maxFail) {
        Assert.fail("More failures detected than expected: " + fail);
    }
    if (pass < minPass) {
        Assert.fail("Less passes detected than expected: " + pass);
    }
}
Also used : Path(java.nio.file.Path) DtsParseResult(org.eclipse.n4js.dts.DtsParseResult) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Files(java.nio.file.Files) Stopwatch(com.google.common.base.Stopwatch) GitUtils.hardReset(org.eclipse.n4js.tests.helper.git.GitUtils.hardReset) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) DtsParser(org.eclipse.n4js.dts.DtsParser) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) N4JSResource(org.eclipse.n4js.resource.N4JSResource) StandardSystemProperty(com.google.common.base.StandardSystemProperty) FileVisitOption(java.nio.file.FileVisitOption) BufferedReader(java.io.BufferedReader) Assert(org.junit.Assert) Path(java.nio.file.Path) Collections(java.util.Collections) InputStreamReader(java.io.InputStreamReader) DtsParseResult(org.eclipse.n4js.dts.DtsParseResult) Stopwatch(com.google.common.base.Stopwatch) FileInputStream(java.io.FileInputStream) DtsParser(org.eclipse.n4js.dts.DtsParser) FileURI(org.eclipse.n4js.workspace.locations.FileURI) BufferedReader(java.io.BufferedReader) N4JSResource(org.eclipse.n4js.resource.N4JSResource)

Example 49 with FileURI

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

the class JSDoc2AdocFullTest method fullTest.

@Override
@SuppressWarnings("unused")
protected void fullTest(String projectName) throws IOException, InterruptedException, InterruptedException {
    // create an empty yarn workspace
    testWorkspaceManager.createTestOnDisk();
    startAndWaitForLspServer();
    assertNoIssues();
    File probandFolder = new File(TESTRESOURCES + projectName);
    File projectFolder = new File(getProjectLocation(), projectName);
    assertTrue("proband folder not found", probandFolder.isDirectory());
    FileCopier.copy(probandFolder, projectFolder);
    cleanBuildAndWait();
    FileURI packageJsonURI = toFileURI(getProjectLocation()).appendSegments(projectName, N4JSGlobals.PACKAGE_JSON);
    assertIssues(Map.of(packageJsonURI, Lists.newArrayList("(Error, [4:17 - 4:26], Missing dependency to n4js-runtime (mandatory for all N4JS projects of type library, application, test).)")));
    String systemSeparator = System.getProperty("line.separator", "\n");
    try {
        for (String lsep : new String[] { "\n", "\r\n", "\r" }) {
            System.setProperty("line.separator", lsep);
            String expectationFileName = projectName + "/expected.adoc";
            ResourceSet resourceSet = workspaceAccess.createResourceSet();
            N4JSProjectConfigSnapshot project = workspaceAccess.findProjectByName(resourceSet, "yarn-test-project/packages/" + projectName);
            assertNotNull("Project not found", project);
            Collection<SpecFile> specChangeSet = jSDoc2SpecProcessor.convert(new File(TESTRESOURCES), Collections.singleton(project), (p) -> resourceSet, SubMonitorMsg.nullProgressMonitor());
            String adocRootName = TESTRESOURCES + projectName + "/expectedADoc";
            Collection<String> expectedFileNames = getExpectedFileNames(adocRootName, specChangeSet);
            assertFalse(expectedFileNames.isEmpty());
            File adocRoot = new File(adocRootName);
            String completeActual = "";
            String completeExpected = "";
            for (SpecFile specFile : specChangeSet) {
                String expectedFile = getExpectedFile(expectedFileNames, specFile);
                if (expectedFile == null)
                    continue;
                Path fullExpectationPath = adocRoot.toPath().resolve(expectedFile);
                File fullExpectationFile = fullExpectationPath.toFile();
                String fullExpectationPathStr = fullExpectationPath.toString();
                String expectedADoc = Files.asCharSource(fullExpectationFile, Charset.defaultCharset()).read();
                String actualADoc = specFile.getNewContent();
                if (UPDATE_EXPECTION && !actualADoc.equals(expectedADoc)) {
                    expectedADoc = actualADoc;
                    org.eclipse.xtext.util.Files.writeStringIntoFile(fullExpectationPathStr, expectedADoc);
                    System.out.println("Updated expectation " + fullExpectationPathStr);
                }
                completeActual += "\n//////// " + expectedFile + " ////////\n";
                completeActual += actualADoc;
                completeExpected += "\n//////// " + expectedFile + " ////////\n";
                completeExpected += expectedADoc;
            }
            assertEqualsIgnoreWS(completeExpected, completeActual);
        }
    } finally {
        System.setProperty("line.separator", systemSeparator);
    }
}
Also used : Path(java.nio.file.Path) FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile) File(java.io.File) SpecFile(org.eclipse.n4js.jsdoc2spec.SpecFile)

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