Skip to content

Commit 57c8cae

Browse files
author
Jackson Kearl
committed
Improve searchresult textmate scopes
1 parent 68db7fc commit 57c8cae

2 files changed

Lines changed: 3163 additions & 1182 deletions

File tree

Lines changed: 169 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
// @ts-check
22

3-
const languages = [
3+
const mappings = [
44
['bat', 'source.batchfile'],
55
['c', 'source.c'],
6+
['cc', 'source.cpp'],
67
['clj', 'source.clojure'],
78
['coffee', 'source.coffee'],
89
['cpp', 'source.cpp'],
910
['cs', 'source.cs'],
11+
['cshtml', 'text.html.cshtml'],
1012
['css', 'source.css'],
1113
['dart', 'source.dart'],
1214
['diff', 'source.diff'],
13-
['dockerfile', 'source.dockerfile'],
15+
['dockerfile', 'source.dockerfile', '(?:dockerfile|Dockerfile)'],
1416
['fs', 'source.fsharp'],
1517
['go', 'source.go'],
1618
['groovy', 'source.groovy'],
1719
['h', 'source.objc'],
20+
['handlebars', 'text.html.handlebars'],
21+
['hbs', 'text.html.handlebars'],
22+
['hlsl', 'source.hlsl'],
1823
['hpp', 'source.objcpp'],
19-
['html', 'source.html'],
24+
['html', 'text.html.basic'],
25+
['ini', 'source.ini'],
2026
['java', 'source.java'],
2127
['js', 'source.js'],
2228
['json', 'source.json.comments'],
2329
['jsx', 'source.js.jsx'],
2430
['less', 'source.css.less'],
31+
['log', 'text.log'],
2532
['lua', 'source.lua'],
2633
['m', 'source.objc'],
27-
['make', 'source.makefile'],
34+
['makefile', 'source.makefile', '(?:makefile|Makefile)(?:\\..*)?'],
35+
['md', 'text.html.markdown'],
2836
['mm', 'source.objcpp'],
2937
['p6', 'source.perl.6'],
3038
['perl', 'source.perl'],
3139
['php', 'source.php'],
3240
['pl', 'source.perl'],
3341
['ps1', 'source.powershell'],
42+
['pug', 'text.pug'],
3443
['py', 'source.python'],
3544
['r', 'source.r'],
3645
['rb', 'source.ruby'],
@@ -42,121 +51,193 @@ const languages = [
4251
['swift', 'source.swift'],
4352
['ts', 'source.ts'],
4453
['tsx', 'source.tsx'],
54+
['vb', 'source.asp.vb.net'],
55+
['xml', 'text.xml'],
4556
['yaml', 'source.yaml'],
4657
];
4758

59+
const scopes = {
60+
root: 'text.searchResult',
61+
header: {
62+
meta: 'meta.header.search keyword.operator.word.search',
63+
key: 'entity.other.attribute-name',
64+
value: 'entity.other.attribute-value string.unquoted',
65+
flags: {
66+
keyword: 'keyword.other',
67+
},
68+
contextLines: {
69+
number: 'constant.numeric.integer',
70+
invalid: 'invalid.illegal',
71+
},
72+
query: {
73+
escape: 'constant.character.escape',
74+
invalid: 'invalid.illegal',
75+
}
76+
},
77+
resultBlock: {
78+
meta: 'meta.resultBlock.search',
79+
path: {
80+
meta: 'string meta.path.search',
81+
dirname: 'meta.path.dirname.search',
82+
basename: 'meta.path.basename.search',
83+
colon: 'punctuation.separator',
84+
},
85+
result: {
86+
meta: 'meta.resultLine.search',
87+
metaSingleLine: 'meta.resultLine.singleLine.search',
88+
metaMultiLine: 'meta.resultLine.multiLine.search',
89+
prefix: {
90+
meta: 'constant.numeric.integer meta.resultLinePrefix.search',
91+
metaContext: 'meta.resultLinePrefix.contextLinePrefix.search',
92+
metaMatch: 'meta.resultLinePrefix.matchLinePrefix.search',
93+
lineNumber: 'meta.resultLinePrefix.lineNumber.search',
94+
colon: 'punctuation.separator',
95+
}
96+
}
97+
}
98+
};
99+
48100
const repository = {};
49-
languages.forEach(([ext, scope]) =>
101+
mappings.forEach(([ext, scope, regexp]) =>
50102
repository[ext] = {
51-
begin: `^(?!\\s)(.*?)([^\\\\\\/\\n]*.${ext})(:)$`,
103+
name: scopes.resultBlock.meta,
104+
begin: `^(?!\\s)(.*?)([^\\\\\\/\\n]*${regexp || `\\.${ext}`})(:)$`,
52105
end: "^(?!\\s)",
53-
name: `searchResult.block.${ext}`,
54106
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-
}
107+
"0": { name: scopes.resultBlock.path.meta },
108+
"1": { name: scopes.resultBlock.path.dirname },
109+
"2": { name: scopes.resultBlock.path.basename },
110+
"3": { name: scopes.resultBlock.path.colon },
67111
},
68112
patterns: [
69113
{
70-
begin: "^ (\\d+)( )",
71-
while: "^ (\\d+)(:| )",
114+
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaMultiLine].join(' '),
115+
begin: "^ ((\\d+) )",
116+
while: "^ ((\\d+)(:))|((\\d+) )",
72117
beginCaptures: {
73-
"1": {
74-
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
75-
},
76-
"2": {
77-
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
78-
}
118+
"0": { name: scopes.resultBlock.result.prefix.meta },
119+
"1": { name: scopes.resultBlock.result.prefix.metaContext },
120+
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
79121
},
80122
whileCaptures: {
81-
"1": {
82-
name: "constant.numeric lineNumber.searchResult resultPrefix.searchResult"
83-
},
84-
"2": {
85-
name: "resultPrefixSeparator.searchResult resultPrefix.searchResult"
86-
}
123+
"0": { name: scopes.resultBlock.result.prefix.meta },
124+
"1": { name: scopes.resultBlock.result.prefix.metaMatch },
125+
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
126+
"3": { name: scopes.resultBlock.result.prefix.colon },
127+
128+
"4": { name: scopes.resultBlock.result.prefix.metaContext },
129+
"5": { name: scopes.resultBlock.result.prefix.lineNumber },
87130
},
88-
name: `searchResult.resultLine.${ext} searchResult.multiline`,
89-
patterns: [
90-
{
91-
include: scope
92-
}
93-
]
131+
patterns: [{ include: scope }]
94132
},
95133
{
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-
}
134+
begin: "^ ((\\d+)(:))",
135+
while: "(?=not)possible",
136+
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaSingleLine].join(' '),
137+
beginCaptures: {
138+
"0": { name: scopes.resultBlock.result.prefix.meta },
139+
"1": { name: scopes.resultBlock.result.prefix.metaMatch },
140+
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
141+
"3": { name: scopes.resultBlock.result.prefix.colon },
142+
},
143+
patterns: [{ include: scope }]
113144
}
114145
]
115146
});
116147

