diff --git a/README.md b/README.md index d2ff002..60d86d9 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The following Visual Studio Code settings are available for the Nim extension. } ``` * `nim.lintOnSave` - perform the project check for errors on save -* `nim.project` - optional array of projects file, if nim.project is not defined then all nim files will be used as separate project +* `nim.project` - optional array of projects file/glob paths, if nim.project is not defined then all nim files will be used as separate project * `nim.licenseString` - optional license text that will be inserted on nim file creation @@ -58,7 +58,7 @@ The following Visual Studio Code settings are available for the Nim extension. "nim.buildOnSave": false, "nim.buildCommand": "c", "nim.lintOnSave": true, - "nim.project": ["project.nim", "project2.nim"], + "nim.project": ["project.nim", "project2.nim", "src/**/*.nim"], "nim.licenseString": "# Copyright 2017.\n\n" } ``` diff --git a/package.json b/package.json index 0982965..58439d7 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "bugs": { "url": "https://github.com/pragmagic/vscode-nim/issues" - }, + }, "scripts": { "vscode:prepublish": "tsc -p ./", "compile": "tsc -watch -p ./", @@ -32,7 +32,8 @@ "lint": "node ./node_modules/tslint/bin/tslint ./src/*.ts ./test/*.ts" }, "dependencies": { - "nedb": "1.8.0" + "nedb": "1.8.0", + "glob": "^7.1.2" }, "devDependencies": { "typescript": "^2.0.3", @@ -40,7 +41,8 @@ "mocha": "^2.3.3", "tslint": "^4.3.1", "@types/node": "^6.0.40", - "@types/mocha": "^2.2.32" + "@types/mocha": "^2.2.32", + "@types/glob": "^5.0.35" }, "engines": { "vscode": "^1.7.0" @@ -154,4 +156,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/nimUtils.ts b/src/nimUtils.ts index 15e25e3..08a200a 100644 --- a/src/nimUtils.ts +++ b/src/nimUtils.ts @@ -10,6 +10,7 @@ import path = require('path'); import os = require('os'); import cp = require('child_process'); import vscode = require('vscode'); +import glob = require('glob'); import { showNimStatus, hideNimStatus } from './nimStatus'; let _pathesCache: { [tool: string]: string; } = {}; @@ -72,6 +73,14 @@ export function getProjects(): string[] { return _projects; } +export function parsePath(p: string): string[] { + if (path.isAbsolute(p)) return [p]; + if (glob.hasMagic(p)) { + return glob.sync(p, {cwd: vscode.workspace.rootPath}); + } + return [path.resolve(vscode.workspace.rootPath, p)]; +} + export function prepareConfig(): void { let config = vscode.workspace.getConfiguration('nim'); let projects = config['project']; @@ -79,10 +88,10 @@ export function prepareConfig(): void { if (projects) { if (projects instanceof Array) { projects.forEach((project) => { - _projects.push(path.isAbsolute(project) ? project : path.resolve(vscode.workspace.rootPath, project)); + _projects.push(...parsePath(project)); }); } else { - _projects.push(path.isAbsolute(projects) ? projects : path.resolve(vscode.workspace.rootPath, projects)); + _projects.push(...parsePath(projects)); } } } @@ -137,4 +146,4 @@ export function removeDirSync(p: string): void { }); fs.rmdirSync(p); } -}; \ No newline at end of file +};