-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath-strategy.js
73 lines (55 loc) · 1.46 KB
/
path-strategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
const IconTables = require("../../icons/icon-tables.js");
const Strategy = require("../strategy.js");
class PathStrategy extends Strategy {
constructor(){
super({
priority: 1,
matchesFiles: true,
matchesDirs: true,
noSetting: true,
ignoreVirtual: false,
});
}
registerResource(resource){
if(super.registerResource(resource)){
const disposables = this.resourceEvents.get(resource);
disposables.add(resource.onDidMove(() => this.check(resource, false)));
this.resourceEvents.set(resource, disposables);
return true;
}
else return false;
}
matchIcon(resource){
let icon = null;
if(resource.isDirectory)
icon =
IconTables.matchPath(resource.path, true) ||
IconTables.matchName(resource.name, true) ||
null;
else{
let {name} = resource;
let path = resource.realPath || resource.path;
let isFiltered = false;
const filtered = this.filter(name) || name;
if(filtered !== name){
isFiltered = true;
name = filtered;
path = this.filter(path);
}
icon =
IconTables.matchPath(path) ||
IconTables.matchName(name) ||
null;
if(isFiltered && (null === icon || icon.priority < 1))
icon = IconTables.matchName(resource.name);
}
return icon || null;
}
filter(path){
return path
.replace(/~(?:orig|previous)$/, "")
.replace(/^([^.]*\.[^.]+)\.(?:inc?|dist|tm?pl|te?mp|ti?dy)$/i, "$1");
}
}
module.exports = new PathStrategy();