117-
const header = {
118-
"match": "^# (Query|Flags|Including|Excluding|ContextLines): .*$",
119-
"name": "comment"
120-
};
148+
const header = [
149+
{
150+
begin: "^(# Query): ",
151+
end: "\n",
152+
name: scopes.header.meta,
153+
beginCaptures: { "1": { name: scopes.header.key }, },
154+
patterns: [
155+
{
156+
match: '(\\\\n)|(\\\\\\\\)',
157+
name: [scopes.header.value, scopes.header.query.escape].join(' ')
158+
},
159+
{
160+
match: '\\\\.|\\\\$',
161+
name: [scopes.header.value, scopes.header.query.invalid].join(' ')
162+
},
163+
{
164+
match: '[^\\\\\\\n]+',
165+
name: [scopes.header.value].join(' ')
166+
},
167+
]
168+
},
169+
{
170+
begin: "^(# Flags): ",
171+
end: "\n",
172+
name: scopes.header.meta,
173+
beginCaptures: { "1": { name: scopes.header.key }, },
174+
patterns: [
175+
{
176+
match: '(RegExp|CaseSensitive|IgnoreExcludeSettings|WordMatch)',
177+
name: [scopes.header.value, 'keyword.other'].join(' ')
178+
},
179+
{ match: '.' },
180+
]
181+
},
182+
{
183+
begin: "^(# ContextLines): ",
184+
end: "\n",
185+
name: scopes.header.meta,
186+
beginCaptures: { "1": { name: scopes.header.key }, },
187+
patterns: [
188+
{
189+
match: '\\d',
190+
name: [scopes.header.value, scopes.header.contextLines.number].join(' ')
191+
},
192+
{ match: '.', name: scopes.header.contextLines.invalid },
193+
]
194+
},
195+
{
196+
match: "^(# (?:Including|Excluding)): (.*)$",
197+
name: scopes.header.meta,
198+
captures: {
199+
"1": { name: scopes.header.key },
200+
"2": { name: scopes.header.value }
201+
}
202+
},
203+
];
121204

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"
205+
const plainText = [
206+
{
207+
match: "^(?!\\s)(.*?)([^\\\\\\/\\n]*)(:)$",
208+
name: [scopes.resultBlock.meta, scopes.resultBlock.path.meta].join(' '),
209+
captures: {
210+
"1": { name: scopes.resultBlock.path.dirname },
211+
"2": { name: scopes.resultBlock.path.basename },
212+
"3": { name: scopes.resultBlock.path.colon }
134213
}
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"
214+
},
215+
{
216+
match: "^ ((\\d+)(:))|((\\d+)( ))(.*)",
217+
name: [scopes.resultBlock.meta, scopes.resultBlock.result.meta].join(' '),
218+
captures: {
219+
"1": { name: [scopes.resultBlock.result.prefix.meta, scopes.resultBlock.result.prefix.metaMatch].join(' ') },
220+
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
221+
"3": { name: scopes.resultBlock.result.prefix.colon },
222+
223+
"4": { name: [scopes.resultBlock.result.prefix.meta, scopes.resultBlock.result.prefix.metaContext].join(' ') },
224+
"5": { name: scopes.resultBlock.result.prefix.lineNumber },
145225
}
146226
}
147-
}];
227+
];
148228

149229
const tmLanguage = {
150230
"information_for_contributors": "This file is generated from ./generateTMLanguage.js.",
151231
name: "Search Results",
152-
scopeName: "text.searchResult",
232+
scopeName: scopes.root,
153233
patterns: [
154-
header,
155-
...languages.map(([ext]) => ({ include: `#${ext}` })),
234+
...header,
235+
...mappings.map(([ext]) => ({ include: `#${ext}` })),
156236
...plainText
157237
],
158238
repository
159239
};
160240

161-
require('fs')
162-
.writeFileSync(require('path').join(__dirname, './searchResult.tmLanguage.json'), JSON.stringify(tmLanguage, null, 2));
241+
require('fs').writeFileSync(
242+
require('path').join(__dirname, './searchResult.tmLanguage.json'),
243+
JSON.stringify(tmLanguage, null, 2));

0 commit comments

Comments
 (0)