Giter VIP home page Giter VIP logo

vscode-custom-code-decorator's Introduction

Custom Code Decorator for VSCode

Create your own, customized, per-project code decorators, simpy putting a .vslinter.js file in your project!

Sometimes certain projects may need custom code analysis that could not be mapped in a generic way.

No worries, now create your own!

Here's an example .vslinter.js file that colors the word "cat" in your code and writes "Meow~" as a description:

module.exports = {
	// Defining style
  style(vscode) {
    return {
      borderWidth: '1px',
      borderStyle: 'dotted',
      overviewRulerColor: 'red',
      overviewRulerLane: vscode.OverviewRulerLane.Right,
      light: { borderColor: 'lightred' },
      dark: { borderColor: 'darkred' },
    };
  },
	// Matching the word "cat" and colorize it, adding a hoverMessage "Meow~"
  lint(document, rangesToDecorate) {
    const regex = /\scat\s/g
    const text = document.getText();
    let match = regex.exec(text);

    while (match) {
      const decoration = {
        'range': [match.index + 1, match.index + match[0].length - 1],
        'hoverMessage': 'Meow~'
      };
      rangesToDecorate.push(decoration);
      match = regex.exec(text);
    }
  }
}

Here's the result:

Some use cases:

  • Defining custom linters for the current project
  • Validating JSON files using custom JSON schemas
  • Custom security requirements for a project
  • Resolving names and suggesting similar elements

Install it on VS Code: https://marketplace.visualstudio.com/items?itemName=monade.vscode-custom-code-decorator

Future work / Suggestions:

https://github.com/monade/vscode-custom-code-decorator/issues

If you want to experiment with the source code:

  • (do the usual steps to download from GitHub and navigate to folder)
  • npm install (just once inside the folder)
  • npm run watch (every time you want to test it)
  • open folder in VS Code and hit F5 or go to Debug and click on the green triangle play button

The key file to edit is extension.ts (in the src folder).

Special Thanks

The initial idea and part of the code comes from this plugin: https://github.com/hchiam/custom-vscode-linter

vscode-custom-code-decorator's People

Contributors

progm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

disco0

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.