GithubHelp home page GithubHelp logo

alexzhang1030 / ast-grep-vscode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ast-grep/ast-grep-vscode

0.0 0.0 0.0 3.94 MB

ast-grep VSCode is a structural search and replace extension for many languages.

Home Page: https://marketplace.visualstudio.com/items?itemName=ast-grep.ast-grep-vscode

License: MIT License

Shell 0.08% JavaScript 3.78% TypeScript 93.16% CSS 2.98%

ast-grep-vscode's Introduction

ast-grep VSCode

ast-grep VSCode, a structural search and replace extension.

It uses ASTs to find and modify code patterns. No more tedious and error-prone text manipulation.

Introduction

Have you ever spent hours trying to find and replace a code pattern using plain text or regular expressions? If so, you know how tedious and error-prone it can be. However, there is a better way to do this: Structural Search and Replace, a technique that allows you to find and modify code patterns based on their syntax and semantics, not just their text.

ast-grep is a structural search/replace tool that uses abstract syntax trees (ASTs) to represent the syntax and structure of your code, and lets you write patterns as if you are writing ordinary code.

It can help you search and replace code elements more precisely and efficiently than using regular expressions or plain text. You can also use ast-grep to perform linting and rewriting tasks, and write your own rules using YAML configuration.

Features

The ast-grep VSCode is an extension to bridge the power of ast-grep and the beloved editor VSCode.

It includes two parts: a UI for ast-grep CLI and a client for ast-grep LSP.

Code search

Use pattern to structural search your codebase.

Search Pattern Search In Folder

Code Replace

Use pattern to replace matching code.

Replace Preview Commit Replace

Code Linting and Actions(*)

Require LSP setup

Code linting and code actions require setting up sgconfig.yml in your workspace root.

Requirements

# install via npm
npm i @ast-grep/cli -g

# install via cargo
cargo install ast-grep

# install via homebrew
brew install ast-grep

Also see the quickstart guide for installation.

  • (optional) setting up ast-grep project.

    This is an optional step to enable code linting and code actions. It requires at least one file and one folder to work:

You can also use the command line tool to set it up.

ast-grep new

Available Commands

  • ast-grep.restartLanguageServer Restart ast-grep langauge server. Useful to reload rule or configuration changes.

  • ast-grep.searchInFolder Find ast-grep pattern in the specified folder in a project.

  • ast-grep.executeAutofix Fix all auto-fixable Problems

Extension Settings

This extension contributes the following settings:

  • astGrep.serverPath: Specify the language server binary path. It can be a relative path to workspace root or an absolute path.

  • astGrep.serverPath: Customize ast-grep config file path relative. Default is sgconfig.yml

Video Introduction

See the introduction on YouTube! Please give it a like~

ast-grep-vscode's People

Contributors

herringtondarkholme avatar renovate[bot] avatar sooniter avatar stevenlove avatar iwanabethatguy avatar siguremo avatar unixzii avatar sevenoutman avatar simon-he95 avatar

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.