mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 20:39:31 +08:00
The source editor, when it cannot load a particular file, will simply display a blank file instead. At the bottom, this is because the APIs used to load the files do not have a way to propagate an error up to the call site. Rather, the callback either is never called, or is called with just an empty string. This refactor changes the way the project system loads file contents by replacing the callback model with a Promise-based model. However, in this version, rather than propagating an error (handled via catch), the error is exposed as a property on the object passed via the the load functions. Although it might be preferable to use async throw/catch, because there are ~4-5 layers of redirection through the project system, the added complexity seems to not really justify that work. I'm open to reconsidering this design, though. Attempting to load a file via file:// which does not exist previously produced no error because the DevToolsUIBindings handler would just always resolve with no content and HTTP status 200. I had previously addressed that bug in this changeset, but I've split it out to https://chromium-review.googlesource.com/c/chromium/src/+/1847833 . Sample "after" screenshot: https://imgur.com/a/tlm90sg Bug: 961940 Bug: 941035 Change-Id: If121611090e9c35eeb1de162b59f8a9f72f696d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817677 Reviewed-by: Lorne Mitchell <lomitch@microsoft.com> Reviewed-by: Jeff Fisher <jeffish@microsoft.com> Commit-Queue: Lorne Mitchell <lomitch@microsoft.com> Cr-Original-Commit-Position: refs/heads/master@{#705438} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 61ec2a233d9a7bf4bb4b3e610de6fc233ae0d46e
204 lines
3.6 KiB
JavaScript
204 lines
3.6 KiB
JavaScript
// Copyright 2018 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
export default class PlatformFileSystem {
|
|
/**
|
|
* @param {string} path
|
|
* @param {string} type
|
|
*/
|
|
constructor(path, type) {
|
|
this._path = path;
|
|
this._type = type;
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {!Promise<?{modificationTime: !Date, size: number}>}
|
|
*/
|
|
getMetadata(path) {
|
|
return Promise.resolve(/** @type ?{modificationTime: !Date, size: number} */ (null));
|
|
}
|
|
|
|
/**
|
|
* @return {!Array<string>}
|
|
*/
|
|
initialFilePaths() {
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @return {!Array<string>}
|
|
*/
|
|
initialGitFolders() {
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
path() {
|
|
return this._path;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
embedderPath() {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
type() {
|
|
// TODO(kozyatinskiy): remove type, overrides should implement this interface.
|
|
return this._type;
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @param {?string} name
|
|
* @return {!Promise<?string>}
|
|
*/
|
|
async createFile(path, name) {
|
|
return Promise.resolve(null);
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {!Promise<boolean>}
|
|
*/
|
|
deleteFile(path) {
|
|
return Promise.resolve(false);
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {!Promise<?Blob>}
|
|
*/
|
|
requestFileBlob(path) {
|
|
return Promise.resolve(/** @type {?Blob} */ (null));
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @returns {!Promise<!Common.DeferredContent>}
|
|
*/
|
|
async requestFileContent(path) {
|
|
return {error: ls`Unable to read files with this implementation.`, isEncoded: false};
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @param {string} content
|
|
* @param {boolean} isBase64
|
|
*/
|
|
setFileContent(path, content, isBase64) {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @param {string} newName
|
|
* @param {function(boolean, string=)} callback
|
|
*/
|
|
renameFile(path, newName, callback) {
|
|
callback(false);
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
*/
|
|
addExcludedFolder(path) {
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
*/
|
|
removeExcludedFolder(path) {
|
|
}
|
|
|
|
fileSystemRemoved() {
|
|
}
|
|
|
|
/**
|
|
* @param {string} folderPath
|
|
* @return {boolean}
|
|
*/
|
|
isFileExcluded(folderPath) {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return {!Set<string>}
|
|
*/
|
|
excludedFolders() {
|
|
return new Set();
|
|
}
|
|
|
|
/**
|
|
* @param {string} query
|
|
* @param {!Common.Progress} progress
|
|
* @return {!Promise<!Array<string>>}
|
|
*/
|
|
searchInPath(query, progress) {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.Progress} progress
|
|
*/
|
|
indexContent(progress) {
|
|
setImmediate(() => progress.done());
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {string}
|
|
*/
|
|
mimeFromPath(path) {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {boolean}
|
|
*/
|
|
canExcludeFolder(path) {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @param {string} path
|
|
* @return {!Common.ResourceType}
|
|
*/
|
|
contentType(path) {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
/**
|
|
* @param {string} url
|
|
* @return {string}
|
|
*/
|
|
tooltipForURL(url) {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
/**
|
|
* @return {boolean}
|
|
*/
|
|
supportsAutomapping() {
|
|
throw new Error('Not implemented');
|
|
}
|
|
}
|
|
|
|
/* Legacy exported object */
|
|
self.Persistence = self.Persistence || {};
|
|
|
|
/* Legacy exported object */
|
|
Persistence = Persistence || {};
|
|
|
|
/** @constructor */
|
|
Persistence.PlatformFileSystem = PlatformFileSystem;
|