Git Product home page Git Product logo

jcf-cli's Introduction

Jedi Code Formatter CLI

I took Jedi Code Formatter (JCF) from Lazarus IDE repository and made it as CLI (command line interface) version by removing all the GUI (graphical user interface) parts from the original GUI version. The CLI version can be used as Pascal code formatter in Visual Studio Code, or as backend engine of an online Pascal code beautifier.

How To Build Using Lazarus

  1. You must have Lazarus IDE already installed on your system.
  2. Clone or download this jcf-cli GitHub repo into your own folder.
  3. Start your Lazarus IDE and open jcf.lpi project within jcf-cli/CommandLine/Lazarus folder.
  4. Build it via Lazarus' RunBuild menu.
  5. Wait while Lazarus is building the JCF project.
  6. Take the executable JCF file from jcf-cli/Output/Lazarus folder along with the jcf.xml configuration file.
  7. Just to make sure, test it from Terminal using ./JCF -? command. It should show the usage manual.

How To Build Using VS Code

  1. You must have both Free Pascal compiler and VS Code already installed on your system.
  2. Clone or download this jcf-cli GitHub repo into your own folder.
  3. Start your VS Code and open jcf.lpr project within jcf-cli/CommandLine/Lazarus folder.
  4. Build it via VS Code's TasksRun Task...JCF: Build Release menu.
  5. Wait while FPC is building the JCF project.
  6. Open test.pas file from jcf-cli folder.
  7. Test JCF program using TasksRun Task...JCF: Test CLI Program menu and you should see the result in the test.pas file.

Note: I've included the executable file for Linux, Mac, and Windows in Output/Lazarus folder so you don't need to build it yourself. However, it's not guaranteed using the latest modification. 😊

How To Use JCF in VS Code

  1. Copy the JCF and jcf.xml config files into your Pascal workspace folder.
  2. Create a new VS Code task or open the tasks.json if you already have one.
  3. Copy the task example below and paste it into your tasks.json file.
{
  "label"  : "JCF: Beautify Code",
  "type"   : "shell",
  "command": "./JCF",
  "args": [
    "${file}",
    "-clarify",
    "-inplace",
    "-config=jcf.xml"
  ],
  "presentation": {
    "reveal": "never"
  },
  "problemMatcher": []
},
  1. It's a task to beautify Pascal code.
  2. If you need a task to obfuscate code, simply make another task using the code above, but then change -clarify arg into -obfuscate.
  3. Save your tasks.json. Now you should have new JCF's tasks in your tasks list.

The Problem With JCF

Although JCF is a good Pascal code formatter, it has one single problem that quite annoying. JCF requires the code must be compilable which means it has to be a complete program and syntactically correct. JCF will fail on code snippets or wrong code. To make it works on code snippet, it must be put between a begin..end pair and has a correct program header, like this:

program test;

begin
  // put code snippet here
end.

Demo

Here's JCF CLI in action within VS Code (with OmniPascal):

Note: If you're also interested in my other tasks shown in the demo, see my gist about it here.

Hope it's gonna be useful to other Pascal fellows out there. Have fun! 😊

jcf-cli's People

Contributors

git-bee avatar luridarmawan avatar paklebah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jcf-cli's Issues

Communication via StdIn/StdOut

I'd like to start a separate VSCode extension (entirely open source) that will use jcf-cli.
Right now, jcf-cli reads a file from the filesystem, formats its contents and writes it back.

That's not the best solution for a code formatter running in the background of a code editor. Biggest drawback is the fact that jcf-cli is unable to format dirty files.

That's why I would like to send the current file content via StdIn to jcf-cli and expect to get the formatted result returned in StdOut.

That way we could format dirty files without running into conflicts with the editor.

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.