Java Code Examples for org.eclipse.lsp4j.FileChangeType#Deleted
The following examples show how to use
org.eclipse.lsp4j.FileChangeType#Deleted .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LSPBuilder.java From n4js with Eclipse Public License 1.0 | 6 votes |
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) { // TODO: Set watched files to client. Note: Client may have performance issues with lots of folders to watch. final List<URI> dirtyFiles = new ArrayList<>(); final List<URI> deletedFiles = new ArrayList<>(); for (FileEvent fileEvent : params.getChanges()) { URI uri = uriExtensions.toUri(fileEvent.getUri()); String fileName = uri.lastSegment(); boolean skipFile = fileName.equals(ProjectStatePersister.FILENAME); if (!skipFile && isSourceFile(uri)) { FileChangeType changeType = fileEvent.getType(); if (changeType == FileChangeType.Deleted) { deletedFiles.add(uri); } else { dirtyFiles.add(uri); } } } if (!dirtyFiles.isEmpty() || !deletedFiles.isEmpty()) { runBuildable("didChangeWatchedFiles", () -> workspaceManager.didChangeFiles(dirtyFiles, deletedFiles)); } }
Example 2
Source File: ServerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testIncrementalDeletion() { StringConcatenation _builder = new StringConcatenation(); _builder.append("type Test {"); _builder.newLine(); _builder.append(" "); _builder.append("NonExisting foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String path = this.writeFile("MyType1.testlang", _builder); this.initialize(); this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getMessage()); this.deleteFile("MyType1.testlang"); WorkspaceService _workspaceService = this.languageServer.getWorkspaceService(); FileEvent _fileEvent = new FileEvent(path, FileChangeType.Deleted); DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent))); _workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams); Assert.assertTrue(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()).isEmpty()); }
Example 3
Source File: ServerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testTwoFilesDeleteClose() { final String fileURI = this.writeFile("Foo.testlang", ""); this.initialize(); final String referencingFileURI = this.getVirtualFile("Bar.testlang"); StringConcatenation _builder = new StringConcatenation(); _builder.append("type Bar {"); _builder.newLine(); _builder.append(" "); _builder.append("Foo foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this.open(referencingFileURI, _builder.toString()); Assert.assertFalse("Bar.testlang references missing type Foo from Foo.testlang: expect error", this.getDiagnostics().get(referencingFileURI).isEmpty()); this.open(fileURI, "type Foo {}"); Assert.assertTrue("Bar.testlang references type Foo from Foo.testlang: expect no error", this.getDiagnostics().get(referencingFileURI).isEmpty()); this.deleteFile(fileURI); WorkspaceService _workspaceService = this.languageServer.getWorkspaceService(); FileEvent _fileEvent = new FileEvent(fileURI, FileChangeType.Deleted); DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent))); _workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams); Assert.assertTrue("delete file on disk: expect no error", this.getDiagnostics().get(referencingFileURI).isEmpty()); this.close(fileURI); Assert.assertFalse("close deleted file: expect error", this.getDiagnostics().get(referencingFileURI).isEmpty()); }
Example 4
Source File: ActionScriptServices.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
private void createSourcePathWatcher() { try { sourcePathWatcher = FileSystems.getDefault().newWatchService(); } catch (IOException e) { System.err.println("Failed to get watch service for source paths."); e.printStackTrace(System.err); } sourcePathWatcherThread = new Thread() { public void run() { while(true) { WatchKey watchKey = null; try { //pause the thread while there are no changes pending, //for better performance watchKey = sourcePathWatcher.take(); } catch(InterruptedException e) { return; } List<FileEvent> changes = new ArrayList<>(); while (watchKey != null) { for (WorkspaceFolder folder : workspaceFolderManager.getWorkspaceFolders()) { WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderData(folder); if(!folderData.sourceOrLibraryPathWatchKeys.containsKey(watchKey)) { continue; } Path path = folderData.sourceOrLibraryPathWatchKeys.get(watchKey); for (WatchEvent<?> event : watchKey.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); Path childPath = (Path) event.context(); childPath = path.resolve(childPath); if(java.nio.file.Files.isDirectory(childPath)) { if(kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) { //if a new directory has been created under //an existing that we're already watching, //then start watching the new one too. watchNewSourceOrLibraryPath(childPath, folderData); } } FileChangeType changeType = FileChangeType.Changed; if(kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) { changeType = FileChangeType.Created; } else if(kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) { changeType = FileChangeType.Deleted; } changes.add(new FileEvent(childPath.toUri().toString(), changeType)); } boolean valid = watchKey.reset(); if (!valid) { folderData.sourceOrLibraryPathWatchKeys.remove(watchKey); } } //keep handling new changes until we run out watchKey = sourcePathWatcher.poll(); } if (changes.size() > 0) { //convert to DidChangeWatchedFilesParams and pass //to didChangeWatchedFiles, as if a notification //had been sent from the client. DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(); params.setChanges(changes); didChangeWatchedFiles(params); } } } }; sourcePathWatcherThread.start(); }