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 '<LOCATION>' --> <COMPLETIONS>
* </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);
}
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);
}
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);
}
}
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);
}
}
Aggregations