beautifiers: Add support for Verilog/SystemVerilog beautification

Signed-off-by: Andrew Andrianov <andrew@ncrmnt.org>
This commit is contained in:
Andrew Andrianov 2017-12-06 14:54:50 +03:00
parent 25a9ee8699
commit 6db872294e
14 changed files with 349 additions and 5 deletions

View File

@ -1,6 +1,7 @@
# Next # Next
- Fix [#1862](https://github.com/Glavin001/atom-beautify/issues/1862) Add support for ocp-indent as an executable - Fix [#1862](https://github.com/Glavin001/atom-beautify/issues/1862) Add support for ocp-indent as an executable
- See [#601](https://github.com/Glavin001/atom-beautify/issues/1862) Add support for tsx files - See [#601](https://github.com/Glavin001/atom-beautify/issues/1862) Add support for tsx files
- Implement Verilog/SystemVerilog beautification via emacs verilog-mode
# v0.30.9 (2017-11-22) # v0.30.9 (2017-11-22)
- Fix [#1949](https://github.com/Glavin001/atom-beautify/issues/1949): Fix beautify on save when text has not changed. - Fix [#1949](https://github.com/Glavin001/atom-beautify/issues/1949): Fix beautify on save when text has not changed.

View File

@ -99,6 +99,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall
| CSScomb | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | | CSScomb | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! |
| dfmt | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [Dfmt (`dfmt`)](https://github.com/Hackerpilot/dfmt) by following https://github.com/dlang-community/dfmt#building<br/> | | dfmt | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [Dfmt (`dfmt`)](https://github.com/Hackerpilot/dfmt) by following https://github.com/dlang-community/dfmt#building<br/> |
| elm-format | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [elm-format (`elm-format`)](https://github.com/avh4/elm-format) with `docker pull unibeautify/elm-format`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [elm-format (`elm-format`)](https://github.com/avh4/elm-format) by following https://github.com/avh4/elm-format#installation-<br/> | | elm-format | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [elm-format (`elm-format`)](https://github.com/avh4/elm-format) with `docker pull unibeautify/elm-format`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [elm-format (`elm-format`)](https://github.com/avh4/elm-format) by following https://github.com/avh4/elm-format#installation-<br/> |
| Emacs Verilog Mode | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [Emacs (`emacs`)](https://www.gnu.org/software/emacs/) by following https://www.gnu.org/software/emacs/<br/> |
| erl_tidy | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to http://erlang.org/doc/man/erl_tidy.html and follow the instructions. | | erl_tidy | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to http://erlang.org/doc/man/erl_tidy.html and follow the instructions. |
| ESLint Fixer | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | | ESLint Fixer | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! |
| formatR | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) with `docker pull unibeautify/rscript`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) by following https://github.com/yihui/formatR<br/> | | formatR | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) with `docker pull unibeautify/rscript`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) by following https://github.com/yihui/formatR<br/> |
@ -204,6 +205,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti
| TypeScript | `TypeScript` |`.ts` | **[`TypeScript Formatter`](https://github.com/vvakame/typescript-formatter)** | | TypeScript | `TypeScript` |`.ts` | **[`TypeScript Formatter`](https://github.com/vvakame/typescript-formatter)** |
| UX Markup | `UX` |`.ux` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** | | UX Markup | `UX` |`.ux` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| Vala | `Vala` |`.vala`, `.vapi` | **[`Uncrustify`](https://github.com/uncrustify/uncrustify)** | | Vala | `Vala` |`.vala`, `.vapi` | **[`Uncrustify`](https://github.com/uncrustify/uncrustify)** |
| Verilog | `Verilog` |`.svh`, `.v`, `.sv` | **[`Emacs Verilog Mode`](https://www.veripool.org/projects/verilog-mode/)** |
| Visualforce | `Visualforce` |`.page` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** | | Visualforce | `Visualforce` |`.page` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| Vue | `Vue Component` |`.vue` | **[`Vue Beautifier`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/vue-beautifier.coffee)** | | Vue | `Vue Component` |`.vue` | **[`Vue Beautifier`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/vue-beautifier.coffee)** |
| XML | `SLD`, `XML`, `XHTML`, `XSD`, `XSL`, `JSP`, `GSP` |`.sld`, `.xml`, `.xhtml`, `.xsd`, `.xsl`, `.jsp`, `.gsp`, `.plist`, `.recipe`, `.config` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)**, [`JS Beautify`](https://github.com/beautify-web/js-beautify) | | XML | `SLD`, `XML`, `XHTML`, `XSD`, `XSL`, `JSP`, `GSP` |`.sld`, `.xml`, `.xhtml`, `.xsd`, `.xsl`, `.jsp`, `.gsp`, `.plist`, `.recipe`, `.config` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)**, [`JS Beautify`](https://github.com/beautify-web/js-beautify) |

View File

@ -13851,6 +13851,100 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify)
} }
``` ```
#### [Verilog](#verilog)
**Supported Beautifiers**: [`Emacs Verilog Mode`](#emacs-verilog-mode)
| Option | Emacs Verilog Mode |
| --- | --- |
| `disabled` | :white_check_mark: |
| `default_beautifier` | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: |
| `emacs_script_path` | :white_check_mark: |
**Description**:
Options for language Verilog
##### [Disable Beautifying Language](#disable-beautifying-language)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Type**: `boolean`
**Description**:
Disable Verilog Beautification
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Disable Beautifying Language*" and change it to your desired configuration.
##### [Default Beautifier](#default-beautifier)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Default**: `Emacs Verilog Mode`
**Type**: `string`
**Enum**: `Emacs Verilog Mode`
**Description**:
Default Beautifier to be used for Verilog
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Default Beautifier*" and change it to your desired configuration.
##### [Beautify On Save](#beautify-on-save)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Type**: `boolean`
**Description**:
Automatically beautify Verilog files on save
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Beautify On Save*" and change it to your desired configuration.
##### [Emacs script path](#emacs-script-path)
**Namespace**: `verilog`
**Key**: `emacs_script_path`
**Type**: `string`
**Supported Beautifiers**: [`Emacs Verilog Mode`](#emacs-verilog-mode)
**Description**:
Path to emacs init.el script with formatting settings. (Leave blank to use default one) (Supported by Emacs Verilog Mode)
**Example `.jsbeautifyrc` Configuration**
```json
{
"verilog": {
"emacs_script_path": ""
}
}
```
#### [Visualforce](#visualforce) #### [Visualforce](#visualforce)
**Supported Beautifiers**: [`Pretty Diff`](#pretty-diff) **Supported Beautifiers**: [`Pretty Diff`](#pretty-diff)
@ -16183,6 +16277,33 @@ Override EOL from line-ending-selector (Supported by Coffee Formatter)
``` ```
### Emacs Verilog Mode
##### [Emacs script path](#emacs-script-path)
**Namespace**: `verilog`
**Key**: `emacs_script_path`
**Type**: `string`
**Supported Beautifiers**: [`Emacs Verilog Mode`](#emacs-verilog-mode)
**Description**:
Path to emacs init.el script with formatting settings. (Leave blank to use default one) (Supported by Emacs Verilog Mode)
**Example `.jsbeautifyrc` Configuration**
```json
{
"verilog": {
"emacs_script_path": ""
}
}
```
### Fortran Beautifier ### Fortran Beautifier
##### [Emacs path](#emacs-path) ##### [Emacs path](#emacs-path)

View File

@ -0,0 +1,33 @@
// Testbench
module test;
reg clk;
reg reset;
reg d;
wire q;
wire qb;
// Instantiate design under test
dff DFF(.clk(clk), .reset(reset),
.d(d), .q(q), .qb(qb));
initial begin
// Dump waves
$dumpfile("dump.vcd");
$dumpvars(1);
$display("Reset flop.");
clk = 0;
reset = 1;
d = 1'bx;
display;
$display("Release reset.");
d = 1;
reset = 0;
display;
$display("Toggle clk.");
clk = 1;
display;
end
task display;
#1 $display("d:%0h, q:%0h, qb:%0h",
d, q, qb);
endtask
endmodule

View File

@ -0,0 +1,33 @@
// Testbench
module test;
reg clk;
reg reset;
reg d;
wire q;
wire qb;
// Instantiate design under test
dff DFF(.clk(clk), .reset(reset),
.d(d), .q(q), .qb(qb));
initial begin
// Dump waves
$dumpfile("dump.vcd");
$dumpvars(1);
$display("Reset flop.");
clk = 0;
reset = 1;
d = 1'bx;
display;
$display("Release reset.");
d = 1;
reset = 0;
display;
$display("Toggle clk.");
clk = 1;
display;
end
task display;
#1 $display("d:%0h, q:%0h, qb:%0h",
d, q, qb);
endtask
endmodule

View File

@ -150,6 +150,10 @@
{ {
"name": "Steven Zeck", "name": "Steven Zeck",
"url": "https://github.com/szeck87" "url": "https://github.com/szeck87"
},
{
"name": "Andrew Andrianov",
"url": "https://github.com/nekromant"
} }
], ],
"engines": { "engines": {
@ -278,7 +282,8 @@
"atom-beautify:beautify-language-xtemplate", "atom-beautify:beautify-language-xtemplate",
"atom-beautify:beautify-language-yaml", "atom-beautify:beautify-language-yaml",
"atom-beautify:beautify-language-terraform", "atom-beautify:beautify-language-terraform",
"atom-beautify:beautify-language-tsx" "atom-beautify:beautify-language-tsx",
"atom-beautify:beautify-language-verilog"
], ],
".tree-view .file .name": [ ".tree-view .file .name": [
"atom-beautify:beautify-file" "atom-beautify:beautify-file"
@ -414,7 +419,9 @@
"goimports", "goimports",
"terraform", "terraform",
"terraformfmt", "terraformfmt",
"tsx" "tsx",
"verilog",
"emacs verilog mode"
], ],
"devDependencies": { "devDependencies": {
"coffeelint": "1.16.0" "coffeelint": "1.16.0"
@ -451,4 +458,4 @@
"prettydiff2" "prettydiff2"
] ]
} }
} }

