Skip to content

Gregoor/tofu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Tofu is an experimental VSCode extension for structured-yet-fluid code writing with JavaScript and TypeScript.

Its goal is to provide more semantically meaningful code transformations while also offering escape hatches for direct literal code editing. A secondary goal is to minimize moments of broken syntax.

Caveats

Given my limited resources of time, I sacrifice efficiency at the altar of iterating on the idea. Tofu re-parses the whole file on every edit, using Babel and formats it with Prettier after most actions. This is not incremental, and costly for large files. In the short-term I make it work by not having large file, which I tend to favor anyway.
In the longer term, I'd love for Tofu to use an incremental parser like TreeSitter instead.

In terms of experience, depending on where you are coming from, this might be a radical change to how you usually code. Forget thinking about code style or managing syntax and slide into the world of literal structural editing.

Actions

The keymap is designed to be familiar and literal. These are the basic actions which are usable in most contexts:

Action Key(s)
Cursor
Move


Jump ⌥ Alt
⌥ Alt
Selection ⇧ Shift +
Extend +
Shrink +
Neighbors +
+
Add new line ⏎ Enter (below)
⇧ Shift ⏎ Enter (above)
Wrap ⌥ Alt (Select)
( (Parenthesize)
{ (Object)
[ (Array)
> (Function)
< (JSX)
Unwrap ⌥ Alt
Move Node ⇧ Shift ⌥ Alt
⇧ Shift ⌥ Alt
Toggle Tofu (Escape hatch) Esc

On top of this there are around 50 contextual actions (and counting). A few examples:

  • e at the end of an if-block will add an else branch, placing the cursor within the new block
  • l at the start of a variable declaration will replace the kind (e.g. const) with let
  • many are small in nature such as [ at the end of an expression inserting [0] instead to minimize broken syntactical states

I am sure there are many I have not thought of, so contributions in the forms of new issues describing your expectations and wishes are greatly appreciated.

The opposite is also true, Tofu makes assumptions about what the right action is in which context. Please let me know where I have baked in assumptions which do not jive with your style.

I will stop thinking of Tofu as an experiment once I and other users deem it a clear workflow improvement and the project has found a path towards monetary sustainability.