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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Global and multiline options can be added for evaluation with a side-by-side doc

## Release Notes

### 0.6.1

- Add Go support

### 0.6.0

- Add support for `d` flag in TypeScript/JavaScript (PR by [@wszgrcy](https://github.com/wszgrcy))
Expand Down
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "regex",
"displayName": "Regex Previewer",
"description": "Regex matches previewer for JavaScript, TypeScript, PHP and Haxe in Visual Studio Code.",
"version": "0.6.0",
"description": "Regex matches previewer for JavaScript, TypeScript, PHP, Haxe and Go in Visual Studio Code.",
"version": "0.6.1",
"publisher": "chrmarti",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,7 +34,8 @@
"onLanguage:typescriptreact",
"onLanguage:vue",
"onLanguage:php",
"onLanguage:haxe"
"onLanguage:haxe",
"onLanguage:go"
],
"main": "./out/extension",
"browser": "./out/extension",
Expand Down
Empty file added root/pkg/mod/cache/lock
Empty file.
30 changes: 27 additions & 3 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 goRegexRegex = /regexp\.(MustCompile|Compile|CompilePOSIX)\s*\(\s*(['"`])((?:\\.|[^\\])*?)\2\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', 'go'];

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

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

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

if (document.languageId === 'go') {
// Go regex: regexp.MustCompile("pattern")
// Groups: [full_match, function_name, quote_char, pattern]
pattern = match[3];
flags = ''; // Go doesn't use inline flags
rangeStart = match.index;
rangeLength = match[0].length;
} else {
// Other languages: /pattern/flags or similar
// Groups: [full_match, prefix, full_regex, pattern, flags, suffix]
pattern = match[3];
flags = match[4] || '';
rangeStart = match.index + match[1].length;
rangeLength = match[2].length;
}

const regex = createRegex(pattern, flags);
if (regex) {
return {
document: document,
regex: regex,
range: new vscode.Range(line, match.index + match[1].length, line, match.index + match[1].length + match[2].length)
range: new vscode.Range(line, rangeStart, line, rangeStart + rangeLength)
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

"@types/vscode@^1.92.0":
version "1.93.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.93.0.tgz#1cd7573e0272aef9c357bafc635b6177c154013e"
resolved "https://registry.npmjs.org/@types/vscode/-/vscode-1.93.0.tgz"
integrity sha512-kUK6jAHSR5zY8ps42xuW89NLcBpw1kOabah7yv38J8MyiYuOHxLQBi0e7zeXbQgVefDy/mZZetqEFC+Fl5eIEQ==

typescript@^5.6.2:
version "5.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"
resolved "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz"
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==