Code Monkey home page Code Monkey logo

tree-sitter-just's Introduction

tree-sitter-just

WIP: Tree-sitter grammar for Justfiles (casey/just)

To use treesitter based highlighting, folds etc. the queries need to be added to the runtimepath, until I get a PR into nvim-treesitter/nvim-treesitter you can install this repo as a plugin using Plug/packer/manual clone etc. This plugin also adds a simple ftdetect plugin for detecting

Packer:

use "IndianBoy42/tree-sitter-just"

Plug

Plug 'IndianBoy42/tree-sitter-just'

Manual

git clone https://github.com/IndianBoy42/tree-sitter-just ~/.local/share/nvim/site/pack/tree-sitter-queries/start/tree-sitter-just

You can then do require('tree-sitter-just').setup() to register the parser with tree-sitter. You can then do TSInstall/TSUpdate as usual to install the parser

You can also add the parser manually using (This is similar to what is done in require"tree-sitter-just".setup())

require("nvim-treesitter.parsers").get_parser_configs().just = {
  install_info = {
    url = "https://github.com/IndianBoy42/tree-sitter-just", -- local path or git repo
    files = { "src/parser.c", "src/scanner.cc" },
    branch = "main",
    -- use_makefile = true -- this may be necessary on MacOS (try if you see compiler errors)
  },
  maintainers = { "@IndianBoy42" },
}

Dont forget to :TSInstall after adding this. With this method you do not have to add this repo as a plugin If you run into problems relating to C++ 11 features, try including this in your setup (you may have to brew install gcc@11):

require"nvim-treesitter.install".compilers = {"gcc-11"}

Testing

Building locally:

npm run gen
npm run test
tree-sitter parse test/test.just

You can use the nvim-treesitter/playground plugin from here, to explore the resulting parse tree. Use TSPlaygroundToggle to view the parse tree, and use TSHighlightCapturesUnderCursor to view highlight groups

TODO

  • Implement a basic parser that is able to understand all features of Justfiles
  • Implement support for highlighting using nvim-treesitter (reference, highlights.scm)
    • Write the queries
    • Implement locals queries
  • Implement queries for textobjects compatible with nvim-treesitter/nvim-treesitter-textobjects
    • Write the queries
      • @block.inner|outer (recipe)
      • @function.inner|outer (recipe)
      • @call.inner|outer (dependencies)
      • @comment.outer
      • @parameter.inner|outer
      • @conditional.inner|outer
      • @statement.outer (recipe line or one variable)
    • Definitions and references
    • Scopenames
  • Implement support for indentation using nvim-treesitter
    • Write the queries
  • Implement support for code folding using nvim-treesitter (folds.scm)
    • Write the queries
  • Write Tests
  • Highlight the fish/bash/etc inside recipes (use tree-sitter injections)
  • Fix weirdness around trailing whitespace (dont leave trailing whitespace after the recipe header)

tree-sitter-just's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.