Skip to content

Commit 121bd31

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Fix AI Assistance not finding automatic filesystems
It also refactors the filesystem type to be enums and automated filesystems to have a flag on them. Fixed: 399333674 Change-Id: Ide6c6ce966177590be5cca1a1637c04b983c6d13 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6305500 Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 06b47b5 commit 121bd31

File tree

13 files changed

+66
-35
lines changed

13 files changed

+66
-35
lines changed

front_end/core/host/InspectorFrontendHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class InspectorFrontendHostStub implements InspectorFrontendHostAPI {
294294
fileSystemName: 'sandboxedRequestedFileSystem',
295295
fileSystemPath: OVERRIDES_FILE_SYSTEM_PATH,
296296
rootURL: 'filesystem:devtools://devtools/isolated/',
297-
type: 'overrides',
297+
type: 'overrides' as const,
298298
};
299299
this.events.dispatchEventToListeners(Events.FileSystemAdded, {fileSystem});
300300
};

front_end/core/host/InspectorFrontendHostAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export interface EyeDropperPickedColorEvent {
8282
}
8383

8484
export interface DevToolsFileSystem {
85-
type: string;
85+
type: ''|'automatic'|'snippets'|'overrides';
8686
fileSystemName: string;
8787
rootURL: string;
8888
fileSystemPath: Platform.DevToolsPath.RawPathString;

front_end/models/breakpoints/BreakpointManager.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ describeWithMockConnection('BreakpointManager', () => {
883883

884884
async function testBreakpointMovedOnInstrumentationBreak(
885885
fileSystemPath: Platform.DevToolsPath.UrlString, fileSystemFileUrl: Platform.DevToolsPath.UrlString,
886-
content: string, type?: string) {
886+
content: string, type?: Persistence.PlatformFileSystem.PlatformFileSystemType) {
887887
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
888888
assert.exists(debuggerModel);
889889

@@ -1480,10 +1480,10 @@ describeWithMockConnection('BreakpointManager', () => {
14801480

14811481
const fileSystemPath = urlString`file://path/to/overrides`;
14821482
const fielSystemFileUrl = urlString`${fileSystemPath + '/site/script.js'}`;
1483-
const type = 'overrides';
14841483
const content = '';
14851484

1486-
await testBreakpointMovedOnInstrumentationBreak(fileSystemPath, fielSystemFileUrl, content, type);
1485+
await testBreakpointMovedOnInstrumentationBreak(
1486+
fileSystemPath, fielSystemFileUrl, content, Persistence.PlatformFileSystem.PlatformFileSystemType.OVERRIDES);
14871487
});
14881488
});
14891489

front_end/models/persistence/IsolatedFileSystem.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import * as Platform from '../../core/platform/platform.js';
3535
import * as TextUtils from '../text_utils/text_utils.js';
3636

3737
import {Events, type IsolatedFileSystemManager} from './IsolatedFileSystemManager.js';
38-
import {PlatformFileSystem} from './PlatformFileSystem.js';
38+
import {PlatformFileSystem, type PlatformFileSystemType} from './PlatformFileSystem.js';
3939

4040
const UIStrings = {
4141
/**
@@ -75,8 +75,9 @@ export class IsolatedFileSystem extends PlatformFileSystem {
7575

7676
constructor(
7777
manager: IsolatedFileSystemManager, path: Platform.DevToolsPath.UrlString,
78-
embedderPath: Platform.DevToolsPath.RawPathString, domFileSystem: FileSystem, type: string) {
79-
super(path, type);
78+
embedderPath: Platform.DevToolsPath.RawPathString, domFileSystem: FileSystem, type: PlatformFileSystemType,
79+
automatic: boolean) {
80+
super(path, type, automatic);
8081
this.manager = manager;
8182
this.embedderPathInternal = embedderPath;
8283
this.domFileSystem = domFileSystem;
@@ -87,14 +88,14 @@ export class IsolatedFileSystem extends PlatformFileSystem {
8788

8889
static async create(
8990
manager: IsolatedFileSystemManager, path: Platform.DevToolsPath.UrlString,
90-
embedderPath: Platform.DevToolsPath.RawPathString, type: string, name: string,
91-
rootURL: string): Promise<IsolatedFileSystem|null> {
91+
embedderPath: Platform.DevToolsPath.RawPathString, type: PlatformFileSystemType, name: string, rootURL: string,
92+
automatic: boolean): Promise<IsolatedFileSystem|null> {
9293
const domFileSystem = Host.InspectorFrontendHost.InspectorFrontendHostInstance.isolatedFileSystem(name, rootURL);
9394
if (!domFileSystem) {
9495
return null;
9596
}
9697

97-
const fileSystem = new IsolatedFileSystem(manager, path, embedderPath, domFileSystem, type);
98+
const fileSystem = new IsolatedFileSystem(manager, path, embedderPath, domFileSystem, type, automatic);
9899
return await fileSystem.initializeFilePaths().then(() => fileSystem).catch(error => {
99100
console.error(error);
100101
return null;

front_end/models/persistence/IsolatedFileSystemManager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import * as Platform from '../../core/platform/platform.js';
3535

3636
import type {FilesChangedData} from './FileSystemWorkspaceBinding.js';
3737
import {IsolatedFileSystem} from './IsolatedFileSystem.js';
38-
import type {PlatformFileSystem} from './PlatformFileSystem.js';
38+
import {type PlatformFileSystem, PlatformFileSystemType} from './PlatformFileSystem.js';
3939

4040
const UIStrings = {
4141
/**
@@ -180,7 +180,8 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
180180
const embedderPath = fileSystem.fileSystemPath;
181181
const fileSystemURL = Common.ParsedURL.ParsedURL.rawPathToUrlString(fileSystem.fileSystemPath);
182182
const promise = IsolatedFileSystem.create(
183-
this, fileSystemURL, embedderPath, fileSystem.type, fileSystem.fileSystemName, fileSystem.rootURL);
183+
this, fileSystemURL, embedderPath, hostFileSystemTypeToPlatformFileSystemType(fileSystem.type),
184+
fileSystem.fileSystemName, fileSystem.rootURL, fileSystem.type === 'automatic');
184185
return promise.then(storeFileSystem.bind(this));
185186

186187
function storeFileSystem(this: IsolatedFileSystemManager, fileSystem: IsolatedFileSystem|null): IsolatedFileSystem|
@@ -359,3 +360,14 @@ export interface EventTypes {
359360
}
360361

361362
let lastRequestId = 0;
363+
364+
function hostFileSystemTypeToPlatformFileSystemType(type: string): PlatformFileSystemType {
365+
switch (type) {
366+
case 'snippets':
367+
return PlatformFileSystemType.SNIPPETS;
368+
case 'overrides':
369+
return PlatformFileSystemType.OVERRIDES;
370+
default:
371+
return PlatformFileSystemType.DISK;
372+
}
373+
}

front_end/models/persistence/PersistenceImpl.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ describeWithMockConnection('PersistenceImpl', () => {
115115
const fileSystemPath = urlString`file://path/to/filesystem`;
116116
const fileSystemFileUrl = urlString`${fileSystemPath + '/script.js'}`;
117117
const {uiSourceCode: fileSystemUiSourceCode, project} = createFileSystemFileForPersistenceTests(
118-
{fileSystemPath, fileSystemFileUrl, type: ''}, SCRIPT_DESCRIPTION.url, SCRIPT_DESCRIPTION.content, target);
118+
{fileSystemPath, fileSystemFileUrl, type: Persistence.PlatformFileSystem.PlatformFileSystemType.DISK},
119+
SCRIPT_DESCRIPTION.url, SCRIPT_DESCRIPTION.content, target);
119120
const breakpointLine = 0;
120121

121122
// Set the breakpoint response for our upcoming request.
@@ -140,7 +141,8 @@ describeWithMockConnection('PersistenceImpl', () => {
140141
const fileSystemPath = urlString`file://path/to/filesystem`;
141142
const fileSystemFileUrl = urlString`${fileSystemPath + '/script.js'}`;
142143
const {uiSourceCode: fileSystemUiSourceCode, project} = createFileSystemFileForPersistenceTests(
143-
{fileSystemPath, fileSystemFileUrl, type: ''}, SCRIPT_DESCRIPTION.url, SCRIPT_DESCRIPTION.content, target);
144+
{fileSystemPath, fileSystemFileUrl, type: Persistence.PlatformFileSystem.PlatformFileSystemType.DISK},
145+
SCRIPT_DESCRIPTION.url, SCRIPT_DESCRIPTION.content, target);
144146
const breakpointLine = 0;
145147

146148
// Set the breakpoint response for our upcoming request.

front_end/models/persistence/PlatformFileSystem.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const {urlString} = Platform.DevToolsPath;
99

1010
describe('PlatformFileSystem', () => {
1111
it('can be instantiated successfully', () => {
12-
const platformFileSystem = new Persistence.PlatformFileSystem.PlatformFileSystem(urlString`Test Path`, 'Test Type');
12+
const platformFileSystem = new Persistence.PlatformFileSystem.PlatformFileSystem(
13+
urlString`Test Path`, Persistence.PlatformFileSystem.PlatformFileSystemType.DISK, false);
1314
assert.strictEqual(platformFileSystem.path(), 'Test Path', 'path was not set or retrieved correctly');
14-
assert.strictEqual(platformFileSystem.type(), 'Test Type', 'Type was not set or retrieved correctly');
15+
assert.strictEqual(
16+
platformFileSystem.type(), Persistence.PlatformFileSystem.PlatformFileSystemType.DISK,
17+
'Type was not set or retrieved correctly');
1518
});
16-
17-
// TODO continue writing tests here or use another describe block
1819
});

front_end/models/persistence/PlatformFileSystem.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ const UIStrings = {
1515
} as const;
1616
const str_ = i18n.i18n.registerUIStrings('models/persistence/PlatformFileSystem.ts', UIStrings);
1717
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
18+
19+
export enum PlatformFileSystemType {
20+
SNIPPETS = 'snippets',
21+
OVERRIDES = 'overrides',
22+
DISK = 'disk',
23+
}
24+
1825
export class PlatformFileSystem {
1926
private readonly pathInternal: Platform.DevToolsPath.UrlString;
20-
private readonly typeInternal: string;
21-
constructor(path: Platform.DevToolsPath.UrlString, type: string) {
27+
#type: PlatformFileSystemType;
28+
#automatic: boolean;
29+
constructor(path: Platform.DevToolsPath.UrlString, type: PlatformFileSystemType, automatic: boolean) {
2230
this.pathInternal = path;
23-
this.typeInternal = type;
31+
this.#type = type;
32+
this.#automatic = automatic;
2433
}
2534

2635
getMetadata(_path: Platform.DevToolsPath.EncodedPathString): Promise<{modificationTime: Date, size: number}|null> {
@@ -44,8 +53,11 @@ export class PlatformFileSystem {
4453
}
4554

4655
type(): string {
47-
// TODO(kozyatinskiy): remove type, overrides should implement this interface.
48-
return this.typeInternal;
56+
return this.#type;
57+
}
58+
59+
automatic(): boolean {
60+
return this.#automatic;
4961
}
5062

5163
async createFile(_path: Platform.DevToolsPath.EncodedPathString, _name: Platform.DevToolsPath.RawPathString|null):

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
487487
if (!(project instanceof Persistence.FileSystemWorkspaceBinding.FileSystem)) {
488488
continue;
489489
}
490-
// Workspace projects do not have a type. Only snippets and
491-
// overrides do.
492-
if (project.fileSystem().type()) {
490+
if (project.fileSystem().type() !== Persistence.PlatformFileSystem.PlatformFileSystemType.DISK) {
493491
continue;
494492
}
495493
this.#project = project;

front_end/panels/snippets/ScriptSnippetFileSystem.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
3939
private readonly lastSnippetIdentifierSetting: Common.Settings.Setting<number>;
4040
private readonly snippetsSetting: Common.Settings.Setting<Snippet[]>;
4141
constructor() {
42-
super('snippet://' as Platform.DevToolsPath.UrlString, 'snippets');
42+
super(
43+
'snippet://' as Platform.DevToolsPath.UrlString, Persistence.PlatformFileSystem.PlatformFileSystemType.SNIPPETS,
44+
false);
4345
this.lastSnippetIdentifierSetting =
4446
Common.Settings.Settings.instance().createSetting('script-snippets-last-identifier', 0);
4547
this.snippetsSetting = Common.Settings.Settings.instance().createSetting('script-snippets', []);

0 commit comments

Comments
 (0)