Skip to content

Commit 55307c2

Browse files
author
Jackson Kearl
committed
Add syntax highlighting to Search Results.
Closes microsoft#86241.
1 parent 889ce81 commit 55307c2

3 files changed

Lines changed: 3100 additions & 101 deletions

File tree

extensions/search-result/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"*"
1717
],
1818
"scripts": {
19+
"update-grammar": "node ./syntaxes/generateTMLanguage.js",
1920
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:search-result ./tsconfig.json"
2021
},
2122
"contributes": {
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// @ts-check
2+
3+
const languages = [
4+
['bat', 'source.batchfile'],
5+
['c', 'source.c'],
6+
['clj', 'source.clojure'],
7+
['coffee', 'source.coffee'],
8+
['cpp', 'source.cpp'],
9+
['cs', 'source.cs'],
10+
['css', 'source.css'],
11+
['dart', 'source.dart'],
12+
['diff', 'source.diff'],
13+
['dockerfile', 'source.dockerfile'],
14+
['fs', 'source.fsharp'],
15+
['go', 'source.go'],
16+
['groovy', 'source.groovy'],
17+
['h', 'source.objc'],
18+
['hpp', 'source.objcpp'],
19+
['html', 'source.html'],
20+
['java', 'source.java'],
21+
['js', 'source.js'],
22+
['json', 'source.json.comments'],
23+
['jsx', 'source.js.jsx'],
24+
['less', 'source.css.less'],
25+
['lua', 'source.lua'],
26+
['m', 'source.objc'],
27+
['make', 'source.makefile'],
28+
['mm', 'source.objcpp'],
29+
['p6', 'source.perl.6'],
30+
['perl', 'source.perl'],
31+
['php', 'source.php'],
32+
['pl', 'source.perl'],
33+
['ps1', 'source.powershell'],
34+
['py', 'source.python'],
35+
['r', 'source.r'],
36+
['rb', 'source.ruby'],
37+
['rs', 'source.rust'],
38+
['scala', 'source.scala'],
39+
['scss', 'source.css.scss'],
40+
['sh', 'source.shell'],
41+
['sql', 'source.sql'],
42+
['swift', 'source.swift'],
43+
['ts', 'source.ts'],
44+
['tsx', 'source.tsx'],
45+
['yaml', 'source.yaml'],
46+
];
47+
48+
const repository = {};
49+
languages.forEach(([ext, scope]) =>
50+
repository[ext] = {
51+
begin: `^(?!\\s)(.*?)([^\\\\\\/\\n]*.${ext})(:)$`,
52+
end: "^(?!\\s)",
53+
name: `searchResult.block.${ext}`,
54+
beginCaptures: {
55+
"0": {
56+
name: "string path.searchResult"
57+
},
58+
"1": {
59+
name: "dirname.path.searchResult"
60+
},
61+
"2": {
62+
name: "basename.path.searchResult"
63+
},
64+
"3": {
65+
name: "endingColon.path.searchResult"
66+
}
67+
},
68+
patterns: [
69+
{
70+
begin: "^ (\\d+)( )",
71+
while: "^ (\\d+)(:| )",
72+
beginCaptures: {
73+
"1": {
74+
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
75+
},
76+
"2": {
77+
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
78+
}
79+
},
80+
whileCaptures: {
81+
"1": {
82+
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
83+
},
84+
"2": {
85+
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
86+
}
87+
},
88+
name: `searchResult.resultLine.${ext} searchResult.multiline`,
89+
patterns: [
90+
{
91+
include: scope
92+
}
93+
]
94+
},
95+
{
96+
match: "^ (\\d+)(:)(.*)",
97+
name: `searchResult.resultLine.${ext} searchResult.singleline`,
98+
captures: {
99+
"1": {
100+
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
101+
},
102+
"2": {
103+
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
104+
},
105+
"3": {
106+
patterns: [
107+
{
108+
include: scope
109+
}
110+
]
111+
}
112+
}
113+
}
114+
]
115+
});
116+
117+
const header = {
118+
"match": "^# (Query|Flags|Including|Excluding|ContextLines): .*$",
119+
"name": "comment"
120+
};
121+
122+
const plainText = [{
123+
match: "^(?!\\s)(.*?)([^\\\\\\/\\n]*)(:)$",
124+
name: "string path.searchResult",
125+
captures: {
126+
"1": {
127+
name: "dirname.path.searchResult"
128+
},
129+
"2": {
130+
name: "basename.path.searchResult"
131+
},
132+
"3": {
133+
name: "endingColon.path.searchResult"
134+
}
135+
}
136+
},
137+
{
138+
match: "^ (\\d+)(:| )",
139+
captures: {
140+
"1": {
141+
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
142+
},
143+
"2": {
144+
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
145+
}
146+
}
147+
}];
148+
149+
const tmLanguage = {
150+
"information_for_contributors": "This file is generated from ./generateTMLanguage.js.",
151+
name: "Search Results",
152+
scopeName: "text.searchResult",
153+
patterns: [
154+
header,
155+
...languages.map(([ext]) => ({ include: `#${ext}` })),
156+
...plainText
157+
],
158+
repository
159+
};
160+
161+
162+
require('fs')
163+
.writeFileSync('./searchResult.tmLanguage.json', JSON.stringify(tmLanguage, null, 2));

0 commit comments

Comments
 (0)