View File

@ -130,7 +130,7 @@ class Executable
Run command-line interface command Run command-line interface command
### ###
run: (args, options = {}) -> run: (args, options = {}) ->
@debug("Run: ", @cmd, args, options) console.log("Run: ", @cmd, args, options)
{ cmd, cwd, ignoreReturnCode, help, onStdin, returnStderr, returnStdoutOrStderr } = options { cmd, cwd, ignoreReturnCode, help, onStdin, returnStderr, returnStdoutOrStderr } = options
exeName = cmd or @cmd exeName = cmd or @cmd
cwd ?= os.tmpdir() cwd ?= os.tmpdir()

View File

@ -36,7 +36,7 @@ module.exports = class FortranBeautifier extends Beautifier
emacs_script_path = path.resolve(__dirname, "emacs-fortran-formating-script.lisp") emacs_script_path = path.resolve(__dirname, "emacs-fortran-formating-script.lisp")
@debug('fortran-beautifier', 'emacs script path: ' + emacs_script_path) @debug('fortran-beautifier', 'emacs script path: ' + emacs_script_path)
args = [ args = [
'--batch' '--batch'
'-l' '-l'

View File

@ -81,6 +81,7 @@ module.exports = class Beautifiers extends EventEmitter
'formatR' 'formatR'
'beautysh' 'beautysh'
'terraformfmt' 'terraformfmt'
'verilog-mode'
] ]
### ###

