当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fileService.FileService类代码示例

本文整理汇总了TypeScript中vs/workbench/services/files/node/fileService.FileService的典型用法代码示例。如果您正苦于以下问题:TypeScript FileService类的具体用法?TypeScript FileService怎么用?TypeScript FileService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileService类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

			return service.createFolder(folderResource).then(f => {
				const resource = uri.file(path.join(testDir, 'deep', 'conway.js'));
				return service.importFile(resource, uri.file(testDir)).then(res => {
					assert.equal(fs.existsSync(res.stat.resource.fsPath), true);
					assert.ok(fs.readdirSync(testDir).some(f => f === 'conway.js'));
					assert.ok(fs.statSync(res.stat.resource.fsPath).isFile);

					assert.ok(createEvent);
					assert.ok(deleteEvent);
					assert.ok(importEvent);

					assert.equal(importEvent.resource.fsPath, resource.fsPath);
					assert.equal(importEvent.target.resource.fsPath, res.stat.resource.fsPath);

					assert.equal(deleteEvent.resource.fsPath, folderResource.fsPath);

					toDispose.dispose();

					done();
				});
			});
开发者ID:armanio123,项目名称:vscode,代码行数:21,代码来源:fileService.test.ts

示例2: function

	test('watchFileChanges - support atomic save', function (done: () => void) {
		let toWatch = uri.file(path.join(testDir, 'index.html'));

		service.watchFileChanges(toWatch);

		events.addListener2(EventType.FILE_CHANGES, (e: FileChangesEvent) => {
			assert.ok(e);

			service.unwatchFileChanges(toWatch);
			done();
		});

		setTimeout(() => {
			// Simulate atomic save by deleting the file, creating it under different name
			// and then replacing the previously deleted file with those contents
			const renamed = `${toWatch.fsPath}.bak`;
			fs.unlinkSync(toWatch.fsPath);
			fs.writeFileSync(renamed, 'Changes');
			fs.renameSync(renamed, toWatch.fsPath);
		}, 100);
	});
开发者ID:sandy081,项目名称:vscode,代码行数:21,代码来源:fileService.test.ts

示例3:

			fs.readFile(resource.fsPath, (error, data) => {
				assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);

				const model = TextModel.createFromString('Hello Bom');

				// Update content: UTF_8 => UTF_8_BOM
				_service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8_with_bom }).done(() => {
					fs.readFile(resource.fsPath, (error, data) => {
						assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);

						// Update content: PRESERVE BOM when using UTF-8
						model.setValue('Please stay Bom');
						_service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8 }).done(() => {
							fs.readFile(resource.fsPath, (error, data) => {
								assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);

								// Update content: REMOVE BOM
								model.setValue('Go away Bom');
								_service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8, overwriteEncoding: true }).done(() => {
									fs.readFile(resource.fsPath, (error, data) => {
										assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);

										// Update content: BOM comes not back
										model.setValue('Do not come back Bom');
										_service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8 }).done(() => {
											fs.readFile(resource.fsPath, (error, data) => {
												assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);

												model.dispose();
												_service.dispose();
												done();
											});
										});
									});
								});
							});
						});
					});
				});
			});
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:40,代码来源:fileService.test.ts

示例4: preserved

	test('updateContent - encoding preserved (UTF 16 LE, ITextSnapShot)', function () {
		const encoding = 'utf16le';
		const resource = uri.file(path.join(testDir, 'some_utf16le.css'));

		return service.resolveContent(resource).then(c => {
			assert.equal(c.encoding, encoding);

			const model = TextModel.createFromString('Some updates');

			return service.updateContent(c.resource, model.createSnapshot(), { encoding: encoding }).then(c => {
				return encodingLib.detectEncodingByBOM(c.resource.fsPath).then((enc) => {
					assert.equal(enc, encodingLib.UTF16le);

					return service.resolveContent(resource).then(c => {
						assert.equal(c.encoding, encoding);

						model.dispose();
					});
				});
			});
		});
	});
开发者ID:sameer-coder,项目名称:vscode,代码行数:22,代码来源:fileService.test.ts

