export async function computeWorkspaceType(): Promise<HaskellWorkspaceType> { const configType = vscode.workspace.getConfiguration('ghcSimple').workspaceType as HaskellWorkspaceType | 'detect'; if (configType !== 'detect') return configType; const isStack = await vscode.workspace.findFiles('stack.yaml'); if (isStack.length > 0) return 'stack'; const isCabal = await vscode.workspace.findFiles('**/*.cabal'); if (isCabal.length > 0) return 'cabal'; const hasStack = await new Promise<boolean>((resolve, reject) => { const cp = child_process.exec( 'stack --help', { cwd: vscode.workspace.rootPath, timeout: 5000 }, (err, stdout, stderr) => { if (err) resolve(false); else resolve(true); } ) }); if (hasStack) return 'bare-stack' else return 'bare'; }
function selectDotEnsime(callback, filterMethod = (dotEnsime) => true) { let dirs = [vscode.workspace.rootPath] let dotEnsimeUris = vscode.workspace.findFiles("**/.ensime", "node_modules", 10) let toString = (uris: vscode.Uri[]) => uris.map((uri) => uri.fsPath) dotEnsimeUris.then((uris) => { if(!uris) { vscode.window.showErrorMessage("You are not in a workspace. Please open a project before using ENSIME.") return } let dotEnsimes = toString(uris) let filteredDotEnsime = dotEnsimes.filter(filterMethod) if(filteredDotEnsime.length == 0) { vscode.window.showErrorMessage("No .ensime file found. Please generate with `sbt gen-ensime` or similar") } else if (filteredDotEnsime.length == 1) { callback(filteredDotEnsime[0]) } else { vscode.window.showQuickPick(filteredDotEnsime).then((item) => callback(item)) } }) }
async function detectNpmScripts(): Promise<Task[]> { let emptyTasks: Task[] = []; let allTasks: Task[] = []; let visitedPackageJsonFiles: Set<string> = new Set(); let folders = workspace.workspaceFolders; if (!folders) { return emptyTasks; } try { for (const folder of folders) { if (isAutoDetectionEnabled(folder)) { let relativePattern = new RelativePattern(folder, '**/package.json'); let paths = await workspace.findFiles(relativePattern, '**/node_modules/**'); for (const path of paths) { if (!isExcluded(folder, path) && !visitedPackageJsonFiles.has(path.fsPath)) { let tasks = await provideNpmScriptsForFolder(path); visitedPackageJsonFiles.add(path.fsPath); allTasks.push(...tasks); } } } } return allTasks; } catch (error) { return Promise.reject(error); } }
private processAllFilesInWorkspace() { if (workspace.rootPath == undefined) return; var fileProcessCount = 0; // Find all the php files to process workspace.findFiles('**/*.php', '').then(files => { console.log(`Files to parse: ${files.length}`); fileProcessCount = files.length; var filePaths: string[] = []; // Get the objects path value for the current file system files.forEach(file => { filePaths.push(file.fsPath); }); // Send the array of paths to the language server this.langClient.sendRequest({ method: "buildFromFiles" }, { files: filePaths }); }); // Update the UI so the user knows the processing status var fileProcessed: NotificationType<any> = { method: "fileProcessed" }; this.langClient.onNotification(fileProcessed, data => { // Get the percent complete var percent:string = ((data.total / fileProcessCount) * 100).toFixed(2); this.statusBarItem.text = `$(zap) Processing source files (${data.total} of ${fileProcessCount} / ${percent}%)`; // Once all files have been processed, update the statusBarItem if(data.total == fileProcessCount){ this.statusBarItem.text = 'File Processing Complete'; } }); }
let buildMap = async (args: any[]) => { let config = vscode.workspace.getConfiguration("wurst"); let mapPromise: Thenable<string>; if (args && args.length > 0) { mapPromise = Promise.resolve(args[0]); } else { let items = workspace.findFiles('*.w3x', null, 10) .then(uris => uris.sort(function(a, b) { return fs.statSync(b.fsPath).mtime.getTime() - fs.statSync(a.fsPath).mtime.getTime(); })) .then(uris => uris.map(uri => uri.path)) mapPromise = window.showQuickPick(items) } let mappath = await mapPromise; if (!mappath) { return Promise.reject("No map selected."); } let request: ExecuteCommandParams = { command: "wurst.buildmap", arguments: [{ 'mappath': mappath }] }; return client.sendRequest(ExecuteCommandRequest.type, request) };
export async function provideNpmScripts(): Promise<Task[]> { let emptyTasks: Task[] = []; let allTasks: Task[] = []; let folders = workspace.workspaceFolders; if (!folders) { return emptyTasks; } try { for (let i = 0; i < folders.length; i++) { let folder = folders[i]; if (isAutoDetectionEnabled(folder)) { let relativePattern = new RelativePattern(folder, '**/package.json'); let paths = await workspace.findFiles(relativePattern, '**/node_modules/**'); for (let j = 0; j < paths.length; j++) { if (!isExcluded(folder, paths[j])) { let tasks = await provideNpmScriptsForFolder(paths[j]); allTasks.push(...tasks); } } } } return allTasks; } catch (error) { return Promise.reject(error); } }
function getYoForceConfig() { return vscode.workspace.findFiles('force.json', '').then(function (files) { var buffer: NodeBuffer = undefined; var data: any = {}; if (files.length && files[0].path) { buffer = fs.readFileSync(files[0].path); try { data = JSON.parse(buffer.toString()); } catch (error) { vscode.window.forceCode.outputChannel.appendLine(error); } return new Promise((resolve, reject) => { try { keychain.getPassword({ account: data.username, service: constants.FORCECODE_KEYCHAIN, }, function (err, pass) { data.password = pass; resolve(data); }); } catch (error) { console.error(error); data.password = (vscode.window.forceCode.config.password || '') + (vscode.window.forceCode.config.token || ''); resolve(data); } }); } return data; }); }
export function forceApexTestRun(testClass?: string) { if (testClass) { runTestClass(testClass); } else { vscode.workspace.findFiles('**/*.testSuite-meta.xml', '').then(files => { const fileItems: vscode.QuickPickItem[] = files.map(file => { return { label: path .basename(file.toString()) .replace('.testSuite-meta.xml', ''), description: file.fsPath }; }); fileItems.push({ label: 'All tests', description: 'Runs all tests in the current workspace' }); vscode.window.showQuickPick(fileItems).then(selection => { if (selection) { if (selection.label === 'All tests') { runAllTests(); } else { runTestSuite(selection.label); } } }); }); } }
export async function registerTaskProvider(ctx: vscode.ExtensionContext) { let rakePromise: Thenable<vscode.Task[]> | undefined = undefined; let files = await vscode.workspace.findFiles("**/[rR]akefile{,.rb}"); for (let i = 0; i < files.length; i++) { rakeFiles.add(files[i]); } let fileWatcher = vscode.workspace.createFileSystemWatcher("**/[rR]akefile{,.rb}"); fileWatcher.onDidChange(() => rakePromise = undefined); fileWatcher.onDidCreate((uri) => { rakeFiles.add(uri); rakePromise = undefined }); fileWatcher.onDidDelete((uri) => { rakeFiles.delete(uri); rakePromise = undefined }); let taskProvider = vscode.workspace.registerTaskProvider('rake', { provideTasks: () => { if (!rakePromise) { rakePromise = getRakeTasks(); } return rakePromise; }, resolveTask(_task: vscode.Task): vscode.Task | undefined { return undefined; } }); }
let startMap = async (cmd: "wurst.startmap" | "wurst.hotstartmap" , args: any[]) => { let config = vscode.workspace.getConfiguration("wurst"); let wc3path = config.get<string>("wc3path"); if (!wc3path) { return Promise.reject("Warcraft path not set (change 'wurst.wc3path' in your settings)."); } let mapPromise: Thenable<string>; if (args && args.length > 0) { mapPromise = Promise.resolve(args[0]); } else { let items = workspace.findFiles('*.w3x', null, 10) .then(uris => uris.sort(function(a, b) { return fs.statSync(b.fsPath).mtime.getTime() - fs.statSync(a.fsPath).mtime.getTime(); })) .then(uris => uris.map(uri => uri.path)) mapPromise = window.showQuickPick(items) } let mappath = await mapPromise; if (!mappath) { return Promise.reject("No map selected."); } let request: ExecuteCommandParams = { command: cmd, arguments: [{ 'mappath': mappath, 'wc3path': wc3path }] }; _lastMapConfig = mappath return client.sendRequest(ExecuteCommandRequest.type, request) };