Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Global and multiline options can be added for evaluation with a side-by-side doc
### 0.6.0

- Add support for `d` flag in TypeScript/JavaScript (PR by [@wszgrcy](https://github.com/wszgrcy))
- Add Java support

### 0.5.0

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "regex",
"displayName": "Regex Previewer",
"description": "Regex matches previewer for JavaScript, TypeScript, PHP and Haxe in Visual Studio Code.",
"description": "Regex matches previewer for JavaScript, TypeScript, PHP, Haxe and Java in Visual Studio Code.",
"version": "0.6.0",
"publisher": "chrmarti",
"repository": {
Expand Down Expand Up @@ -34,7 +34,8 @@
"onLanguage:typescriptreact",
"onLanguage:vue",
"onLanguage:php",
"onLanguage:haxe"
"onLanguage:haxe",
"onLanguage:java"
],
"main": "./out/extension",
"browser": "./out/extension",
Expand Down
20 changes: 18 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function activate(context: vscode.ExtensionContext) {
const regexRegex = /(^|\s|[()={},:?;])(\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimuyd]*))(\s|[()={},:?;]|$)/g;
const phpRegexRegex = /(^|\s|[()={},:?;])['|"](\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimuy]*))['|"](\s|[()={},:?;]|$)/g;
const haxeRegexRegex = /(^|\s|[()={},:?;])(~\/((?:\\\/|\[[^\]]*\]|[^/])+)\/([gimsu]*))(\s|[.()={},:?;]|$)/g;
const javaRegexRegex = /(^|\s|[()={},:?;]|[a-zA-Z_$][a-zA-Z0-9_$]*\.)(Pattern\.compile\s*\(\s*"([^"\\]*(\\.[^"\\]*)*)"\s*\)|(?:matches|replaceAll|replaceFirst|split)\s*\(\s*"([^"\\]*(\\.[^"\\]*)*)"\s*[,)])(\s|[()={},:?;]|$)/g;
const regexHighlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(100,100,100,.35)' });
const matchHighlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(255,255,0,.35)' });

Expand All @@ -38,7 +39,7 @@ www.demo.com http://foo.co.uk/
https://marketplace.visualstudio.com/items?itemName=chrmarti.regex
https://github.com/chrmarti/vscode-regex
`;
const languages = ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'php', 'haxe'];
const languages = ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'php', 'haxe', 'java'];

const decorators = new Map<vscode.TextEditor, RegexMatchDecorator>();

Expand Down Expand Up @@ -295,12 +296,27 @@ https://github.com/chrmarti/vscode-regex
return haxeRegexRegex;
} else if (languageId == 'php') {
return phpRegexRegex;
} else if (languageId == 'java') {
return javaRegexRegex;
}
return regexRegex;
}

function createRegexMatch(document: vscode.TextDocument, line: number, match: RegExpExecArray) {
const regex = createRegex(match[3], match[4]);
let pattern: string;
let flags: string;

if (document.languageId === 'java') {
// For Java, pattern is in match[3] or match[5], flags are empty
pattern = match[3] || match[5];
flags = '';
} else {
// For other languages, use the standard format
pattern = match[3];
flags = match[4];
}

const regex = createRegex(pattern, flags);
if (regex) {
return {
document: document,
Expand Down