diff --git a/README.md b/README.md index 2f9c6cb..89c560b 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..eb2c3cd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,41 @@ +{ + "name": "regex", + "version": "0.6.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "regex", + "version": "0.6.0", + "license": "MIT", + "devDependencies": { + "@types/vscode": "^1.92.0", + "typescript": "^5.6.2" + }, + "engines": { + "vscode": "^1.92.0" + } + }, + "node_modules/@types/vscode": { + "version": "1.93.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.93.0.tgz", + "integrity": "sha512-kUK6jAHSR5zY8ps42xuW89NLcBpw1kOabah7yv38J8MyiYuOHxLQBi0e7zeXbQgVefDy/mZZetqEFC+Fl5eIEQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json index f2713e6..e7ad76d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -34,7 +34,8 @@ "onLanguage:typescriptreact", "onLanguage:vue", "onLanguage:php", - "onLanguage:haxe" + "onLanguage:haxe", + "onLanguage:go" ], "main": "./out/extension", "browser": "./out/extension", diff --git a/root/pkg/mod/cache/lock b/root/pkg/mod/cache/lock new file mode 100644 index 0000000..e69de29 diff --git a/src/extension.ts b/src/extension.ts index 828350a..25eb7e2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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)' }); @@ -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(); @@ -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) }; } } diff --git a/yarn.lock b/yarn.lock index aa1844e..d404ae6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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==