use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractIdeTest method deleteFolderNotContainingOpenFiles.
/**
* Delete a folder and its entire content and notify the LSP server. The folder must not contain open files.
* <p>
* Which URIs the LSP client will include in the resulting <code>didChangeWatchedFiles</code> notification depends
* on the configuration during server start-up and initialization. For example, a VSCode extension might configure a
* static glob pattern for this purpose or the server could dynamically register for file events in certain folders.
* To simulate various such configurations in tests, this method provides the <code>nameRegEx</code> parameter.
*
* @param folderURI
* URI of the folder to be deleted. Must not contain open files.
* @param nameRegEx
* the URI of a deleted file/folder is included in the <code>didChangeWatchedFiles</code> notification if
* and only if the file/folder's name matches this regular expression.
*/
protected void deleteFolderNotContainingOpenFiles(FileURI folderURI, String nameRegEx) {
// 1) collect all files and folders to be deleted
List<FileURI> allFoldersAndFiles;
try (Stream<Path> walker = Files.walk(folderURI.toFile().toPath())) {
allFoldersAndFiles = walker.map(p -> toFileURI(p.toFile())).collect(Collectors.toList());
} catch (IOException e) {
throw new WrappedException("exception while walking file tree", e);
}
// 2) delete on disk
for (FileURI currURI : Lists.reverse(allFoldersAndFiles)) {
deleteFileOnDiskWithoutNotification(currURI);
}
Assert.assertFalse("folder was not properly deleted on disk", folderURI.toFile().exists());
// 3) notify the LSP server
Pattern pattern = Pattern.compile(nameRegEx);
List<FileEvent> fileEvents = allFoldersAndFiles.stream().filter(uri -> pattern.matcher(uri.getName()).matches()).map(uri -> new FileEvent(uri.toString(), FileChangeType.Deleted)).collect(Collectors.toList());
Assert.assertFalse("at least one deleted file/folder must match the 'nameRegEx'", fileEvents.isEmpty());
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(fileEvents);
languageServer.didChangeWatchedFiles(params);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class AbstractRenameTest method applyWorkspaceEdit.
/**
* Unchanged modules are not included in the returned map.
*/
private Map<FileURI, String> applyWorkspaceEdit(Map<String, Map<String, String>> projectsModulesSourcesBefore, WorkspaceEdit edit, RenamePosition pos, RenameTestConfiguration config) {
Map<FileURI, List<TextEdit>> fileURI2TextEdits = new LinkedHashMap<>();
for (Entry<String, List<TextEdit>> entry : edit.getChanges().entrySet()) {
String uriStr = entry.getKey();
List<TextEdit> textEdits = entry.getValue();
FileURI fileURI = getFileURIFromURIString(uriStr);
fileURI2TextEdits.put(fileURI, textEdits);
}
Map<FileURI, String> fileURI2ActualSourceAfter = new LinkedHashMap<>();
for (Entry<String, Map<String, String>> entry1 : projectsModulesSourcesBefore.entrySet()) {
String projectName = entry1.getKey();
Map<String, String> moduleName2SourceBefore = entry1.getValue();
if (projectName.startsWith("#")) {
// ignore entries with special information, e.g. TestWorkspaceManager#NODE_MODULES
continue;
}
for (Entry<String, String> entry2 : moduleName2SourceBefore.entrySet()) {
String moduleName = entry2.getKey();
String sourceBefore = entry2.getValue();
if (moduleName.startsWith("#")) {
// ignore entries with special information, e.g. TestWorkspaceManager#DEPENDENCIES
continue;
}
FileURI fileURI = getFileURIFromModuleName(moduleName);
List<TextEdit> textEdits = fileURI2TextEdits.get(fileURI);
if (textEdits != null) {
String actualSourceAfter = applyTextEdits(sourceBefore, textEdits);
fileURI2ActualSourceAfter.put(fileURI, actualSourceAfter);
} else {
// no changes in this file -> ignore
}
}
}
Set<FileURI> unknownURIs = new LinkedHashSet<>(fileURI2TextEdits.keySet());
unknownURIs.removeAll(fileURI2ActualSourceAfter.keySet());
if (!unknownURIs.isEmpty()) {
String sourceBefore = config.projectsModulesSourcesBefore.get(pos.projectName).get(pos.moduleName);
fail("rename led to text edits in unknown URIs: " + Joiner.on(", ").join(unknownURIs), sourceBefore, pos);
}
return fileURI2ActualSourceAfter;
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class TestLspManager method doStartLspServer.
/**
* Connects, initializes and waits for the initial build of the test project.
*/
@SuppressWarnings("deprecation")
protected void doStartLspServer(File root) {
ClientCapabilities capabilities = new ClientCapabilities();
WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
wcc.setExecuteCommand(new ExecuteCommandCapabilities());
capabilities.setWorkspace(wcc);
TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities();
// activate 'prepareRename' requests
tdcc.setRename(new RenameCapabilities(true, false));
capabilities.setTextDocument(tdcc);
InitializeParams initParams = new InitializeParams();
initParams.setCapabilities(capabilities);
initParams.setRootUri(new FileURI(root).toString());
languageServer.connect(languageClient);
languageServer.initialize(initParams).join();
languageServer.initialized(null);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class XtIdeTest method output.
/**
* Compiles and executes the current xt file and compares the output to the expected output
*
* <pre>
* // Xpect output --> <OUTPUT>
* </pre>
*/
// NOTE: This annotation is used only to enable validation and navigation of .xt files.
@Xpect
public void output(XtMethodData data) {
String moduleName = xtData.workspace.moduleNameOfXtFile;
int idxStart = Math.max(moduleName.lastIndexOf("/") + 1, 0);
int idxEnd = moduleName.lastIndexOf(".");
String genModuleName = moduleName.substring(idxStart, idxEnd) + ".js";
FileURI fileUri = getFileURIFromModuleName(genModuleName);
installN4JSRuntime();
assertOutput(fileUri, data.expectation);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class XtIdeTest method initializeXtFile.
/**
* Call this before calling any other methods of {@link XtIdeTest}.
*/
public void initializeXtFile(Set<String> globallySuppressedIssues, XtFileData newXtData) {
Preconditions.checkNotNull(newXtData);
xtData = newXtData;
testWorkspaceManager.createTestOnDisk(xtData.workspace);
Set<String> actuallySuppressedIssues = new HashSet<>(globallySuppressedIssues);
actuallySuppressedIssues.removeAll(xtData.enabledIssues);
actuallySuppressedIssues.addAll(xtData.disabledIssues);
setSuppressedIssues(actuallySuppressedIssues);
for (XtMethodData startupMethod : xtData.startupMethodData) {
switch(startupMethod.name) {
case "startAndWaitForLspServer":
startAndWaitForLspServer();
break;
default:
throw new IllegalArgumentException("Unknown method: " + startupMethod.name);
}
}
FileURI xtModule = getFileURIFromModuleName(xtData.workspace.moduleNameOfXtFile);
languageServer.getResourceTaskManager().runInTemporaryContext(xtModule.toURI(), "test", false, (context, ci) -> {
resource = context.getResource();
Preconditions.checkNotNull(resource);
eobjProvider = new XtResourceEObjectAccessor(xtData, resource);
if (resource instanceof N4JSResource) {
N4JSResource n4Res = ((N4JSResource) resource);
n4Res.resolveLazyCrossReferences(ci);
}
return null;
}).join();
ArrayList<XtMethodData> issueTests = new ArrayList<>();
LOOP: for (XtMethodData testMethod : xtData.getTestMethodData()) {
switch(testMethod.name) {
case "nowarnings":
case "noerrors":
case "warnings":
case "errors":
issueTests.add(testMethod);
break;
default:
// test method data is sorted: issue related tests methods come first
break LOOP;
}
}
this.issueHelper = new XtMethodsIssues(xtData, getIssuesInFile(xtModule), issueTests);
}
Aggregations