Skip to content

JulesNP/advent2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Configuring a Repl

Every new repl comes with a .replit and a replit.nix file that let you configure your repl to do just about anything in any language!

replit.nix

Every new repl is now a Nix repl, which means you can install any package available on Nix, and support any number of languages in a single repl. You can search for a list of available packages here.

The replit.nix file should look something like the example below. The deps array specifies which Nix packages you would like to be available in your environment.

{ pkgs }: {
    deps = [
        pkgs.cowsay
    ];
}

Learn More About Nix

If you'd like to learn more about Nix, here are some great resources:

Written Guides

Video Guides

  • Nixology — A series of videos introducing Nix in a practical way
  • Taking the Nix pill — An introduction to what Nix is, how it works, and a walkthrough of publishing several new languages to Replit within an hour.
  • Nix: A Deep Dive — A deep dive on Nix: what Nix is, why you should use it, and how it works.

.replit

The .replit file allows you to configure many options for your repl, most basic of which is the run command.

Check out how to use the .replit file to configure a repl to enable Clojure:

<iframe width="640" height="400" style="margin-bottom: 10px;" src="https://www.loom.com/embed/cbe1f74399c546c38e0c1871893816c5" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

.replit files follow the toml configuration format and look something like this:

# The command that is executed when the run button is clicked.
run = ["cargo", "run"]

# The default file opened in the editor.
entrypoint = "src/main.rs"

# Setting environment variables
[env]
FOO="foo"

# Packager configuration for the Universal Package Manager
# See https://github.com/replit/upm for supported languages.
[packager]
language = "rust"

  [packager.features]
  # Enables the package search sidebar
  packageSearch = true
  # Enabled package guessing
  guessImports = false

# Per language configuration: language.<lang name> 
[languages.rust]
# The glob pattern to match files for this programming language
pattern = "**/*.rs"

    # LSP configuration for code intelligence
    [languages.rust.languageServer]
    start = ["rust-analyzer"]

In the code above, the strings in the array assigned to run are executed in order in the shell whenever you hit the "Run" button.

The language configuration option helps the IDE understand how to provide features like packaging and code intelligence.

And the [languages.rust] pattern option is configured so that all files ending with .rs are treated as Rust files. The name is user-defined and doesn't have any special meaning, we could have used [languages.rs] instead.

We can now set up a language server specifically for Rust. Which is what we do with the next configuration option: [languages.rust.languageServer]. Language servers add smart features to your editor like code intelligence, go-to-definition, and documentation on hover.

Since repls are fully configurable, you're not limited to just one language. For example, you could install Clojure and its language server using replit.nix, add a [languages.clojure] configuration option to the above .replit file that matched all Clojure files and have code intelligence enabled for both languages in the same repl.

.replit reference

A Command can either be a string or a list of strings. If the Command is a string ("node index.js"), it will be executed via sh -c "<Command>". If the Command is a list of strings (["node", "index.js"]), it will be directly executed with the list of strings passed as arguments. When possible, it is preferred to pass a list of strings.

  • run
    • Type: Command
    • Description: The command to run the repl.
  • entrypoint
    • Type: string
    • Description: The name of the main file including the extension. This is the file that will be run, and shown by default when opening the editor.
  • onBoot
    • Type: Command
    • Description: The command that executes after your repl has booted.
  • compile
    • Type: Command
    • Description: The shell command to compile the repl before the run command. Only for compiled languages like C, C++, and Java.
  • audio
    • Type: boolean
    • Description: Enables system-wide audio for the repl when configured to true.
  • language
    • Type: string
    • Description: Reserved. During a GitHub import, this tells the workspace which language should be used when creating the repl. For new repls, this option will always be Nix, so this field should generally not be touched.
  • [env]
    • Description: Set environment variables. Don't put secrets here—use the Secrets tab in the left sidebar.
    • Example: VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
  • interpreter
    • Description: Specifies the interpreter, which should be a compliant prybar binary.
    • command
      • Type: [string]
      • Description: This is the command that will be run to start the interpreter. It has higher precedence than the run command (i.e. interpreter command will run instead of the run command).
    • prompt
      • Type: [byte]
      • Description: This is the prompt used to detect running state, if unspecified it defaults to [0xEE, 0xA7].
  • [unitTest]
    • Enables unit testing to the repl.
    • language
      • Type: string
      • Description: The language you want the unit tests to run. Supported strings: java, python, and nodejs.
  • [packager]
    • Description: Package management configuration. Learn more about installing packages here.
    • afterInstall
      • Type: Command
      • Description: The command that is executed after a new package is installed.
    • ignoredPaths
      • Type: [string]
      • Description: List of paths to ignore while attempting to guess packages.
    • ignoredPackages
      • Type: [string]
      • Description: List of modules to never attempt to guess a package for, when installing packages.
    • language
      • Type: string
      • Description: Specifies the language to use for package operations. See available languages in the Universal Package Manager repository.
    • [packager.features]
      • Description: UPM features that are supported by the specified languages.
        • packageSearch
          • Type: Boolean
          • Description: When set to true, enables a package search panel in the sidebar.
        • guessImports
          • Type: Boolean
          • Description: When set to true, UPM will attempt to guess which packages need to be installed prior to running the repl.
  • [languages.<language name>]
    • Description: Per-language configuration. The language name has no special meaning other than to allow multiple languages to be configured at once.
    • pattern
      • Type: string
      • Description: A glob used to identify which files belong to this language configuration (**/*.js)
    • syntax
      • Type: string
      • Description: The language to use for syntax highlighting.
    • [languages.<language name>.languageServer]
      • Description: Configuration for setting up LSP for this language. This allows for code intelligence (autocomplete, underlined errors, etc...).
      • start
        • Type: Command
        • Description: The command used to start the LSP server for the specified language.
  • [nix]
    • Description: Where you specify a Nix channel.
    • channel
      • Type: string
      • Description: A nix channel id.
  • [debugger]
    • Description: Advanced users only. See field types & docstrings here, and in the advanced section below.

Example configurations

Beginner

Advanced

About

Advent of Code 2022

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published