virtual_file.md: cleanup, updates

This commit is contained in:
Yann Cébron 2020-07-16 14:45:23 +02:00
parent 985dc2a3f3
commit a735561573

View File

@ -3,7 +3,7 @@ title: Virtual Files
---
<!-- Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
A virtual file [`VirtualFile`](upsource:///platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java) is the *IntelliJ Platform's* representation of a file in a Virtual File System (VFS).
A [`VirtualFile`](upsource:///platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java) (VF) is the *IntelliJ Platform's* representation of a file in a [Virtual File System (VFS)](/basics/virtual_file_system.md).
Most commonly, a virtual file is a file in a local file system.
However, the *IntelliJ Platform* supports multiple pluggable file system implementations, so virtual files can also represent classes in a JAR file, old revisions of files loaded from a version control repository, and so on.
@ -17,7 +17,7 @@ From an action
From a path in the local file system:
: - `LocalFileSystem.getInstance().findFileByIoFile()`
- `com.intellij.openapi.vfs.VirtualFileLookup` (2020.2 and later)
- `VirtualFileManager.findFileByNioPath()`/`refreshAndFindFileByNioPath()` (2020.2 and later)
From a PSI file
: `psiFile.getVirtualFile()` (may return `null` if the PSI file exists only in memory)
@ -32,10 +32,10 @@ Recursive iteration should be performed using `VfsUtilCore.iterateChildrenRecurs
## Where does it come from?
The VFS is built incrementally by scanning the file system up and down starting from the project root.
New files appearing in the file system are detected by VFS _refreshes_.
A refresh operation can be initiated programmatically using `VirtualFileManager.getInstance().refresh()` or `VirtualFile.refresh()`.
VFS refreshes are also triggered whenever file system watchers receive file system change notifications (available on the Windows and macOS operating systems).
The VFS is built incrementally by scanning the file system up and down, starting from the project root.
VFS _refreshes_ detect new files appearing in the file system.
A refresh operation can be initiated programmatically using `VirtualFileManager.syncRefresh()`/`asyncRefresh()` or `VirtualFile.refresh()`.
VFS refreshes are also triggered whenever file system watchers receive file system change notifications.
Invoking a VFS refresh might be necessary for accessing a file that has just been created by an external tool through the IntelliJ Platform APIs.
@ -48,7 +48,7 @@ If a file is deleted, its corresponding VirtualFile instance becomes invalid (`i
## How do I create a virtual file?
Usually, you don't. As a rule, files are created either through the PSI API or through the regular `java.io.File` API.
Usually, you don't. As a general rule, files are created either through the PSI API or through the regular `java.io.File` API.
If one needs to create a file through VFS, use `VirtualFile.createChildData()` to create a `VirtualFile` instance and `VirtualFile.setBinaryContent()` to write some data to the file.
@ -81,7 +81,7 @@ Use [`ProjectLocator`](upsource:///platform/projectModel-api/src/com/intellij/op
## How do I extend VFS?
To provide an alternative file system implementation (for example, an FTP file system), implement the [`VirtualFileSystem`](upsource:///platform/core-api/src/com/intellij/openapi/vfs/VirtualFileSystem.java) class (most likely you'll also need to implement `VirtualFile`), and register your implementation as an [application component](/basics/plugin_structure/plugin_components.md).
To provide an alternative file system implementation (for example, an FTP file system), implement the [`VirtualFileSystem`](upsource:///platform/core-api/src/com/intellij/openapi/vfs/VirtualFileSystem.java) class (most likely you'll also need to implement `VirtualFile`), and register your implementation via `com.intellij.virtualFileSystem` extension point (2019.2 and later) or [application component](/basics/plugin_structure/plugin_components.md) for earlier versions.
To hook into operations performed in the local file system (for example, when developing a version control system integration that needs custom rename/move handling), implement [`LocalFileOperationsHandler`](upsource:///platform/analysis-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java) and register it via `LocalFileSystem.registerAuxiliaryFileOperationsHandler()`.