Silos

Dumb, proomptable modular snippet search.

preview

Installation

You can download a binary from releases tab or build the project from source.

From source

Prerequisites:

Clone this repository and build it.

cargo install --git https://github.com/lavafroth/silos

Editor support

  • Helix: Use the example .helix directory provided to run the LSP for files under ./examples/.
  • Neovim: Please follow the official guide.
  • VSCode: Use the vscode-lspconfig extension with the .vscode/settings.json provided.

Make sure to modify the binary path in the example to where you have it on your system.

Usage

  • Write a comment above a paragraph of code, consider the example in examples/example.go
  resumeFilename := "resume.pdf"
  version := 3
  // refactor: change the file basename to that of the parent
  whereIsMyResume :=
    filepath.Base(
      documentsDirectory + "CV" + "_v" + strconv.Itoa(version) + "/" + resumeFilename)
  • The comment must begin with either of
    • generate:
    • refactor:
  • Select the code to be modified along with the comment above it.
  • Trigger code actions. In helix, this is space, a.
  • Select the option called "ask silos."

Note

Embedding defaults to using the CPU. You may use the --gpu flag with a GPU number to use a dedicated GPU.

generate snippets

  • Stored in the KDL format inside per-language directories under ./snippets/v1.
  • They must conform to the following structure
desc "describes the snippet"
body #"the snippet itself"#

KDL supports arbitrary raw strings with as many #s before and after the quotes to disambiguate them from the string contents.

See the example snippet ./snippets/v1/go/simple_worker.kdl in the go programming language.

refactor snippets

This API parses code into an AST (Abstract Syntax Tree) via tree-sitter and can perform subsequent mutations.

Supported Languages

  • C
  • Rust
  • Go
  • Javascript
  • C++

Defining mutation collections

description "describes the mutation collection"
mutation {
  expression "(some ((beautiful) @adjective) AST expression) @root"
  substitute {
    literal "hello"
    capture "adjective"
    literal "world"
  }
}

mutation {
  expression "(another) @root"
  substitute {
    literal "multiple mutations work"
    literal "as long as their expression"
    literal "don't collide"
  }
}
  • description: A textual description of the mutation collection.
  • mutation: Defines individual code changes.
    • expression: Uses tree-sitter to match and capture AST nodes with @ prefixes,
    • The special @root node must be specify the expression to be replaced.
    • substitute: Constructs the modified code using literals and captured arguments.

See the example mutation collection in ./snippets/v2/go/filepath-parent.kdl.

  • The API performs a single-pass substitution based on the closest matching mutation.
  • Captured groups are used within the substitute block and the mutated code is returned.

Every capture group must contain the largest atom to be operated on. For example: if you wish to operate on elements of an array, capture each identifier inside the array

Correct way: Here the array and identifier only hints about where the expression root lies.

(array (identifier @root))

Incorrect way: Here the root expression matches the block all the array elements inside the braces, not each element.

(array ((identifier)*) @entire-block-capture) @root

Further reading

Description
No description provided
Readme 2.1 MiB
Languages
Rust 97.8%
Nix 2.2%