Skip to content

Consider checking if it's possible to treat JS/TS template literals prefixed by tact as scratch buffers to support some level of code intelligence #758

@novusnota

Description

@novusnota

While doing the Tact Tour, for storing code for each lesson I've settled on strings specified using template literals of JS/TS.

The basic setup needs the following definition:

/** Template literal for highlighting Tact code within strings */
export const tact = (strings: TemplateStringsArray, ...values: unknown[]): string => {
  return strings.reduce((result, string, i) => {
    return result + string + (values[i] || "");
  }, "");
};

After which, one can write tact followed by backticks, and then in code editors that use Tree-sitter grammars, those strings would automatically highlight with tree-sitter-tact. I can't vouch for all such editors, but in Neovim and Helix, the inner code there is highlighted as Tact code, while the outer code is highlighted as TypeScript:

import { tact } from "./tact-literal"; // example import

const tactCode = tact`// here goes code in Tact, with highlighting!
import "@stdlib/ownable";

// ...
contract Whatever() {}

Or, an actual example from the editor:

Image

It could be fun to enable some code intelligence and at least some auto-complete and hover while the cursor (caret) is within the Tact template literal in the .[tj]sx? files (basic regex for js, jsx, ts, tsx).

Not necessary, as in case of the Tour all examples would be checked locally for validity upon compilation. But fun!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions