|
1 | 1 | [](https://travis-ci.org/SeeSharpSoft/intellij-csv-validator) |
2 | 2 | [](https://coveralls.io/github/SeeSharpSoft/intellij-csv-validator?branch=master) |
3 | | -# Lightweight CSV plugin for JetBrains IDE family |
| 3 | +# Lightweight CSV Plugin for JetBrains IDE family |
4 | 4 |
|
5 | | -Compatible with: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion Gogland DataGrip Rider MPS Android Studio - for Versions >= 2016.1 |
| 5 | +Compatible with _IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion Gogland DataGrip Rider MPS Android Studio_ - __2016.3.2 and newer__ |
6 | 6 |
|
7 | | -**Features:** |
| 7 | +This plugin introduces CSV (_Comma-Separated Values_) as a language to Jetbrains IDE with a syntax definition, structured language elements and associated file types (.csv/.tsv). |
| 8 | +This enables default editor features like syntax validation, highlighting and inspections for CSV files. |
8 | 9 |
|
9 | | -- CSV file detection |
| 10 | +## Features |
| 11 | + |
| 12 | +- CSV/TSV file detection |
10 | 13 | - syntax validation |
11 | 14 | - syntax highlighting (configurable) |
12 | 15 | - content formatting (configurable) |
13 | 16 | - quick fix inspections |
14 | | -- intentions, e.g. Quote/Unquote (all) |
| 17 | +- intentions (Alt+Enter), e.g. Quote/Unquote (all), Shift Column Left/Right |
15 | 18 | - structure view (header-entry layout) |
16 | | -- support for ',' or ';' as value separator |
| 19 | +- support for ',', ';', '|' and '↹' as value separator |
| 20 | + |
| 21 | +### Syntax parser & validation |
| 22 | + |
| 23 | +The CSV syntax parser follows the standard defined in [IETF 4180](https://www.ietf.org/rfc/rfc4180.txt) but tolerates leading and trailing whitespaces of escaped text and accepts basically every literal as text data. |
| 24 | +This results in a less restrictive checks and contributes to the flexibility of this format. |
| 25 | +The goal of the plugin is to support editing files in CSV format, not introducing new hurdles. |
| 26 | + |
| 27 | +Being strict, the following CSV snippet is actually incorrect cause of the leading whitespaces. However, it is accepted by the plugins syntax parser implementation: |
| 28 | + |
| 29 | +``` |
| 30 | +"firstName", "lastName", "birthday" |
| 31 | +``` |
| 32 | +Besides the mentioned diversion from the standard definition, syntax errors will be detected and can be inspected. |
| 33 | +Please note that if a document is syntactically incorrect, other features like code formatting or the structure view can not function properly. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +### Highlighting |
| 38 | + |
| 39 | +The different symbols of a CSV document, namely the separator (comma), the quotes, the escaped literals and the text elements itself, are highlighted by a coloring scheme that can be customized: |
| 40 | + |
| 41 | +- _File > Settings > Editor > Color Scheme > CSV_ |
| 42 | + |
| 43 | +Preset colors are based on Jetbrains IDE defaults and support the different UI themes. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +### Separator |
| 48 | + |
| 49 | +CSV files provide a high degree of flexibility and can be used universally for all kind of data. |
| 50 | +This led to a variety of CSV derivatives like semicolon or pipe separated values, which share the common format but make use of a different separator. |
| 51 | + |
| 52 | +The plugin supports project specific separator setting. |
| 53 | +New separators can be added fairly easy in the parser definition of the source code. |
| 54 | + |
| 55 | +#### TSV |
| 56 | + |
| 57 | +Tab (↹) can be explicitly set as a separator for CSV files. |
| 58 | +Additionally the file type TSV was introduced as a kind of CSV language. |
| 59 | +For TSV files the same formatter and code style settings are applied as for CSV itself, but the separator is considered to be a tab. |
| 60 | +All functionality that is available for plain CSV files (inspections, intentions, structure view, etc.) can be used for TSV as well. |
| 61 | + |
| 62 | +### Formatting |
| 63 | + |
| 64 | +- _File > Settings > Editor > Code Style > CSV_ |
| 65 | + |
| 66 | +Formatting CSV is tricky: On one hand it is easy cause the language has only four different symbols and is generally easy to handle. |
| 67 | +On the other hand, formatting elements like whitespaces and tabs do have a meaning in CSV. |
| 68 | +However, in reality when parsing CSV, the leading and trailing whitespaces are quite often ignored or trimmed. |
| 69 | +Formatting can be completely disabled if no option is selected at all at the settings screen. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +#### Formatting options |
| 74 | + |
| 75 | +The formatting examples are based on the following CSV snippet as input: |
| 76 | + |
| 77 | +``` |
| 78 | +"name", "city", "position" |
| 79 | +Annasusanna,Amsterdam,1 |
| 80 | + Ben , Berlin , 2 |
| 81 | +``` |
| 82 | + |
| 83 | +##### Separator |
| 84 | + |
| 85 | +The following separators are currently supported: ',', ';', '|' and '↹' |
| 86 | + |
| 87 | +When changing the separator, press the apply button to refresh the preview window properly. |
| 88 | + |
| 89 | +_Space before separator_ |
| 90 | + |
| 91 | +``` |
| 92 | +"name" , "city" , "position" |
| 93 | +Annasusanna ,Amsterdam ,1 |
| 94 | + Ben , Berlin , 2 |
| 95 | +``` |
| 96 | + |
| 97 | +_Space after separator_ |
| 98 | + |
| 99 | +``` |
| 100 | +"name", "city", "position" |
| 101 | +Annasusanna, Amsterdam, 1 |
| 102 | + Ben , Berlin , 2 |
| 103 | +``` |
| 104 | + |
| 105 | +##### Trimming |
| 106 | + |
| 107 | +Trimming can be combined with _Space before/after separator_. |
| 108 | + |
| 109 | +_Trim leading whitespaces_ |
| 110 | + |
| 111 | +``` |
| 112 | +"name","city","position" |
| 113 | +Annasusanna,Amsterdam,1 |
| 114 | +Ben ,Berlin ,2 |
| 115 | +``` |
| 116 | + |
| 117 | +_Trim trailing whitespaces_ |
| 118 | + |
| 119 | +``` |
| 120 | +"name", "city", "position" |
| 121 | +Annasusanna,Amsterdam,1 |
| 122 | + Ben, Berlin, 2 |
| 123 | +``` |
| 124 | + |
| 125 | +##### Tabularize enabled _(default)_ |
| 126 | + |
| 127 | +Please note: The separator settings can be used in combination with Tabularize enabled, while trimming options are ignored. |
| 128 | + |
| 129 | +``` |
| 130 | +"name ","city ","position" |
| 131 | +Annasusanna,Amsterdam,1 |
| 132 | +Ben ,Berlin ,2 |
| 133 | +``` |
| 134 | + |
| 135 | +_Trimming/spacing outside quotes_ |
| 136 | + |
| 137 | +``` |
| 138 | +"name" ,"city" ,"position" |
| 139 | +Annasusanna,Amsterdam,1 |
| 140 | +Ben ,Berlin ,2 |
| 141 | +``` |
| 142 | + |
| 143 | +_Leading whitespaces_ |
| 144 | + |
| 145 | +``` |
| 146 | +" name"," city","position" |
| 147 | +Annasusanna,Amsterdam, 1 |
| 148 | + Ben, Berlin, 2 |
| 149 | +``` |
| 150 | + |
| 151 | +_Trimming/spacing outside quotes & Leading whitespaces_ |
| 152 | + |
| 153 | +``` |
| 154 | + "name", "city","position" |
| 155 | +Annasusanna,Amsterdam, 1 |
| 156 | + Ben, Berlin, 2 |
| 157 | +``` |
| 158 | + |
| 159 | +### Inspections |
| 160 | + |
| 161 | +- _File > Settings > Editor > Inspections > CSV_ |
| 162 | + |
| 163 | +Inspections are an IDE feature that can be used to fix syntax errors. |
| 164 | +They are accessed via _Alt+Enter_ when the cursor is at an erroneous position. |
| 165 | +The plugin provides three types of inspections: |
| 166 | + |
| 167 | +- **Surround with quotes** Surrounds the current field with quotes and escapes already existing ones |
| 168 | +- **Add separator** Adds a (missing) separator at the cursor position |
| 169 | +- **Add closing quote** Adds a (missing) closing quote at the end of the document |
| 170 | + |
| 171 | +### Intentions |
| 172 | + |
| 173 | +- _File > Settings > Editor > Intentions > CSV_ |
| 174 | + |
| 175 | +Intentions are similar to inspections and provide a quick way to automatically adjust the document. |
| 176 | +They are accessed via _Alt+Enter_ at any time. The shown intentions can vary depending on the cursor position within the document. |
| 177 | +The plugin provides six types of intentions: |
| 178 | + |
| 179 | +- **Quote All** Surrounds all unquoted fields with quotes |
| 180 | +- **Quote Value** Quotes the currently unquoted value at the cursor position |
| 181 | +- **Unquote All** Unquotes all quoted fields if possible |
| 182 | +- **Unquote Value** Unquotes the currently quoted value at the cursor position if possible |
| 183 | +- **Shift Column Left** Shifts the column at cursor position to the left |
| 184 | +- **Shift Column Right** Shifts the column at cursor position to the right |
| 185 | + |
| 186 | +### Structure View |
| 187 | + |
| 188 | +- _View > Tool Windows > Structure_ |
| 189 | + |
| 190 | +The structure view shows the first line of the currently opened CSV file as header. |
| 191 | +Expanding a header entry shows all entries in this column. |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | +## Installation |
| 196 | + |
| 197 | +Install it from the Jetbrains plugin repository within your IDE (**recommended**): |
| 198 | + |
| 199 | +- _File > Settings > Plugins > Browse repositories... > Search 'CSV Plugin' > Category 'Editor'_ |
| 200 | + |
| 201 | +You can also download the JAR package from the [Jetbrains plugin repository](https://plugins.jetbrains.com/plugin/10037-csv-plugin) or from [GitHub Releases](https://github.com/SeeSharpSoft/intellij-csv-validator/releases) and add it manually to your plugins: |
| 202 | + |
| 203 | +- _File > Settings > Plugins > Install plugin from disk..._ |
| 204 | + |
| 205 | +## Contribution |
| 206 | + |
| 207 | +Contributions are welcome. Please check [CONTRIBUTING.md](./CONTRIBUTING.md) for more information. |
| 208 | + |
| 209 | +Besides source code contributions, feel free to open bug reports or just suggest new features [here](https://github.com/SeeSharpSoft/intellij-csv-validator/issues). |
| 210 | + |
| 211 | +## FAQ |
| 212 | + |
| 213 | +> Where is the table editor? |
| 214 | +
|
| 215 | +The initial intention of this plugin was the usage of the built-in text-editor features (e.g. validation, highlighting, formatting, etc) for CSV files. |
| 216 | +Providing an own editor was not planned at all. |
| 217 | +Still, it's just a matter of time and effort that needs to be invested for the implementation. |
| 218 | +Feel free to contribute to [make this dream come true](https://github.com/SeeSharpSoft/intellij-csv-validator/issues/2). |
| 219 | + |
| 220 | +Please note that there is a table like editor available in [IntelliJ IDEA Ultimate/PhpStorm/DataGrip/etc.](https://www.jetbrains.com/help/phpstorm/editing-csv-and-tsv-files.html) |
| 221 | +It is a well thought-through component and worth giving it a try if a CSV table editor is a necessity in your daily work. |
| 222 | +This plugin is fully compatible with this feature. |
| 223 | + |
| 224 | +> Why can't I choose the separator freely? |
| 225 | +
|
| 226 | +Having clearly defined symbols enables the syntax parser and language lexer to do its job properly. |
| 227 | +The code for those is generated during build time by using the [Grammar-Kit](https://github.com/JetBrains/Grammar-Kit). |
| 228 | +Adding a new kind of separator during development is fairly easy (please feel free to request a new commonly used one) in comparison to the implementation effort and usefulness of a freely defined separator. |
| 229 | + |
17 | 230 |
|
| 231 | +## Jetbrains Repository |
18 | 232 |
|
19 | 233 | JetBrains Plugin Repository Link: https://plugins.jetbrains.com/plugin/10037-csv-plugin |
0 commit comments