View File

@ -0,0 +1,57 @@
###
Requires emacs with verilog-mode https://www.veripool.org/wiki/verilog-mode
###
"use strict"
Beautifier = require('../beautifier')
path = require("path")
module.exports = class EmacsVerilogMode extends Beautifier
name: "Emacs Verilog Mode"
link: "https://www.veripool.org/projects/verilog-mode/"
isPreInstalled: false
executables: [
{
name: "Emacs"
cmd: "emacs"
homepage: "https://www.gnu.org/software/emacs/"
installation: "https://www.gnu.org/software/emacs/"
version: {
parse: (text) -> text.match(/Emacs (\d+\.\d+\.\d+)/)[1]
}
}
]
options: {
Verilog: {
emacs_script_path: true
}
}
beautify: (text, language, options) ->
emacs_script_path = options.emacs_script_path
if not emacs_script_path
emacs_script_path = path.resolve(__dirname, "verilog-mode.el")
@debug('verilog-beautifier', 'emacs script path: ' + emacs_script_path)
tempFile = @tempFile("input", text)
args = [
"--batch"
tempFile
"-l"
emacs_script_path
"-f"
"verilog-mode"
"-f"
"verilog-batch-indent"
]
@debug('verilog-beautifier', 'emacs args: ' + args)
@exe("emacs").run(args, {ignoreReturnCode: false})
.then(=>
@readFile(tempFile)
)

View File

@ -0,0 +1,3 @@
(add-hook 'verilog-mode-hook '(lambda ()
(add-hook 'local-write-file-hooks (lambda()
(untabify (point-min) (point-max))))))

View File

@ -79,6 +79,7 @@ module.exports = class Languages
"xtemplate" "xtemplate"
"yaml" "yaml"
"terraform" "terraform"
"verilog"
] ]
### ###

View File

@ -0,0 +1,28 @@
module.exports = {
name: "Verilog"
namespace: "verilog"
###
Supported Grammars
###
grammars: [
"Verilog"
]
###
Supported extensions
###
extensions: [
"svh"
"v"
"sv"
]
options:
emacs_script_path:
type: 'string'
default: ""
description: "Path to emacs init.el script with formatting settings. (Leave blank to use default one)"
}

View File

@ -9210,6 +9210,63 @@
} }
} }
}, },
"verilog": {
"title": "Verilog",
"type": "object",
"description": "Options for language Verilog",
"collapsed": true,
"beautifiers": [
"Emacs Verilog Mode"
],
"grammars": [
"Verilog"
],
"extensions": [
"svh",
"v",
"sv"
],
"properties": {
"emacs_script_path": {
"type": "string",
"default": "",
"description": "Path to emacs init.el script with formatting settings. (Leave blank to use default one) (Supported by Emacs Verilog Mode)",
"title": "Emacs script path",
"beautifiers": [
"Emacs Verilog Mode"
],
"key": "emacs_script_path",
"language": {
"name": "Verilog",
"namespace": "verilog"
}
},
"disabled": {
"title": "Disable Beautifying Language",
"order": -3,
"type": "boolean",
"default": false,
"description": "Disable Verilog Beautification"
},
"default_beautifier": {
"title": "Default Beautifier",
"order": -2,
"type": "string",
"default": "Emacs Verilog Mode",
"description": "Default Beautifier to be used for Verilog",
"enum": [
"Emacs Verilog Mode"
]
},
"beautify_on_save": {
"title": "Beautify On Save",
"order": -1,
"type": "boolean",
"default": false,
"description": "Automatically beautify Verilog files on save"
}
}
},
"executables": { "executables": {
"title": "Executables", "title": "Executables",
"type": "object", "type": "object",