Skip to content

Commit 1f5b996

Browse files
authored
Merge pull request #127 from SeeSharpSoft/master
Release 2.4.0
2 parents f9a5833 + 619f486 commit 1f5b996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+834
-125
lines changed

CHANGELOG

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
2.4.0
2+
May 11, 2019
3+
4+
NEW: option to keep/ignore a linebreak at the end of a file (table editor)
5+
NEW: improved change detection of table editor to avoid overwriting original text representation without editing any values
6+
NEW: file based value separator (e.g. ',' or ';')
7+
18
2.3.1
29
Mar 31, 2019
310

4-
NEW: use default color scheme font for table editor as well
11+
NEW: use default color scheme & font for table editor as well
512
FIX: ConcurrentModificationException tackled (table editor)
613

714
2.3.0

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Coverage Status](https://coveralls.io/repos/github/SeeSharpSoft/intellij-csv-validator/badge.svg?branch=master)](https://coveralls.io/github/SeeSharpSoft/intellij-csv-validator?branch=master)
44
[![Known Vulnerabilities](https://snyk.io/test/github/SeeSharpSoft/intellij-csv-validator/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/SeeSharpSoft/intellij-csv-validator?targetFile=build.gradle)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/97769359388e44bfb7101346d510fccf)](https://www.codacy.com/app/github_124/intellij-csv-validator?utm_source=github.com&utm_medium=referral&utm_content=SeeSharpSoft/intellij-csv-validator&utm_campaign=Badge_Grade)
6+
[![BCH compliance](https://bettercodehub.com/edge/badge/SeeSharpSoft/intellij-csv-validator?branch=master)](https://bettercodehub.com/results/SeeSharpSoft/intellij-csv-validator/)
67

78
# Lightweight CSV Plugin for JetBrains IDE family
89

@@ -147,6 +148,10 @@ Set whether soft wrapping should be activated for CSV/TSV. It still can be chang
147148

148149
Defines how many lines of text are shown in one editor cell by default. *Auto* does recalculate the height on the fly that can cause some flickering while editing. This setting can be changed in the table editor itself per file.
149150

151+
##### Keep/ignore linebreak at end of file
152+
153+
If the file ends with a completely empty line (no spaces or tabs either), the table editor will not show this line as empty values but ignore it. When table data is serialized, an existing empty line is kept at the end of the file.
154+
150155
##### Show info panel
151156

152157
Enables/disables the info panel at the bottom of the table editor.
@@ -202,6 +207,8 @@ Annasusanna,Amsterdam,1
202207

203208
The following separators are currently supported: **,** (Comma), **;** (Semicolon), **|** (Pipe) and **↹** (Tab)
204209

210+
_Value separator (default)_ defines which separator is used by default. The separator character can be changed for each CSV file individually.
211+
205212
When changing the separator, press the apply button to refresh the preview window properly.
206213

207214
_Space before separator_
@@ -274,6 +281,18 @@ Annasusanna,Amsterdam, 1
274281
Ben, Berlin, 2
275282
```
276283

284+
### Actions
285+
286+
#### File specific value separator
287+
288+
![Context menu](./docs/contextmenu.png)
289+
290+
The action to switch the value separator used for CSV syntax validation of a specific file is part of its text editors context menu.
291+
292+
293+
This action defines how the parser/validator/highlighter/etc. behaves. It does intentionally not change the file content.
294+
To be more precise: It **does not replace** previous separator characters by new ones or adjust the escaped texts.
295+
277296
### Inspections
278297

279298
- _File > Settings > Editor > Inspections > CSV_

docs/contextmenu.png

10.1 KB
Loading

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://www.jetbrains.com/intellij-repository/snapshots
44

55
name='CSV Plugin'
6-
pluginVersion=2.3.1
6+
pluginVersion=2.4.0
77
javaVersion=1.8
88
javaTargetVersion=1.8
99
downloadIntellijSources=false
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.seesharpsoft.intellij.lang;
2+
3+
import com.intellij.lang.ParserDefinition;
4+
import com.intellij.lang.PsiParser;
5+
import com.intellij.lexer.Lexer;
6+
import com.intellij.psi.PsiFile;
7+
8+
/**
9+
* Support for file specific parser definition.
10+
*/
11+
public interface FileParserDefinition extends ParserDefinition {
12+
default Lexer createLexer(PsiFile file) {
13+
return createLexer(file.getProject());
14+
}
15+
16+
default PsiParser createParser(PsiFile file) {
17+
return createParser(file.getProject());
18+
}
19+
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public RowInfo getRowInfo(T element) {
2525
return myElementInfos.get(element);
2626
}
2727

28+
public RowInfo getRowInfo(int index) {
29+
return myElementInfos.values().stream()
30+
.filter(rowInfo -> rowInfo.getRowIndex() == index)
31+
.findFirst().orElse(null);
32+
}
33+
2834
public int getColumnIndex() {
2935
return myColumnIndex;
3036
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvColumnInfoMap.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,19 @@ public boolean hasErrors() {
5454
public void setHasErrors(boolean hasErrorsArg) {
5555
hasErrors = hasErrorsArg;
5656
}
57+
58+
public boolean hasEmptyLastLine() {
59+
CsvColumnInfo<T> columnInfo = myInfoColumnMap.get(0);
60+
int size = columnInfo.getSize();
61+
if (!columnInfo.getRowInfo(size - 1).getTextRange().isEmpty()) {
62+
return false;
63+
}
64+
for (int columnIndex = 1; columnIndex < myInfoColumnMap.size(); ++columnIndex) {
65+
if (myInfoColumnMap.get(columnIndex).getSize() == size) {
66+
return false;
67+
}
68+
}
69+
return true;
70+
}
71+
5772
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import com.intellij.openapi.project.Project;
99
import com.intellij.openapi.vfs.VirtualFile;
1010
import com.intellij.psi.PsiElement;
11+
import com.intellij.psi.PsiFile;
1112
import com.intellij.psi.PsiManager;
1213
import com.intellij.psi.TokenType;
1314
import com.intellij.psi.impl.source.DummyHolder;
1415
import com.intellij.psi.impl.source.DummyHolderFactory;
1516
import com.intellij.psi.impl.source.tree.FileElement;
1617
import com.intellij.psi.tree.IElementType;
1718
import com.intellij.psi.util.PsiTreeUtil;
19+
import net.seesharpsoft.intellij.lang.FileParserDefinition;
1820
import net.seesharpsoft.intellij.plugins.csv.psi.CsvField;
1921
import net.seesharpsoft.intellij.plugins.csv.psi.CsvFile;
2022
import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;
@@ -27,14 +29,15 @@ public final class CsvHelper {
2729

2830
// replaces PsiElementFactory.SERVICE.getInstance(element.getProject()).createDummyHolder("<undefined>", CsvTypes.FIELD, null);
2931
// https://github.com/SeeSharpSoft/intellij-csv-validator/issues/4
30-
public static PsiElement createEmptyCsvField(Project project) {
32+
public static PsiElement createEmptyCsvField(PsiFile psiFile) {
33+
final Project project = psiFile.getProject();
3134
final String text = "<undefined>";
3235
final IElementType type = CsvTypes.FIELD;
3336
final PsiManager psiManager = PsiManager.getInstance(project);
3437
final DummyHolder dummyHolder = DummyHolderFactory.createHolder(psiManager, null);
3538
final FileElement fileElement = dummyHolder.getTreeElement();
36-
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(CsvLanguage.INSTANCE);
37-
final Lexer lexer = parserDefinition.createLexer(project);
39+
final FileParserDefinition parserDefinition = (FileParserDefinition)LanguageParserDefinitions.INSTANCE.forLanguage(CsvLanguage.INSTANCE);
40+
final Lexer lexer = parserDefinition.createLexer(psiFile);
3841
final PsiBuilder psiBuilder = PsiBuilderFactory.getInstance().createBuilder(project, fileElement, lexer, CsvLanguage.INSTANCE, text);
3942
final ASTNode node = parserDefinition.createParser(project).parse(type, psiBuilder);
4043
fileElement.rawAddChildren((com.intellij.psi.impl.source.tree.TreeElement) node);
@@ -44,7 +47,7 @@ public static PsiElement createEmptyCsvField(Project project) {
4447
public static boolean isCsvFile(Project project, VirtualFile file) {
4548
final FileType fileType = file.getFileType();
4649
return (fileType instanceof LanguageFileType && ((LanguageFileType) fileType).getLanguage().isKindOf(CsvLanguage.INSTANCE)) ||
47-
(fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file) == CsvLanguage.INSTANCE);
50+
(fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file).isKindOf(CsvLanguage.INSTANCE));
4851
}
4952

5053
public static IElementType getElementType(PsiElement element) {

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvParserDefinition.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.seesharpsoft.intellij.plugins.csv;
22

33
import com.intellij.lang.ASTNode;
4-
import com.intellij.lang.ParserDefinition;
54
import com.intellij.lang.PsiParser;
65
import com.intellij.lexer.Lexer;
76
import com.intellij.openapi.project.Project;
@@ -11,21 +10,23 @@
1110
import com.intellij.psi.TokenType;
1211
import com.intellij.psi.tree.IFileElementType;
1312
import com.intellij.psi.tree.TokenSet;
13+
import net.seesharpsoft.intellij.lang.FileParserDefinition;
1414
import net.seesharpsoft.intellij.plugins.csv.parser.CsvParser;
1515
import net.seesharpsoft.intellij.plugins.csv.psi.CsvFile;
16+
import net.seesharpsoft.intellij.plugins.csv.psi.CsvFileElementType;
1617
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
1718
import net.seesharpsoft.intellij.plugins.csv.settings.CsvCodeStyleSettings;
1819
import org.jetbrains.annotations.NotNull;
1920

20-
public class CsvParserDefinition implements ParserDefinition {
21+
public class CsvParserDefinition implements FileParserDefinition {
2122
public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
2223

23-
public static final IFileElementType FILE = new IFileElementType(CsvLanguage.INSTANCE);
24+
public static final IFileElementType FILE = new CsvFileElementType(CsvLanguage.INSTANCE);
2425

2526
@NotNull
2627
@Override
2728
public Lexer createLexer(Project project) {
28-
return new CsvLexerAdapter(CsvCodeStyleSettings.getCurrentSeparator(project));
29+
throw new UnsupportedOperationException("use 'createLexer(PsiFile file)' instead");
2930
}
3031

3132
@Override
@@ -72,4 +73,14 @@ public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode r
7273
public PsiElement createElement(ASTNode node) {
7374
return CsvTypes.Factory.createElement(node);
7475
}
76+
77+
@Override
78+
public Lexer createLexer(@NotNull PsiFile file) {
79+
return new CsvLexerAdapter(CsvCodeStyleSettings.getCurrentSeparator(file));
80+
}
81+
82+
@Override
83+
public PsiParser createParser(@NotNull PsiFile file) {
84+
return createParser(file.getProject());
85+
}
7586
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvParserUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ private CsvParserUtil() {
1515
public static boolean separator(PsiBuilder builder, int tokenType) {
1616
if (builder.getTokenType() == CsvTypes.COMMA) {
1717
PsiFile currentFile = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
18+
if (currentFile == null) {
19+
throw new UnsupportedOperationException("parser requires containing file");
20+
}
1821
return builder.getTokenText().equals(
19-
CsvCodeStyleSettings.getCurrentSeparator(builder.getProject(), currentFile != null ? currentFile.getLanguage() : null)
22+
CsvCodeStyleSettings.getCurrentSeparator(currentFile)
2023
);
2124
}
2225
return false;

0 commit comments

Comments
 (0)