示例5: nfcall

	test('updateContent - encoding preserved (UTF 16 LE)', function(done: () => void) {
		let charset = 'utf16le';
		let resource = uri.file(path.join(testDir, 'some_utf16le.css'));

		service.resolveContent(resource).done(c => {
			assert.equal(c.charset, charset);

			c.value = 'Some updates';

			return service.updateContent(c.resource, c.value, { charset: charset }).then(c => {
				return nfcall(encoding.detectEncodingByBOM, c.resource.fsPath).then((enc) => {
					assert.equal(enc, encoding.UTF16le);

					return service.resolveContent(resource).then(c => {
						assert.equal(c.charset, charset);

						done();
					});
				});
			});
		});
	});
开发者ID:sangohan,项目名称:KodeStudio,代码行数:22,代码来源:fileService.test.ts

示例6:

							return pfs.readFile(resource.fsPath).then(data => {
								assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);

								// Update content: REMOVE BOM
								model.setValue('Go away Bom');
								return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8, overwriteEncoding: true }).then(() => {
									return pfs.readFile(resource.fsPath).then(data => {
										assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);

										// Update content: BOM comes not back
										model.setValue('Do not come back Bom');
										return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8 }).then(() => {
											return pfs.readFile(resource.fsPath).then(data => {
												assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);

												model.dispose();
												_service.dispose();
											});
										});
									});
								});
							});
开发者ID:sameer-coder,项目名称:vscode,代码行数:22,代码来源:fileService.test.ts

示例7: nfcall

	test('updateContent - encoding preserved (UTF 16 LE)', function (done: () => void) {
		let encoding = 'utf16le';
		let resource = uri.file(path.join(testDir, 'some_utf16le.css'));

		service.resolveContent(resource).done(c => {
			assert.equal(c.encoding, encoding);

			c.value = 'Some updates';

			return service.updateContent(c.resource, c.value, { encoding: encoding }).then(c => {
				return nfcall(encodingLib.detectEncodingByBOM, c.resource.fsPath).then((enc) => {
					assert.equal(enc, encodingLib.UTF16le);

					return service.resolveContent(resource).then(c => {
						assert.equal(c.encoding, encoding);

						done();
					});
				});
			});
		}, error => onError(error, done));
	});
开发者ID:elemongw,项目名称:vscode,代码行数:22,代码来源:fileService.test.ts

示例8: encoding

	test('updateContent - use encoding (UTF 16 BE, ITextSnapShot)', function () {
		const resource = uri.file(path.join(testDir, 'small.txt'));
		const encoding = 'utf16be';

		return service.resolveContent(resource).then(c => {
			c.encoding = encoding;

			const model = TextModel.createFromString(c.value);

			return service.updateContent(c.resource, model.createSnapshot(), { encoding: encoding }).then(c => {
				return encodingLib.detectEncodingByBOM(c.resource.fsPath).then((enc) => {
					assert.equal(enc, encodingLib.UTF16be);

					return service.resolveContent(resource).then(c => {
						assert.equal(c.encoding, encoding);

						model.dispose();
					});
				});
			});
		});
	});
开发者ID:sameer-coder,项目名称:vscode,代码行数:22,代码来源:fileService.test.ts

示例9: onError

		service.resolveFile(uri.file(testDir)).done(parent => {
			const folderResource = uri.file(path.join(parent.resource.fsPath, 'conway.js'));
			return service.createFolder(folderResource).then(f => {
				const resource = uri.file(path.join(testDir, 'deep', 'conway.js'));
				return service.copyFile(resource, f.resource, true).then(copied => {
					assert.equal(fs.existsSync(copied.resource.fsPath), true);
					assert.ok(fs.statSync(copied.resource.fsPath).isFile);

					assert.ok(createEvent);
					assert.ok(deleteEvent);
					assert.ok(copyEvent);

					assert.equal(copyEvent.resource.fsPath, resource.fsPath);
					assert.equal(copyEvent.target.resource.fsPath, copied.resource.fsPath);

					assert.equal(deleteEvent.resource.fsPath, folderResource.fsPath);

					toDispose.dispose();

					done();
				});
			});
		}, error => onError(error, done));
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:23,代码来源:fileService.test.ts


注:本文中的vs/workbench/services/files/node/fileService.FileService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。