-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use createFileSystemWatcher to more reliably watch for file system changes #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
752b0cf
Use createFileSystemWatcher to more reliably watch for file system ch…
mrubens b3e2e61
Add changeset
mrubens 51b9418
Tests
mrubens c50cfad
Merge remote-tracking branch 'origin/main' into file_system_watcher
mrubens b4c7a2a
Merge remote-tracking branch 'origin/main' into file_system_watcher
mrubens 5d3c465
Update README
mrubens 947adc4
Merge remote-tracking branch 'origin/main' into file_system_watcher
mrubens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "roo-cline": patch | ||
| --- | ||
|
|
||
| Use createFileSystemWatcher to more reliably update list of files to @-mention |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/integrations/workspace/__tests__/WorkspaceTracker.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import * as vscode from "vscode" | ||
| import WorkspaceTracker from "../WorkspaceTracker" | ||
| import { ClineProvider } from "../../../core/webview/ClineProvider" | ||
| import { listFiles } from "../../../services/glob/list-files" | ||
|
|
||
| // Mock modules | ||
| const mockOnDidCreate = jest.fn() | ||
| const mockOnDidDelete = jest.fn() | ||
| const mockOnDidChange = jest.fn() | ||
| const mockDispose = jest.fn() | ||
|
|
||
| const mockWatcher = { | ||
| onDidCreate: mockOnDidCreate.mockReturnValue({ dispose: mockDispose }), | ||
| onDidDelete: mockOnDidDelete.mockReturnValue({ dispose: mockDispose }), | ||
| onDidChange: mockOnDidChange.mockReturnValue({ dispose: mockDispose }), | ||
| dispose: mockDispose | ||
| } | ||
|
|
||
| jest.mock("vscode", () => ({ | ||
| workspace: { | ||
| workspaceFolders: [{ | ||
| uri: { fsPath: "/test/workspace" }, | ||
| name: "test", | ||
| index: 0 | ||
| }], | ||
| createFileSystemWatcher: jest.fn(() => mockWatcher), | ||
| fs: { | ||
| stat: jest.fn().mockResolvedValue({ type: 1 }) // FileType.File = 1 | ||
| } | ||
| }, | ||
| FileType: { File: 1, Directory: 2 } | ||
| })) | ||
|
|
||
| jest.mock("../../../services/glob/list-files") | ||
|
|
||
| describe("WorkspaceTracker", () => { | ||
| let workspaceTracker: WorkspaceTracker | ||
| let mockProvider: ClineProvider | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
|
|
||
| // Create provider mock | ||
| mockProvider = { postMessageToWebview: jest.fn() } as any | ||
|
|
||
| // Create tracker instance | ||
| workspaceTracker = new WorkspaceTracker(mockProvider) | ||
| }) | ||
|
|
||
| it("should initialize with workspace files", async () => { | ||
| const mockFiles = [["/test/workspace/file1.ts", "/test/workspace/file2.ts"], false] | ||
| ;(listFiles as jest.Mock).mockResolvedValue(mockFiles) | ||
|
|
||
| await workspaceTracker.initializeFilePaths() | ||
|
|
||
| expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ | ||
| type: "workspaceUpdated", | ||
| filePaths: ["file1.ts", "file2.ts"] | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle file creation events", async () => { | ||
| // Get the creation callback and call it | ||
| const [[callback]] = mockOnDidCreate.mock.calls | ||
| await callback({ fsPath: "/test/workspace/newfile.ts" }) | ||
|
|
||
| expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ | ||
| type: "workspaceUpdated", | ||
| filePaths: ["newfile.ts"] | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle file deletion events", async () => { | ||
| // First add a file | ||
| const [[createCallback]] = mockOnDidCreate.mock.calls | ||
| await createCallback({ fsPath: "/test/workspace/file.ts" }) | ||
|
|
||
| // Then delete it | ||
| const [[deleteCallback]] = mockOnDidDelete.mock.calls | ||
| await deleteCallback({ fsPath: "/test/workspace/file.ts" }) | ||
|
|
||
| // The last call should have empty filePaths | ||
| expect(mockProvider.postMessageToWebview).toHaveBeenLastCalledWith({ | ||
| type: "workspaceUpdated", | ||
| filePaths: [] | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle file change events", async () => { | ||
| const [[callback]] = mockOnDidChange.mock.calls | ||
| await callback({ fsPath: "/test/workspace/changed.ts" }) | ||
|
|
||
| expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ | ||
| type: "workspaceUpdated", | ||
| filePaths: ["changed.ts"] | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle directory paths correctly", async () => { | ||
| // Mock stat to return directory type | ||
| ;(vscode.workspace.fs.stat as jest.Mock).mockResolvedValueOnce({ type: 2 }) // FileType.Directory = 2 | ||
|
|
||
| const [[callback]] = mockOnDidCreate.mock.calls | ||
| await callback({ fsPath: "/test/workspace/newdir" }) | ||
|
|
||
| expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ | ||
| type: "workspaceUpdated", | ||
| filePaths: ["newdir"] | ||
| }) | ||
| }) | ||
|
|
||
| it("should clean up watchers on dispose", () => { | ||
| workspaceTracker.dispose() | ||
| expect(mockDispose).toHaveBeenCalled() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.