-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for untitled file working copies (#124120)
* untitled file working copy - first cut * untitled file working copy - first cut manager * untitled file working copy - tests * untitled file working copy - 💄 * untitled file working copy - extract reusable interfaces * untitled file working copy - extract common super type for manager * untitled file working copy - add workingcopyservice#get * untitled file working copy - wire in save support * untitled file working copy - fix tests * untitled file working copy - some code 💄 * untitled file working copy - set visibility * untitled file working copy - poperly resolve target * untitled file working copy - shared dispose handling * untitled file working copy - add new manager that unifies file and untitled working copies * untitled file working copy - tests for new unified manager * untitled file working copy - test 💄
- Loading branch information
Showing
21 changed files
with
2,156 additions
and
368 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
112 changes: 112 additions & 0 deletions
112
src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopy.ts
This file contains 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,112 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { IDisposable } from 'vs/base/common/lifecycle'; | ||
import { Event } from 'vs/base/common/event'; | ||
import { CancellationToken } from 'vs/base/common/cancellation'; | ||
import { VSBufferReadableStream } from 'vs/base/common/buffer'; | ||
import { URI } from 'vs/base/common/uri'; | ||
import { IWorkingCopy } from 'vs/workbench/services/workingCopy/common/workingCopy'; | ||
|
||
export interface IBaseFileWorkingCopyModelFactory<T extends IBaseFileWorkingCopyModel> { | ||
|
||
/** | ||
* Create a model from the given content under the provided resource. | ||
* | ||
* @param resource the `URI` of the model | ||
* @param contents the content of the model to create it | ||
* @param token support for cancellation | ||
*/ | ||
createModel(resource: URI, contents: VSBufferReadableStream, token: CancellationToken): Promise<T>; | ||
} | ||
|
||
/** | ||
* A generic file working copy model to be reused by untitled | ||
* and existing file working copies. | ||
*/ | ||
export interface IBaseFileWorkingCopyModel extends IDisposable { | ||
|
||
/** | ||
* This event signals ANY changes to the contents, for example: | ||
* - through the user typing into the editor | ||
* - from API usage (e.g. bulk edits) | ||
* - when `IBaseFileWorkingCopyModel#update` is invoked with contents | ||
* that are different from the current contents | ||
* | ||
* The file working copy will listen to these changes and may mark | ||
* the working copy as dirty whenever this event fires. | ||
* | ||
* Note: ONLY report changes to the model but not the underlying | ||
* file. The file working copy is tracking changes to the file | ||
* automatically. | ||
*/ | ||
readonly onDidChangeContent: Event<unknown>; | ||
|
||
/** | ||
* An event emitted right before disposing the model. | ||
*/ | ||
readonly onWillDispose: Event<void>; | ||
|
||
/** | ||
* Snapshots the model's current content for writing. This must include | ||
* any changes that were made to the model that are in memory. | ||
* | ||
* @param token support for cancellation | ||
*/ | ||
snapshot(token: CancellationToken): Promise<VSBufferReadableStream>; | ||
|
||
/** | ||
* Updates the model with the provided contents. The implementation should | ||
* behave in a similar fashion as `IBaseFileWorkingCopyModelFactory#createModel` | ||
* except that here the model already exists and just needs to update to | ||
* the provided contents. | ||
* | ||
* Note: it is expected that the model fires a `onDidChangeContent` event | ||
* as part of the update. | ||
* | ||
* @param the contents to use for the model | ||
* @param token support for cancellation | ||
*/ | ||
update(contents: VSBufferReadableStream, token: CancellationToken): Promise<void>; | ||
} | ||
|
||
export interface IBaseFileWorkingCopy<T extends IBaseFileWorkingCopyModel> extends IWorkingCopy, IDisposable { | ||
|
||
/** | ||
* An event for when the file working copy has been reverted. | ||
*/ | ||
readonly onDidRevert: Event<void>; | ||
|
||
/** | ||
* An event for when the file working copy has been disposed. | ||
*/ | ||
readonly onWillDispose: Event<void>; | ||
|
||
/** | ||
* Provides access to the underlying model of this file | ||
* based working copy. As long as the file working copy | ||
* has not been resolved, the model is `undefined`. | ||
*/ | ||
readonly model: T | undefined; | ||
|
||
/** | ||
* Resolves the file working copy and thus makes the `model` | ||
* available. | ||
*/ | ||
resolve(): Promise<void>; | ||
|
||
/** | ||
* Whether we have a resolved model or not. | ||
*/ | ||
isResolved(): this is IBaseResolvedFileWorkingCopy<T>; | ||
} | ||
|
||
export interface IBaseResolvedFileWorkingCopy<T extends IBaseFileWorkingCopyModel> extends IBaseFileWorkingCopy<T> { | ||
|
||
/** | ||
* A resolved file working copy has a resolved model. | ||
*/ | ||
readonly model: T; | ||
} |
Oops, something went wrong.