files2 - adopt new methods

This commit is contained in:
Benjamin Pasero
2019-04-16 12:18:04 +02:00
parent 96d03958ae
commit 31ffdc0eb5
27 changed files with 106 additions and 112 deletions
-7
View File
@@ -101,11 +101,6 @@ export interface IFileService {
*/
exists(resource: URI): Promise<boolean>;
/**
* @deprecated use readFile() instead.
*/
resolveContent(resource: URI, options?: IReadTextFileOptions): Promise<IContent>;
/**
* Read the contents of the provided resource unbuffered.
*/
@@ -1203,6 +1198,4 @@ export interface ILegacyFileService extends IDisposable {
onAfterOperation: Event<FileOperationEvent>;
registerProvider(scheme: string, provider: IFileSystemProvider): IDisposable;
resolveContent(resource: URI, options?: IReadTextFileOptions): Promise<IContent>;
}
@@ -15,7 +15,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ResourceViewerContext, ResourceViewer } from 'vs/workbench/browser/parts/editor/resourceViewer';
import { URI } from 'vs/base/common/uri';
import { Dimension, size, clearNode } from 'vs/base/browser/dom';
import { IFileService } from 'vs/platform/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { CancellationToken } from 'vs/base/common/cancellation';
import { dispose } from 'vs/base/common/lifecycle';
import { IStorageService } from 'vs/platform/storage/common/storage';
@@ -47,7 +47,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
callbacks: IOpenCallbacks,
telemetryService: ITelemetryService,
themeService: IThemeService,
@IFileService private readonly _fileService: IFileService,
@ITextFileService private readonly textFileService: ITextFileService,
@IStorageService storageService: IStorageService
) {
super(id, telemetryService, themeService, storageService);
@@ -89,7 +89,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
// Render Input
this.resourceViewerContext = ResourceViewer.show(
{ name: model.getName(), resource: model.getResource(), size: model.getSize(), etag: model.getETag(), mime: model.getMime() },
this._fileService,
this.textFileService,
this.binaryContainer,
this.scrollbar,
resource => this.handleOpenInternalCallback(input, options),
@@ -1144,7 +1144,8 @@ export class ChangeEncodingAction extends Action {
@IEditorService private readonly editorService: IEditorService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@ITextResourceConfigurationService private readonly textResourceConfigurationService: ITextResourceConfigurationService,
@IFileService private readonly fileService: IFileService
@IFileService private readonly fileService: IFileService,
@ITextFileService private readonly textFileService: ITextFileService
) {
super(actionId, actionLabel);
}
@@ -1195,7 +1196,7 @@ export class ChangeEncodingAction extends Action {
return Promise.resolve(null); // encoding detection only possible for resources the file service can handle
}
return this.fileService.resolveContent(resource, { autoGuessEncoding: true, acceptTextOnly: true }).then(content => content.encoding, err => null);
return this.textFileService.read(resource, { autoGuessEncoding: true, acceptTextOnly: true }).then(content => content.encoding, err => null);
})
.then((guessedEncoding: string) => {
const isReopenWithEncoding = (action === reopenWithEncodingPick);
@@ -21,7 +21,7 @@ import { Action } from 'vs/base/common/actions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { memoize } from 'vs/base/common/decorators';
import * as platform from 'vs/base/common/platform';
import { IFileService } from 'vs/platform/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
export interface IResourceDescriptor {
readonly resource: URI;
@@ -72,7 +72,7 @@ export class ResourceViewer {
static show(
descriptor: IResourceDescriptor,
fileService: IFileService,
textFileService: ITextFileService,
container: HTMLElement,
scrollbar: DomScrollableElement,
openInternalClb: (uri: URI) => void,
@@ -85,7 +85,7 @@ export class ResourceViewer {
// Images
if (ResourceViewer.isImageResource(descriptor)) {
return ImageView.create(container, descriptor, fileService, scrollbar, openExternalClb, metadataClb);
return ImageView.create(container, descriptor, textFileService, scrollbar, openExternalClb, metadataClb);
}
// Large Files
@@ -114,13 +114,13 @@ class ImageView {
static create(
container: HTMLElement,
descriptor: IResourceDescriptor,
fileService: IFileService,
textFileService: ITextFileService,
scrollbar: DomScrollableElement,
openExternalClb: (uri: URI) => void,
metadataClb: (meta: string) => void
): ResourceViewerContext {
if (ImageView.shouldShowImageInline(descriptor)) {
return InlineImageView.create(container, descriptor, fileService, scrollbar, metadataClb);
return InlineImageView.create(container, descriptor, textFileService, scrollbar, metadataClb);
}
return LargeImageView.create(container, descriptor, openExternalClb, metadataClb);
@@ -357,7 +357,7 @@ class InlineImageView {
static create(
container: HTMLElement,
descriptor: IResourceDescriptor,
fileService: IFileService,
textFileService: ITextFileService,
scrollbar: DomScrollableElement,
metadataClb: (meta: string) => void
) {
@@ -559,7 +559,7 @@ class InlineImageView {
}
}));
InlineImageView.imageSrc(descriptor, fileService).then(dataUri => {
InlineImageView.imageSrc(descriptor, textFileService).then(dataUri => {
const imgs = container.getElementsByTagName('img');
if (imgs.length) {
imgs[0].src = dataUri;
@@ -569,12 +569,12 @@ class InlineImageView {
return context;
}
private static imageSrc(descriptor: IResourceDescriptor, fileService: IFileService): Promise<string> {
private static imageSrc(descriptor: IResourceDescriptor, textFileService: ITextFileService): Promise<string> {
if (descriptor.resource.scheme === Schemas.data) {
return Promise.resolve(descriptor.resource.toString(true /* skip encoding */));
}
return fileService.resolveContent(descriptor.resource, { encoding: 'base64' }).then(data => {
return textFileService.read(descriptor.resource, { encoding: 'base64' }).then(data => {
const mime = getMime(descriptor);
return `data:${mime};base64,${data.value}`;
@@ -97,7 +97,7 @@ export class LanguageConfigurationFileHandler {
}
private _handleConfigFile(languageIdentifier: LanguageIdentifier, configFileLocation: URI): void {
this._fileService.resolveContent(configFileLocation, { encoding: 'utf8' }).then((contents) => {
this._fileService.readFile(configFileLocation).then((contents) => {
const errors: ParseError[] = [];
const configuration = <ILanguageConfiguration>parse(contents.value.toString(), errors);
if (errors.length) {
@@ -559,7 +559,7 @@ class Launch extends AbstractLaunch implements ILaunch {
const resource = this.uri;
let created = false;
return this.fileService.resolveContent(resource).then(content => content.value, err => {
return this.fileService.readFile(resource).then(content => content.value, err => {
// launch.json not found: create one by collecting launch configs from debugConfigProviders
return this.configurationManager.guessDebugger(type).then(adapter => {
if (adapter) {
@@ -585,10 +585,11 @@ class Launch extends AbstractLaunch implements ILaunch {
if (!content) {
return { editor: null, created: false };
}
const index = content.indexOf(`"${this.configurationManager.selectedConfiguration.name}"`);
const contentValue = content.toString();
const index = contentValue.indexOf(`"${this.configurationManager.selectedConfiguration.name}"`);
let startLineNumber = 1;
for (let i = 0; i < index; i++) {
if (content.charAt(i) === '\n') {
if (contentValue.charAt(i) === '\n') {
startLineNumber++;
}
}
@@ -45,6 +45,7 @@ import { IExperimentService, ExperimentActionType, ExperimentState } from 'vs/wo
import { CancellationToken } from 'vs/base/common/cancellation';
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
import { extname } from 'vs/base/common/resources';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
const milliSecondsInADay = 1000 * 60 * 60 * 24;
const choiceNever = localize('neverShowAgain', "Don't Show Again");
@@ -108,6 +109,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
@IExperimentService private readonly experimentService: IExperimentService,
@ITextFileService private readonly textFileService: ITextFileService
) {
super();
@@ -325,8 +327,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
return Promise.resolve(null);
}
return Promise.resolve(this.fileService.resolveContent(workspace.configuration)
.then(content => <IExtensionsConfigContent>(json.parse(content.value)['extensions']), err => null));
return Promise.resolve(this.fileService.readFile(workspace.configuration)
.then(content => <IExtensionsConfigContent>(json.parse(content.value.toString())['extensions']), err => null));
}
/**
@@ -336,8 +338,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
const extensionsJsonUri = workspaceFolder.toResource(EXTENSIONS_CONFIG);
return Promise.resolve(this.fileService.resolve(extensionsJsonUri)
.then(() => this.fileService.resolveContent(extensionsJsonUri))
.then(content => <IExtensionsConfigContent>json.parse(content.value), err => null));
.then(() => this.fileService.readFile(extensionsJsonUri))
.then(content => <IExtensionsConfigContent>json.parse(content.value.toString()), err => null));
}
/**
@@ -956,7 +958,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
const storageKey = 'extensionsAssistant/dynamicWorkspaceRecommendations';
const workspaceUri = this.contextService.getWorkspace().folders[0].uri;
return Promise.all([getHashedRemotesFromUri(workspaceUri, this.fileService, false), getHashedRemotesFromUri(workspaceUri, this.fileService, true)]).then(([hashedRemotes1, hashedRemotes2]) => {
return Promise.all([getHashedRemotesFromUri(workspaceUri, this.fileService, this.textFileService, false), getHashedRemotesFromUri(workspaceUri, this.fileService, this.textFileService, true)]).then(([hashedRemotes1, hashedRemotes2]) => {
const hashedRemotes = (hashedRemotes1 || []).concat(hashedRemotes2 || []);
if (!hashedRemotes.length) {
return undefined;
@@ -22,7 +22,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
import { ShowViewletAction } from 'vs/workbench/browser/viewlet';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { Query } from 'vs/workbench/contrib/extensions/common/extensionQuery';
import { IFileService, IContent } from 'vs/platform/files/common/files';
import { IFileService, IFileContent } from 'vs/platform/files/common/files';
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -2031,7 +2031,7 @@ export abstract class AbstractConfigureRecommendedExtensionsAction extends Actio
protected openWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<any> {
return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
.then(content => this.getSelectionPosition(content.value, content.resource, ['extensions', 'recommendations']))
.then(content => this.getSelectionPosition(content.value.toString(), content.resource, ['extensions', 'recommendations']))
.then(selection => this.editorService.openEditor({
resource: workspaceConfigurationFile,
options: {
@@ -2045,7 +2045,7 @@ export abstract class AbstractConfigureRecommendedExtensionsAction extends Actio
return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
.then(content => {
const extensionIdLowerCase = extensionId.toLowerCase();
const workspaceExtensionsConfigContent: IExtensionsConfigContent = (json.parse(content.value) || {})['extensions'] || {};
const workspaceExtensionsConfigContent: IExtensionsConfigContent = (json.parse(content.value.toString()) || {})['extensions'] || {};
let insertInto = shouldRecommend ? workspaceExtensionsConfigContent.recommendations || [] : workspaceExtensionsConfigContent.unwantedRecommendations || [];
let removeFrom = shouldRecommend ? workspaceExtensionsConfigContent.unwantedRecommendations || [] : workspaceExtensionsConfigContent.recommendations || [];
@@ -2105,26 +2105,26 @@ export abstract class AbstractConfigureRecommendedExtensionsAction extends Actio
}
protected getWorkspaceExtensionsConfigContent(extensionsFileResource: URI): Promise<IExtensionsConfigContent> {
return Promise.resolve(this.fileService.resolveContent(extensionsFileResource))
return Promise.resolve(this.fileService.readFile(extensionsFileResource))
.then(content => {
return (json.parse(content.value) || {})['extensions'] || {};
return (json.parse(content.value.toString()) || {})['extensions'] || {};
}, err => ({ recommendations: [], unwantedRecommendations: [] }));
}
protected getWorkspaceFolderExtensionsConfigContent(extensionsFileResource: URI): Promise<IExtensionsConfigContent> {
return Promise.resolve(this.fileService.resolveContent(extensionsFileResource))
return Promise.resolve(this.fileService.readFile(extensionsFileResource))
.then(content => {
return (<IExtensionsConfigContent>json.parse(content.value));
return (<IExtensionsConfigContent>json.parse(content.value.toString()));
}, err => ({ recommendations: [], unwantedRecommendations: [] }));
}
private getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<IContent> {
return Promise.resolve(this.fileService.resolveContent(workspaceConfigurationFile))
private getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<IFileContent> {
return Promise.resolve(this.fileService.readFile(workspaceConfigurationFile))
.then(content => {
const workspaceRecommendations = <IExtensionsConfigContent>json.parse(content.value)['extensions'];
const workspaceRecommendations = <IExtensionsConfigContent>json.parse(content.value.toString())['extensions'];
if (!workspaceRecommendations || !workspaceRecommendations.recommendations) {
return this.jsonEditingService.write(workspaceConfigurationFile, { key: 'extensions', value: { recommendations: [] } }, true)
.then(() => this.fileService.resolveContent(workspaceConfigurationFile));
.then(() => this.fileService.readFile(workspaceConfigurationFile));
}
return content;
});
@@ -2153,8 +2153,8 @@ export abstract class AbstractConfigureRecommendedExtensionsAction extends Actio
}
private getOrCreateExtensionsFile(extensionsFileResource: URI): Promise<{ created: boolean, extensionsFileResource: URI, content: string }> {
return Promise.resolve(this.fileService.resolveContent(extensionsFileResource)).then(content => {
return { created: false, extensionsFileResource, content: content.value };
return Promise.resolve(this.fileService.readFile(extensionsFileResource)).then(content => {
return { created: false, extensionsFileResource, content: content.value.toString() };
}, err => {
return this.textFileService.write(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
return { created: true, extensionsFileResource, content: ExtensionsConfigurationInitialContent };
@@ -236,7 +236,7 @@ class Extension implements IExtension {
}
if (this.local && this.local.readmeUrl) {
return this.fileService.resolveContent(this.local.readmeUrl, { encoding: 'utf8' }).then(content => content.value);
return this.fileService.readFile(this.local.readmeUrl).then(content => content.value.toString());
}
if (this.type === ExtensionType.System) {
@@ -277,7 +277,7 @@ ${this.description}
return Promise.reject(new Error('not available'));
}
return this.fileService.resolveContent(changelogUrl, { encoding: 'utf8' }).then(content => content.value);
return this.fileService.readFile(changelogUrl).then(content => content.value.toString());
}
get dependencies(): string[] {
@@ -12,9 +12,9 @@ import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { URI } from 'vs/base/common/uri';
import { BINARY_FILE_EDITOR_ID } from 'vs/workbench/contrib/files/common/files';
import { IFileService } from 'vs/platform/files/common/files';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
/**
* An implementation of editor for binary files like images.
@@ -26,10 +26,10 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IFileService fileService: IFileService,
@IWindowsService private readonly windowsService: IWindowsService,
@IEditorService private readonly editorService: IEditorService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@ITextFileService textFileService: ITextFileService
) {
super(
BinaryFileEditor.ID,
@@ -39,7 +39,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
},
telemetryService,
themeService,
fileService,
textFileService,
storageService
);
}
@@ -198,7 +198,7 @@ export class SnippetFile {
load(): Promise<this> {
if (!this._loadPromise) {
this._loadPromise = Promise.resolve(this._fileService.resolveContent(this.location, { encoding: 'utf8' })).then(content => {
this._loadPromise = Promise.resolve(this._fileService.readFile(this.location)).then(content => {
const data = <JsonSerializedSnippets>jsonParse(content.value.toString());
if (typeof data === 'object') {
forEach(data, entry => {
@@ -20,6 +20,7 @@ import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspa
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { joinPath } from 'vs/base/common/resources';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/;
const SshUrlMatcher = /^([^@:]+@)?([^:]+):(.+)$/;
@@ -193,14 +194,14 @@ export function getHashedRemotesFromConfig(text: string, stripEndingDotGit: bool
});
}
export function getHashedRemotesFromUri(workspaceUri: URI, fileService: IFileService, stripEndingDotGit: boolean = false): Promise<string[]> {
export function getHashedRemotesFromUri(workspaceUri: URI, fileService: IFileService, textFileService: ITextFileService, stripEndingDotGit: boolean = false): Promise<string[]> {
const path = workspaceUri.path;
const uri = workspaceUri.with({ path: `${path !== '/' ? path : ''}/.git/config` });
return fileService.exists(uri).then(exists => {
if (!exists) {
return [];
}
return fileService.resolveContent(uri, { acceptTextOnly: true }).then(
return textFileService.read(uri, { acceptTextOnly: true }).then(
content => getHashedRemotesFromConfig(content.value, stripEndingDotGit),
err => [] // ignore missing or binary file
);
@@ -221,7 +222,8 @@ export class WorkspaceStats implements IWorkbenchContribution {
@IWindowService private readonly windowService: IWindowService,
@INotificationService private readonly notificationService: INotificationService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IStorageService private readonly storageService: IStorageService
@IStorageService private readonly storageService: IStorageService,
@ITextFileService private readonly textFileService: ITextFileService
) {
this.report();
}
@@ -434,7 +436,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
tags['workspace.android.cpp'] = true;
}
function getFilePromises(filename: string, fileService: IFileService, contentHandler: (content: IContent) => void): Promise<void>[] {
function getFilePromises(filename: string, fileService: IFileService, textFileService: ITextFileService, contentHandler: (content: IContent) => void): Promise<void>[] {
return !nameSet.has(filename) ? [] : (folders as URI[]).map(workspaceUri => {
const uri = workspaceUri.with({ path: `${workspaceUri.path !== '/' ? workspaceUri.path : ''}/${filename}` });
return fileService.exists(uri).then(exists => {
@@ -442,7 +444,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
return undefined;
}
return fileService.resolveContent(uri, { acceptTextOnly: true }).then(contentHandler);
return textFileService.read(uri, { acceptTextOnly: true }).then(contentHandler);
}, err => {
// Ignore missing file
});
@@ -468,7 +470,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
}
}
const requirementsTxtPromises = getFilePromises('requirements.txt', this.fileService, content => {
const requirementsTxtPromises = getFilePromises('requirements.txt', this.fileService, this.textFileService, content => {
const dependencies: string[] = content.value.split(/\r\n|\r|\n/);
for (let dependency of dependencies) {
// Dependencies in requirements.txt can have 3 formats: `foo==3.1, foo>=3.1, foo`
@@ -479,7 +481,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
}
});
const pipfilePromises = getFilePromises('pipfile', this.fileService, content => {
const pipfilePromises = getFilePromises('pipfile', this.fileService, this.textFileService, content => {
let dependencies: string[] = content.value.split(/\r\n|\r|\n/);
// We're only interested in the '[packages]' section of the Pipfile
@@ -499,7 +501,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
});
const packageJsonPromises = getFilePromises('package.json', this.fileService, content => {
const packageJsonPromises = getFilePromises('package.json', this.fileService, this.textFileService, content => {
try {
const packageJsonContents = JSON.parse(content.value);
if (packageJsonContents['dependencies']) {
@@ -624,7 +626,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
if (!exists) {
return [];
}
return this.fileService.resolveContent(uri, { acceptTextOnly: true }).then(
return this.textFileService.read(uri, { acceptTextOnly: true }).then(
content => getDomainsOfRemotes(content.value, SecondLevelDomainWhitelist),
err => [] // ignore missing or binary file
);
@@ -644,7 +646,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
private reportRemotes(workspaceUris: URI[]): void {
Promise.all<string[]>(workspaceUris.map(workspaceUri => {
return getHashedRemotesFromUri(workspaceUri, this.fileService, true);
return getHashedRemotesFromUri(workspaceUri, this.fileService, this.textFileService, true);
})).then(hashedRemotes => {
/* __GDPR__
"workspace.hashedRemotes" : {
@@ -693,7 +695,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
if (!exists) {
return false;
}
return this.fileService.resolveContent(uri, { acceptTextOnly: true }).then(
return this.textFileService.read(uri, { acceptTextOnly: true }).then(
content => !!content.value.match(/azure/i),
err => false
);
@@ -234,8 +234,8 @@ CommandsRegistry.registerCommand('_workbench.captureSyntaxTokens', function (acc
let fileName = basename(resource);
let snapper = accessor.get(IInstantiationService).createInstance(Snapper);
return fileService.resolveContent(resource).then(content => {
return snapper.captureSyntaxTokens(fileName, content.value);
return fileService.readFile(resource).then(content => {
return snapper.captureSyntaxTokens(fileName, content.value.toString());
});
};
@@ -16,7 +16,7 @@ import * as modes from 'vs/editor/common/modes';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IFileService } from 'vs/platform/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
@@ -118,7 +118,7 @@ class WebviewProtocolProvider extends Disposable {
private readonly _extensionLocation: URI | undefined,
private readonly _getLocalResourceRoots: () => ReadonlyArray<URI>,
private readonly _environmentService: IEnvironmentService,
private readonly _fileService: IFileService,
private readonly _textFileService: ITextFileService,
) {
super();
@@ -137,11 +137,11 @@ class WebviewProtocolProvider extends Disposable {
const appRootUri = URI.file(this._environmentService.appRoot);
registerFileProtocol(contents, WebviewProtocol.CoreResource, this._fileService, undefined, () => [
registerFileProtocol(contents, WebviewProtocol.CoreResource, this._textFileService, undefined, () => [
appRootUri
]);
registerFileProtocol(contents, WebviewProtocol.VsCodeResource, this._fileService, this._extensionLocation, () =>
registerFileProtocol(contents, WebviewProtocol.VsCodeResource, this._textFileService, this._extensionLocation, () =>
this._getLocalResourceRoots()
);
}
@@ -374,7 +374,7 @@ export class WebviewElement extends Disposable implements Webview {
@IInstantiationService instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService,
@IEnvironmentService environmentService: IEnvironmentService,
@IFileService fileService: IFileService,
@ITextFileService textFileService: ITextFileService,
@ITunnelService tunnelService: ITunnelService,
@ITelemetryService telemetryService: ITelemetryService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@@ -412,7 +412,7 @@ export class WebviewElement extends Disposable implements Webview {
this._options.extension ? this._options.extension.location : undefined,
() => (this._contentOptions.localResourceRoots || []),
environmentService,
fileService));
textFileService));
this._register(new WebviewPortMappingProvider(
session,
@@ -6,16 +6,16 @@ import { getMediaMime, MIME_UNKNOWN } from 'vs/base/common/mime';
import { extname, sep } from 'vs/base/common/path';
import { startsWith } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
export const enum WebviewProtocol {
CoreResource = 'vscode-core-resource',
VsCodeResource = 'vscode-resource',
}
function resolveContent(fileService: IFileService, resource: URI, mime: string, callback: any): void {
fileService.resolveContent(resource, { encoding: 'binary' }).then(contents => {
function resolveContent(textFileService: ITextFileService, resource: URI, mime: string, callback: any): void {
textFileService.read(resource, { encoding: 'binary' }).then(contents => {
callback({
data: Buffer.from(contents.value, contents.encoding),
mimeType: mime
@@ -29,7 +29,7 @@ function resolveContent(fileService: IFileService, resource: URI, mime: string,
export function registerFileProtocol(
contents: Electron.WebContents,
protocol: WebviewProtocol,
fileService: IFileService,
textFileService: ITextFileService,
extensionLocation: URI | undefined,
getRoots: () => ReadonlyArray<URI>
) {
@@ -44,7 +44,7 @@ export function registerFileProtocol(
requestResourcePath: requestUri.path
})
});
resolveContent(fileService, redirectedUri, getMimeType(requestUri), callback);
resolveContent(textFileService, redirectedUri, getMimeType(requestUri), callback);
return;
}
@@ -52,7 +52,7 @@ export function registerFileProtocol(
const normalizedPath = URI.file(requestPath);
for (const root of getRoots()) {
if (startsWith(normalizedPath.fsPath, root.fsPath + sep)) {
resolveContent(fileService, normalizedPath, getMimeType(normalizedPath), callback);
resolveContent(textFileService, normalizedPath, getMimeType(normalizedPath), callback);
return;
}
}
@@ -133,7 +133,7 @@ export class UserConfiguration extends Disposable {
async reload(): Promise<ConfigurationModel> {
try {
const content = await this.configurationFileService.resolveContent(this.configurationResource);
const content = await this.configurationFileService.readFile(this.configurationResource);
this.parser.parseContent(content);
return this.parser.configurationModel;
} catch (e) {
@@ -379,7 +379,7 @@ class FileServiceBasedWorkspaceConfiguration extends Disposable implements IWork
}
let contents = '';
try {
contents = await this.configurationFileService.resolveContent(this._workspaceIdentifier.configPath);
contents = await this.configurationFileService.readFile(this._workspaceIdentifier.configPath);
} catch (error) {
const exists = await this.configurationFileService.exists(this._workspaceIdentifier.configPath);
if (exists) {
@@ -547,7 +547,7 @@ class FileServiceBasedFolderConfiguration extends Disposable implements IFolderC
async loadConfiguration(): Promise<ConfigurationModel> {
const configurationContents = await Promise.all(this.configurationResources.map(async resource => {
try {
return await this.configurationFileService.resolveContent(resource);
return await this.configurationFileService.readFile(resource);
} catch (error) {
const exists = await this.configurationFileService.exists(resource);
if (exists) {
@@ -49,7 +49,7 @@ export interface IConfigurationFileService {
whenProviderRegistered(scheme: string): Promise<void>;
watch(resource: URI): IDisposable;
exists(resource: URI): Promise<boolean>;
resolveContent(resource: URI): Promise<string>;
readFile(resource: URI): Promise<string>;
}
export class ConfigurationFileService implements IConfigurationFileService {
@@ -82,8 +82,8 @@ export class ConfigurationFileService implements IConfigurationFileService {
return this.fileService.exists(resource);
}
resolveContent(resource: URI): Promise<string> {
return this.fileService.resolveContent(resource, { encoding: 'utf8' }).then(content => content.value);
readFile(resource: URI): Promise<string> {
return this.fileService.readFile(resource).then(content => content.value.toString());
}
}
@@ -51,9 +51,9 @@ export class ConfigurationFileService extends Disposable implements IConfigurati
return this._fileServiceBasedConfigurationFileService ? this._fileServiceBasedConfigurationFileService.exists(resource) : pfs.exists(resource.fsPath);
}
async resolveContent(resource: URI): Promise<string> {
async readFile(resource: URI): Promise<string> {
if (this._fileServiceBasedConfigurationFileService) {
return this._fileServiceBasedConfigurationFileService.resolveContent(resource);
return this._fileServiceBasedConfigurationFileService.readFile(resource);
} else {
const contents = await pfs.readFile(resource.fsPath);
return contents.toString();
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Disposable, IDisposable, toDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { IFileService, IResolveFileOptions, FileChangesEvent, FileOperationEvent, IFileSystemProviderRegistrationEvent, IFileSystemProvider, IFileStat, IResolveFileResult, IReadTextFileOptions, IContent, ICreateFileOptions, IFileSystemProviderActivationEvent, FileOperationError, FileOperationResult, FileOperation, FileSystemProviderCapabilities, FileType, toFileSystemProviderErrorCode, FileSystemProviderErrorCode, IStat, IFileStatWithMetadata, IResolveMetadataFileOptions, etag, hasReadWriteCapability, hasFileFolderCopyCapability, hasOpenReadWriteCloseCapability, toFileOperationResult, IFileSystemProviderWithOpenReadWriteCloseCapability, IFileSystemProviderWithFileReadWriteCapability, IResolveFileResultWithMetadata, IWatchOptions, ILegacyFileService, IWriteFileOptions, IReadFileOptions, IFileStreamContent, IFileContent } from 'vs/platform/files/common/files';
import { IFileService, IResolveFileOptions, FileChangesEvent, FileOperationEvent, IFileSystemProviderRegistrationEvent, IFileSystemProvider, IFileStat, IResolveFileResult, ICreateFileOptions, IFileSystemProviderActivationEvent, FileOperationError, FileOperationResult, FileOperation, FileSystemProviderCapabilities, FileType, toFileSystemProviderErrorCode, FileSystemProviderErrorCode, IStat, IFileStatWithMetadata, IResolveMetadataFileOptions, etag, hasReadWriteCapability, hasFileFolderCopyCapability, hasOpenReadWriteCloseCapability, toFileOperationResult, IFileSystemProviderWithOpenReadWriteCloseCapability, IFileSystemProviderWithFileReadWriteCapability, IResolveFileResultWithMetadata, IWatchOptions, ILegacyFileService, IWriteFileOptions, IReadFileOptions, IFileStreamContent, IFileContent } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
@@ -528,10 +528,6 @@ export class FileService2 extends Disposable implements IFileService {
return stat;
}
resolveContent(resource: URI, options?: IReadTextFileOptions): Promise<IContent> {
return this.joinOnLegacy.then(legacy => legacy.resolveContent(resource, options));
}
//#endregion
//#region Move/Copy/Delete/Create Folder
@@ -210,11 +210,11 @@ class FileOutputChannelModel extends AbstractFileOutputChannelModel implements I
}
loadModel(): Promise<ITextModel> {
this.loadModelPromise = this.fileService.resolveContent(this.file, { position: this.startOffset, encoding: 'utf8' })
this.loadModelPromise = this.fileService.readFile(this.file, { position: this.startOffset })
.then(content => {
this.endOffset = this.startOffset + this.getByteLength(content.value);
this.endOffset = this.startOffset + content.value.byteLength;
this.etag = content.etag;
return this.createModel(content.value);
return this.createModel(content.value.toString());
});
return this.loadModelPromise;
}
@@ -233,12 +233,12 @@ class FileOutputChannelModel extends AbstractFileOutputChannelModel implements I
protected updateModel(): void {
if (this.model) {
this.fileService.resolveContent(this.file, { position: this.endOffset, encoding: 'utf8' })
this.fileService.readFile(this.file, { position: this.endOffset })
.then(content => {
this.etag = content.etag;
if (content.value) {
this.endOffset = this.endOffset + this.getByteLength(content.value);
this.appendToModel(content.value);
this.endOffset = this.endOffset + content.value.byteLength;
this.appendToModel(content.value.toString());
}
this.updateInProgress = false;
}, () => this.updateInProgress = false);
@@ -117,8 +117,8 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
}
private loadFile(): Promise<string> {
return this.fileService.resolveContent(this.file, { position: this.startOffset, encoding: 'utf8' })
.then(content => this.appendedMessage ? content.value + this.appendedMessage : content.value);
return this.fileService.readFile(this.file, { position: this.startOffset })
.then(content => this.appendedMessage ? content.value + this.appendedMessage : content.value.toString());
}
protected updateModel(): void {
@@ -21,7 +21,7 @@ import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ILabelService } from 'vs/platform/label/common/label';
@@ -59,7 +59,6 @@ export class PreferencesService extends Disposable implements IPreferencesServic
constructor(
@IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IFileService private readonly fileService: IFileService,
@ITextFileService private readonly textFileService: ITextFileService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@INotificationService private readonly notificationService: INotificationService,
@@ -546,7 +545,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return Promise.resolve(undefined);
}
return this.fileService.resolveContent(workspaceConfig)
return this.textFileService.read(workspaceConfig)
.then(content => {
if (Object.keys(parse(content.value)).indexOf('settings') === -1) {
return this.jsonEditingService.write(resource, { key: 'settings', value: {} }, true).then(undefined, () => { });
@@ -558,7 +557,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
}
private createIfNotExists(resource: URI, contents: string): Promise<any> {
return this.fileService.resolveContent(resource, { acceptTextOnly: true }).then(undefined, error => {
return this.textFileService.read(resource, { acceptTextOnly: true }).then(undefined, error => {
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
return this.textFileService.write(resource, contents).then(undefined, error => {
return Promise.reject(new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", this.labelService.getUriLabel(resource, { relative: true }), error)));
@@ -248,8 +248,8 @@ export class TextMateService extends Disposable implements ITextMateService {
return null;
}
try {
const content = await this._fileService.resolveContent(location, { encoding: 'utf8' });
return parseRawGrammar(content.value, location.path);
const content = await this._fileService.readFile(location);
return parseRawGrammar(content.value.toString(), location.path);
} catch (e) {
this._logService.error(`Unable to load and parse grammar for scope ${scopeName} from ${location}`, e);
return null;
@@ -297,7 +297,7 @@ function toCSSSelector(extensionId: string, path: string) {
function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRules: ITokenColorizationRule[], resultColors: IColorMap): Promise<any> {
if (resources.extname(themeLocation) === '.json') {
return fileService.resolveContent(themeLocation, { encoding: 'utf8' }).then(content => {
return fileService.readFile(themeLocation).then(content => {
let errors: Json.ParseError[] = [];
let contentValue = Json.parse(content.value.toString(), errors);
if (errors.length > 0) {
@@ -345,7 +345,7 @@ function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRu
}
function _loadSyntaxTokens(fileService: IFileService, themeLocation: URI, resultRules: ITokenColorizationRule[], resultColors: IColorMap): Promise<any> {
return fileService.resolveContent(themeLocation, { encoding: 'utf8' }).then(content => {
return fileService.readFile(themeLocation).then(content => {
try {
let contentValue = parsePList(content.value.toString());
let settings: ITokenColorizationRule[] = contentValue.settings;
@@ -185,7 +185,7 @@ interface IconThemeDocument extends IconsAssociation {
}
function _loadIconThemeDocument(fileService: IFileService, location: URI): Promise<IconThemeDocument> {
return fileService.resolveContent(location, { encoding: 'utf8' }).then((content) => {
return fileService.readFile(location).then((content) => {
let errors: Json.ParseError[] = [];
let contentValue = Json.parse(content.value.toString(), errors);
if (errors.length > 0 || !contentValue) {
@@ -298,8 +298,8 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
}
// Read the contents of the workspace file, update it to new location and save it.
const raw = await this.fileService.resolveContent(configPathURI);
const newRawWorkspaceContents = rewriteWorkspaceFileForNewLocation(raw.value, configPathURI, targetConfigPathURI);
const raw = await this.fileService.readFile(configPathURI);
const newRawWorkspaceContents = rewriteWorkspaceFileForNewLocation(raw.value.toString(), configPathURI, targetConfigPathURI);
await this.textFileService.create(targetConfigPathURI, newRawWorkspaceContents, { overwrite: true });
}
@@ -37,7 +37,7 @@ import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/p
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, MenuBarVisibility, IURIToOpen, IOpenSettings, IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
@@ -243,15 +243,15 @@ export class TestTextFileService extends BrowserTextFileService {
return Promise.reject(error);
}
return this.fileService.resolveContent(resource, options).then((content): ITextFileStreamContent => {
return this.fileService.readFileStream(resource, options).then(async (content): Promise<ITextFileStreamContent> => {
return {
resource: content.resource,
name: content.name,
mtime: content.mtime,
etag: content.etag,
encoding: content.encoding,
value: createTextBufferFactory(content.value),
size: content.value.length
encoding: 'utf8',
value: await createTextBufferFactoryFromStream(content.value),
size: 10
};
});
}