Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
Added feature to leave out match.
  • Loading branch information
Kjeldgaard committed Nov 14, 2020
1 parent e40fcf8 commit a90a9c3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
#### Version 1.0.0
- [Feature] Possibility to leave match out of the generated URL.

#### Version 0.2.0
- [breaking change] Added 'postfix' string. Update extension configuration with 'postfix' field
- Added icon.
Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@
This is the README for the Visual Studio Code extension named "Regex Show Go".

## Features
When hovering a line in Visual Studio Code, the line text is matched against one or several regex patterns. If a match is found, a hover box is shown with a link which is created from a match-prefix and the actual match and a match-postfix. See Extension Settings section for configuration.
When hovering a line in Visual Studio Code, the line is matched against one or several regex patterns. If a match is found, a hover box is shown with a link which is created from a match-prefix and the actual match and a match-postfix. See Extension Settings section for configuration.

## Extension Settings
To use the extension, you must configure a regex match pattern and a match prefix. See configuration example:
To use the extension, you must configure a regex match pattern, match prefix, and match postfix. Note, for backward compatibility, if "search_at" is not defined, the default value is "false".

Configuration example:
```
"regex_show_go.config.match": [
{
"match_pattern": "WIKI[0-9-]+",
"prefix": "https://duckduckgo.com/?q=",
"postfix" ""
},
{
"match_pattern": "TEST[0-9-]+",
"prefix": "https://www.imdb.com/find?q="
"prefix": "https://www.google.com/search?q="
"postfix": "-test"
}
},
{
"match_pattern": "WIKI",
"prefix": "https://en.wikipedia.org/wiki/",
"postfix": "",
"search_at": true
}]
```
If a line contains the word "WIKI-123", the following link is generated "https://duckduckgo.com/?q=WIKI-123" when hovering the line.
Example 1:
Hovering a line containing the text "TEST-1234", will generate the following link "https://www.google.com/search?q=TEST-1234-test".

Example 2:
Hovering a line containing the text "WIKI#test#", will generate the following link "https://en.wikipedia.org/wiki/test". Note, "match_pattern" is not included in the generated URL.

## Release Notes
#### Version 1.0.0
- [Feature] Possibility to leave match out of the generated URL. See the section "Extension Settings".

#### Version 0.2.0
- [breaking change] Added 'postfix' string. Update extension configuration with 'postfix' field
- Added icon.
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Regex Show Go",
"publisher": "Kjeldgaard",
"description": "",
"version": "0.2.0",
"version": "1.0.0",
"engines": {
"vscode": "^1.46.0"
},
Expand Down Expand Up @@ -42,6 +42,10 @@
"postfix": {
"type": "string",
"description": "postfix"
},
"search_at": {
"type": "boolean",
"description": "search_at site"
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,39 @@ export function activate(context: vscode.ExtensionContext) {
// Search for regex match pattern in line text
for (let i = 0; i < Object.keys(config).length; i++)
{
let pattern = new RegExp(config[i].match_pattern, 'g');
let pattern;
let match;
let search_at = !(typeof config[i].search_at === "undefined") && config[i].search_at === true;

// If match found, store match prefix and match
let match = pattern.exec(line.text);
if (search_at)
{
// If match found, store match prefix and match
pattern = new RegExp(config[i].match_pattern + "#?([^#]+)#", 'g');
match = pattern.exec(line.text);
}
else
{
// If match found, store match prefix and match
pattern = new RegExp(config[i].match_pattern, 'g');
match = pattern.exec(line.text);
}

while (match)
{
// Store match, add separator if not the first match
if (text.length > 0)
{
text += " \|\| ";
}
text += config[i].prefix + match[0] + config[i].postfix;
if (search_at)
{
text += config[i].prefix + match[1] + config[i].postfix;
}
else
{
text += config[i].prefix + match[0] + config[i].postfix;
}


// Get next match
match = pattern.exec(line.text);
Expand Down

0 comments on commit a90a9c3

Please sign in to comment.