Add Workspace Exclusion Regex Support (#220)

This commit is contained in:
berwyn (Jamison) 2019-04-19 07:00:44 -04:00 committed by Crawl
parent 4c01c27b09
commit 983207ae48
3 changed files with 28 additions and 3 deletions

View file

@ -138,7 +138,15 @@
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "Decides whether to display elapsed time for a workspace or a single file" "description": "Decides whether to display elapsed time for a workspace or a single file"
} },
"discord.workspaceExcludePatterns": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Patterns of workspaces to ignore"
}
} }
} }
] ]

View file

@ -20,7 +20,21 @@ const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon);
export async function activate(context: ExtensionContext) { export async function activate(context: ExtensionContext) {
Logger.log('Discord Presence activated!'); Logger.log('Discord Presence activated!');
if (config.get<boolean>('enabled')) { let isWorkspaceExcluded = false;
const excludePatterns = config.get<string[]>('workspaceExcludePatterns');
if (excludePatterns && excludePatterns.length > 0) {
for (const pattern of excludePatterns) {
const regex = new RegExp(pattern);
const folders = workspace.workspaceFolders;
if (!folders) break;
if (folders.some((folder) => regex.test(folder.uri.fsPath))) {
isWorkspaceExcluded = true;
break;
}
}
}
if (!isWorkspaceExcluded && config.get<boolean>('enabled')) {
statusBarIcon.show(); statusBarIcon.show();
try { try {
await rpc.login(); await rpc.login();

View file

@ -13,7 +13,10 @@
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"removeComments": false, "removeComments": false,
"experimentalDecorators": true "experimentalDecorators": true,
"typeRoots": [
"node_modules/@types"
]
}, },
"include": [ "include": [
"./src" "./src"