Skip to content

Commit

Permalink
Try to always print five matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed May 8, 2022
1 parent 779f244 commit 0bbd7a6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.3
- Changed the description text in the hover window.
- Changed the sample matches list to always try to print five non-duplicate matches if possible.

## 1.1.2
- Added support for JSX and TSX.
- Changed output to create shorter wildcard results.
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

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

6 changes: 3 additions & 3 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.2",
"version": "1.1.3",
"description": "Generate sample matches when a regular expression is hovered over.",
"categories": [
"Other"
Expand All @@ -28,9 +28,9 @@
"randexp": "~0.5.3"
},
"devDependencies": {
"@types/node": "ts4.3",
"@types/node": "ts4.6",
"@types/vscode": "1.50.0",
"typescript": "^4.5.4"
"typescript": "^4.6.4"
},
"engines": {
"vscode": "^1.50.0"
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const supportedLanguages = [
'groovy',
];

const COUNT = 5;
const regexRegex = /\/((?![*+?])(?:[^\r\n\[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*\])+)\/[gimusy]*/; // so:17843691

function provideHover(document: vscode.TextDocument, position: vscode.Position) {
Expand All @@ -22,7 +21,8 @@ function provideHover(document: vscode.TextDocument, position: vscode.Position)
if (match.includes('\n')) return;
// Create preview regexes
const previews: string[] = [];
for (let i = 0; i < COUNT; i++) {
let i = 0;
while (previews.length < 5 && i++ < 20) {
const annotation = new RandExp(eval(match));
annotation.max = 5;
const preview = annotation.gen();
Expand All @@ -32,7 +32,8 @@ function provideHover(document: vscode.TextDocument, position: vscode.Position)
}
// Return
const previewText = previews.map(text => '\n- `` ' + text + ' ``').join('');
const result = new vscode.MarkdownString(`**Possible matches:**\n${previewText}`);
const outputText = `**Sample matches:**\n${previewText}`;
const result = new vscode.MarkdownString(outputText);
return new vscode.Hover(result);
}

Expand Down

0 comments on commit 0bbd7a6

Please sign in to comment.