Skip to content

Commit

Permalink
Fix unescaped characters breaking preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jan 5, 2022
1 parent 4b825a8 commit 49651e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## 1.1.1
- Fixed expressions with escaped backslashes not displaying previews.
- Fixed unescaped characters breaking the preview formatting.

## 1.1.0
- Changed display of hints from an inline hint to be in a hover menu.
- Changed result to include a list of several sample matches.
- Fixed extension ocasionally crashing.

## 1.0.0
- Added inlay hints to preview regular expressions.
18 changes: 9 additions & 9 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "inlay-regex",
"displayName": "Inlay Regex Previewer",
"version": "1.1.0",
"version": "1.1.1",
"description": "Generate sample matches when a regular expression is hovered over.",
"categories": [
"Debuggers",
Expand All @@ -28,7 +28,7 @@
},
"devDependencies": {
"@types/node": "ts4.3",
"@types/vscode": "^1.63.1",
"@types/vscode": "1.50.0",
"typescript": "^4.5.4"
},
"engines": {
Expand Down
7 changes: 3 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import RandExp from 'randexp';

const languages = ['javascript', 'typescript', 'coffeescript', 'ruby', 'groovy'];
const numPreviews = 5;
const regexRegex = /\/((?![*+?])(?:[^\r\n\[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*\])+)\/[gimusy]*/; // so:17843691

function provideHover(document: vscode.TextDocument, position: vscode.Position) {
// Get content of line
const regex = /\/.*?[^\\]\/[gimusy]*/g;
const range = document.getWordRangeAtPosition(position, regex);
const range = document.getWordRangeAtPosition(position, regexRegex);
const match = document.getText(range);
console.debug({match})
// Exit if no regex selected
if (match.includes('\n')) return;
// Create preview regexes
Expand All @@ -23,7 +22,7 @@ function provideHover(document: vscode.TextDocument, position: vscode.Position)
}
}
// Return
const previewText = previews.map(text => '\n- ``' + text + '``').join('');
const previewText = previews.map(text => '\n- `` ' + text + ' ``').join('');
const result = new vscode.MarkdownString(`**Possible matches:**\n${previewText}`);
return new vscode.Hover(result);
}
Expand Down
4 changes: 3 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ const regex = /\/.*?[^\\]\/[gimusy]*?/g;
if ("string".match(/s..\w+$/)) console.log('match');
/a/, /b/;
/.+/

const escape = /a\\b/ + /!\\/;
const look = /abc(?=def)/;
const lookNested = /abc(?=(?<!def)def)/;

0 comments on commit 49651e6

Please sign in to comment.