Skip to main content

Module file_io

Module file_io 

Source
Expand description

The editor’s file RPCs (read, write, list, reveal, create, delete; a rename is fs.rename), moved out of register_editor_handlers unchanged as named functions. Each mutation takes the user’s home folder as a parameter, so a test can point it at a temp dir; the registration passes dirs::home_dir().

Constants§

MAX_EDITOR_FILE_BYTES 🔒
readeditorfile and writeeditorfile refuse more than this.

Functions§

check_write_size 🔒
Content past the limit is refused before anything else, remote or local.
create_dir 🔒
Creates a directory inside an existing directory.
create_file 🔒
Creates an empty file inside an existing directory.
delete_file 🔒
Deletes a file or directory.
dir_entry 🔒
file_type() is the entry’s own type, so a symlink shows as one (no follow); metadata() follows symlinks, so a symlinked dir reports is_dir. Both are needed: is_symlink from the first, is_dir and size from the second (a symlink-to-dir reads as a directory, matching VS Code).
encode_content 🔒
The file’s original encoding, BOM and line endings, so a non-UTF-8 file round-trips instead of being silently rewritten as UTF-8. Absent fields default to UTF-8. The bool is true when some character has no representation in that encoding.
is_plain_name 🔒
A new file or folder name is one plain path component.
list_dir 🔒
Lists a directory for the editor’s file-tree pane. Symlinks are followed (matches VS Code semantics; the frontend marks followed symlinks with a ↗ overlay). Spec: docs/specs/SPEC_EDITOR_FILE_TREE_2026-05-26.md
read_local_file 🔒
Reads the bytes and detects the encoding (BOM, then UTF-8, then a heuristic), decoding to UTF-8 for the editor, so non-UTF-8 files (Windows-1252 .ini, UTF-16, Shift_JIS, …) open instead of erroring.
read_remote_file 🔒
A file on an SSH host: read there by its helper, decoded here the same way (remote terminals spec §6.3).
read_result 🔒
The reply to a read: the detected encoding, BOM and line ending ride back so a save round-trips the original format. See docs/specs/SPEC_EDITOR_FILE_ENCODINGS_2026_06_17.md.
reveal_in_shell 🔒
Reveals a path in the OS file manager.
write_local_file 🔒
Writes restricted to under the user’s home directory: an allowlist, safer than an incomplete denylist.
write_remote_file 🔒
A file on an SSH host: encoded here as for a local file, then written there atomically by its helper.