vscode-languageclient#WorkspaceFolder TypeScript Examples

The following examples show how to use vscode-languageclient#WorkspaceFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: commands.ts    From macro-executor with MIT License 6 votes vote down vote up
// Set Compiler
async function setCompiler() {
	pickFolder(workspace => {
		const config = vscode.workspace.getConfiguration('macro', workspace);
		const quickPickOptions = {
			matchOnDetail: true,
			matchOnDescription: false,
			placeHolder: `current: ${config.build.compiler}`
		};
	
		vscode.window.showQuickPick(COMPILER, quickPickOptions).then(value => {
			if (value !== undefined) {
				config.update('build.compiler', value, vscode.ConfigurationTarget.WorkspaceFolder).then(() => {
					//Done
				}, reason => {
					vscode.window.showErrorMessage(`Failed to set 'compilerPath'. Error: ${reason.message}`);
					console.error(reason);
				});
			}
		});
	});
}
Example #2
Source File: commands.ts    From macro-executor with MIT License 6 votes vote down vote up
async function setControlType () {
	pickFolder(workspace => {
		const config = vscode.workspace.getConfiguration('macro', workspace);
		const quickPickOptions = {
			matchOnDetail: true,

			matchOnDescription: false,
			placeHolder: `current: ${config.build.controlType}`
		};

		vscode.window.showQuickPick(CONTROL_TYPE, quickPickOptions).then(value => {
			if (value !== undefined) {
				config.update('build.controlType', value, vscode.ConfigurationTarget.WorkspaceFolder).then(() => {
					//Done
				}, reason => {
					vscode.window.showErrorMessage(`Failed to set 'controlType'. Error: ${reason.message}`);
					console.error(reason);
				});
			}
		});
	});
}
Example #3
Source File: commands.ts    From macro-executor with MIT License 6 votes vote down vote up
function pickFolder(cb:(workspace:vscode.WorkspaceFolder) => void) {
	const folders = vscode.workspace.workspaceFolders;
	if (folders.length === 1) {
		cb(folders[0]);
		return;
	}
	vscode.window.showWorkspaceFolderPick({placeHolder:'', ignoreFocusOut:true}).then(selected => {
		if (selected) {
			cb(selected);
		}
	});
	if (folders.length === 1) {
		cb(folders[0]);
		return;
	}
}
Example #4
Source File: commands.ts    From macro-executor with MIT License 5 votes vote down vote up
public getCompileCommand(workspace:vscode.WorkspaceFolder, dir:string|undefined=undefined) : string | undefined {
		const config = vscode.workspace.getConfiguration('macro', workspace);
		const compiler 	= config.build.compiler;
		const type 		= config.build.controlType;
		const prm 		= config.build.compilerParams;
		const buildPath	= config.project.buildPath;
		const currentFile = vscode.window.activeTextEditor?.document.uri.fsPath;

		let fileDir = '';
		let filesPattern = '';

		if (dir !== undefined) {
			const relativ = this.getRelativePath(dir, workspace.uri.fsPath);
			fileDir = relativ;
			filesPattern = path.join(relativ, '*.src');
		}
		else if (currentFile){
			fileDir = this.getRelativePath(path.dirname(currentFile), workspace.uri.fsPath);
			filesPattern = this.getRelativePath(currentFile, workspace.uri.fsPath);
		}
		else {
			return undefined;
		}

		let args:any[] = [];
		args.push(filesPattern);
		args.push('-'+type);
		args.push(prm);

		if (buildPath){
			const buildDir = this.getRelativePath(buildPath, workspace.uri.fsPath);
			args.push('-Fo' + buildDir);
			args.push('-Fr' + buildDir);
			args.push('-Fp' + buildDir);
		}

		if (fileDir) {
			args.push('-Fl' + fileDir);
		}
		return compiler + ' '+ args.join(' ');
	}
Example #5
Source File: commands.ts    From macro-executor with MIT License 5 votes vote down vote up
public async getLinkCommand(workspace:vscode.WorkspaceFolder, dir:string|undefined=undefined) : Promise<string | undefined> {
		const config 	= vscode.workspace.getConfiguration('macro', workspace);
		const buildPath	= config.project.buildPath;
		const exportPath= config.project.exportPath;
		const compiler 	= config.build.compiler;
		const params 	= config.build.linkerParams;
		const link 		= this.getRelativePath(config.project.linkPath, workspace.uri.fsPath);

		let glob = '**/*.{[lL][nN][kK]}';
		if (link){
			glob = path.join(link,'/', glob);
		}

		const lnkFiles = await vscode.workspace.findFiles(new vscode.RelativePattern(workspace, glob));
		if (!lnkFiles) {
			return undefined;
		}

		const lines:string[] = [];		
		let linkPath = '';
		if (buildPath) {
			lines.push('cd ' + buildPath);
			lines.push('\n\r');
			linkPath = '..\\';
		}

		for (const file of lnkFiles) {	
			lines.push(BUILD_SYSTEMS[compiler].linker + ' ' + params);
			lines.push(linkPath + this.getRelativePath(file.fsPath, workspace.uri.fsPath));
			lines.push('\n\r');
			lines.push(BUILD_SYSTEMS[compiler].card);
			lines.push(path.parse(this.getRelativePath(path.basename(file.fsPath), workspace.uri.fsPath)).name);
			lines.push('\n\r');
		}	

		if (exportPath) {
			let p = '';
			if (path.isAbsolute(exportPath)) {
				p = path.normalize(exportPath);
			}
			else {
				p = path.join('..\\',this.getRelativePath(exportPath, workspace.uri.fsPath));
			}
			lines.push('copy *.mem');
			lines.push(p);
		}		
		return lines.join(' ');
	}
Example #6
Source File: commands.ts    From macro-executor with MIT License 5 votes vote down vote up
public async getCleanCommand(workspace:vscode.WorkspaceFolder) : Promise<string> {
		const config 	= vscode.workspace.getConfiguration('macro', workspace);
		const makeFile	= config.build.makeFile;

		// Execute internal build script
		if (makeFile === undefined || makeFile === '') {

			
			let source = this.getRelativePath(config.project.sourcePath, workspace.uri.fsPath);
			let build = this.getRelativePath(config.project.buildPath, workspace.uri.fsPath);
			if (source){
				source = path.join(source,'/');
			}
			else {
				source = '';
			}
			if (build){
				build = path.join(build,'/');
			}
			else {
				build = '';
			}
			const lines:string[] = [];
			lines.push('del ' + source + '*.LST');
			lines.push('\n\r');
	
			for (const ext of build_ext_glob){
				lines.push('del ' + build + '*.'+ ext);
				lines.push('\n\r');
			}
			return lines.join(' ');
		}
		else {
			const make = this.getRelativePath(path.dirname(makeFile), workspace.uri.fsPath);
			let glob = '**/{[cC][lL][eE][aA][nN]}.*';
			if (make) {
				glob = path.join(make, '/', glob);
			}

			const files = await vscode.workspace.findFiles(new vscode.RelativePattern(workspace, glob));
			if (files.length > 0) {		
				const cleanFile = this.getRelativePath(files[0].fsPath, workspace.uri.fsPath);
				return '.\\' + cleanFile;
			}
			else {
				return '.\\' + makeFile + ' ' + ['0', 'clean'].join(' ');
			}
		}
	}