Skip to content

Commit a90a9c3

Browse files
committed
Version 1.0.0
Added feature to leave out match.
1 parent e40fcf8 commit a90a9c3

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Change Log
2+
#### Version 1.0.0
3+
- [Feature] Possibility to leave match out of the generated URL.
4+
25
#### Version 0.2.0
36
- [breaking change] Added 'postfix' string. Update extension configuration with 'postfix' field
47
- Added icon.

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@
22
This is the README for the Visual Studio Code extension named "Regex Show Go".
33

44
## Features
5-
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.
5+
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.
66

77
## Extension Settings
8-
To use the extension, you must configure a regex match pattern and a match prefix. See configuration example:
8+
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".
9+
10+
Configuration example:
911
```
1012
"regex_show_go.config.match": [
11-
{
12-
"match_pattern": "WIKI[0-9-]+",
13-
"prefix": "https://duckduckgo.com/?q=",
14-
"postfix" ""
15-
},
1613
{
1714
"match_pattern": "TEST[0-9-]+",
18-
"prefix": "https://www.imdb.com/find?q="
15+
"prefix": "https://www.google.com/search?q="
1916
"postfix": "-test"
20-
}
17+
},
18+
{
19+
"match_pattern": "WIKI",
20+
"prefix": "https://en.wikipedia.org/wiki/",
21+
"postfix": "",
22+
"search_at": true
23+
}]
2124
```
22-
If a line contains the word "WIKI-123", the following link is generated "https://duckduckgo.com/?q=WIKI-123" when hovering the line.
25+
Example 1:
26+
Hovering a line containing the text "TEST-1234", will generate the following link "https://www.google.com/search?q=TEST-1234-test".
27+
28+
Example 2:
29+
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.
2330

2431
## Release Notes
32+
#### Version 1.0.0
33+
- [Feature] Possibility to leave match out of the generated URL. See the section "Extension Settings".
34+
2535
#### Version 0.2.0
2636
- [breaking change] Added 'postfix' string. Update extension configuration with 'postfix' field
2737
- Added icon.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Regex Show Go",
44
"publisher": "Kjeldgaard",
55
"description": "",
6-
"version": "0.2.0",
6+
"version": "1.0.0",
77
"engines": {
88
"vscode": "^1.46.0"
99
},
@@ -42,6 +42,10 @@
4242
"postfix": {
4343
"type": "string",
4444
"description": "postfix"
45+
},
46+
"search_at": {
47+
"type": "boolean",
48+
"description": "search_at site"
4549
}
4650
}
4751
}

src/extension.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,39 @@ export function activate(context: vscode.ExtensionContext) {
2727
// Search for regex match pattern in line text
2828
for (let i = 0; i < Object.keys(config).length; i++)
2929
{
30-
let pattern = new RegExp(config[i].match_pattern, 'g');
30+
let pattern;
31+
let match;
32+
let search_at = !(typeof config[i].search_at === "undefined") && config[i].search_at === true;
3133

32-
// If match found, store match prefix and match
33-
let match = pattern.exec(line.text);
34+
if (search_at)
35+
{
36+
// If match found, store match prefix and match
37+
pattern = new RegExp(config[i].match_pattern + "#?([^#]+)#", 'g');
38+
match = pattern.exec(line.text);
39+
}
40+
else
41+
{
42+
// If match found, store match prefix and match
43+
pattern = new RegExp(config[i].match_pattern, 'g');
44+
match = pattern.exec(line.text);
45+
}
46+
3447
while (match)
3548
{
3649
// Store match, add separator if not the first match
3750
if (text.length > 0)
3851
{
3952
text += " \|\| ";
4053
}
41-
text += config[i].prefix + match[0] + config[i].postfix;
54+
if (search_at)
55+
{
56+
text += config[i].prefix + match[1] + config[i].postfix;
57+
}
58+
else
59+
{
60+
text += config[i].prefix + match[0] + config[i].postfix;
61+
}
62+
4263

4364
// Get next match
4465
match = pattern.exec(line.text);

0 commit comments

Comments
 (0)