Merge pull request #75375 from microsoft/dev/mjbvz/vscode-api-readonly-events

Mark events as readonly in VS Code api
This commit is contained in:
Matt Bierner 2019-06-14 11:59:57 -07:00 committed by GitHub
commit c419355b5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 41 deletions

View file

@ -230,7 +230,7 @@ class TaskDetector {
this.detectors.clear(); this.detectors.clear();
} }
private updateWorkspaceFolders(added: vscode.WorkspaceFolder[], removed: vscode.WorkspaceFolder[]): void { private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
for (let remove of removed) { for (let remove of removed) {
let detector = this.detectors.get(remove.uri.toString()); let detector = this.detectors.get(remove.uri.toString());
if (detector) { if (detector) {

View file

@ -209,7 +209,7 @@ class TaskDetector {
this.detectors.clear(); this.detectors.clear();
} }
private updateWorkspaceFolders(added: vscode.WorkspaceFolder[], removed: vscode.WorkspaceFolder[]): void { private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
for (let remove of removed) { for (let remove of removed) {
let detector = this.detectors.get(remove.uri.toString()); let detector = this.detectors.get(remove.uri.toString());
if (detector) { if (detector) {

View file

@ -32,7 +32,7 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
isEnabled = true; isEnabled = true;
} }
function onDidChangeTextDocument(document: TextDocument, changes: TextDocumentContentChangeEvent[]) { function onDidChangeTextDocument(document: TextDocument, changes: readonly TextDocumentContentChangeEvent[]) {
if (!isEnabled) { if (!isEnabled) {
return; return;
} }

View file

@ -208,7 +208,7 @@ class TaskDetector {
this.detectors.clear(); this.detectors.clear();
} }
private updateWorkspaceFolders(added: vscode.WorkspaceFolder[], removed: vscode.WorkspaceFolder[]): void { private updateWorkspaceFolders(added: readonly vscode.WorkspaceFolder[], removed: readonly vscode.WorkspaceFolder[]): void {
for (let remove of removed) { for (let remove of removed) {
let detector = this.detectors.get(remove.uri.toString()); let detector = this.detectors.get(remove.uri.toString());
if (detector) { if (detector) {

View file

@ -75,7 +75,7 @@ class BufferSynchronizer {
} }
} }
public change(filepath: string, events: vscode.TextDocumentContentChangeEvent[]) { public change(filepath: string, events: readonly vscode.TextDocumentContentChangeEvent[]) {
if (!events.length) { if (!events.length) {
return; return;
} }
@ -210,7 +210,7 @@ class SyncedBuffer {
this.state = BufferState.Closed; this.state = BufferState.Closed;
} }
public onContentChanged(events: vscode.TextDocumentContentChangeEvent[]): void { public onContentChanged(events: readonly vscode.TextDocumentContentChangeEvent[]): void {
if (this.state !== BufferState.Open) { if (this.state !== BufferState.Open) {
console.error(`Unexpected buffer state: ${this.state}`); console.error(`Unexpected buffer state: ${this.state}`);
} }

View file

@ -46,7 +46,7 @@ class TagClosing extends Disposable {
private onDidChangeTextDocument( private onDidChangeTextDocument(
document: vscode.TextDocument, document: vscode.TextDocument,
changes: vscode.TextDocumentContentChangeEvent[] changes: readonly vscode.TextDocumentContentChangeEvent[]
) { ) {
const activeDocument = vscode.window.activeTextEditor && vscode.window.activeTextEditor.document; const activeDocument = vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
if (document !== activeDocument || changes.length === 0) { if (document !== activeDocument || changes.length === 0) {

60
src/vs/vscode.d.ts vendored
View file

@ -531,16 +531,16 @@ declare module 'vscode' {
/** /**
* The [text editor](#TextEditor) for which the selections have changed. * The [text editor](#TextEditor) for which the selections have changed.
*/ */
textEditor: TextEditor; readonly textEditor: TextEditor;
/** /**
* The new value for the [text editor's selections](#TextEditor.selections). * The new value for the [text editor's selections](#TextEditor.selections).
*/ */
selections: Selection[]; readonly selections: ReadonlyArray<Selection>;
/** /**
* The [change kind](#TextEditorSelectionChangeKind) which has triggered this * The [change kind](#TextEditorSelectionChangeKind) which has triggered this
* event. Can be `undefined`. * event. Can be `undefined`.
*/ */
kind?: TextEditorSelectionChangeKind; readonly kind?: TextEditorSelectionChangeKind;
} }
/** /**
@ -550,11 +550,11 @@ declare module 'vscode' {
/** /**
* The [text editor](#TextEditor) for which the visible ranges have changed. * The [text editor](#TextEditor) for which the visible ranges have changed.
*/ */
textEditor: TextEditor; readonly textEditor: TextEditor;
/** /**
* The new value for the [text editor's visible ranges](#TextEditor.visibleRanges). * The new value for the [text editor's visible ranges](#TextEditor.visibleRanges).
*/ */
visibleRanges: Range[]; readonly visibleRanges: ReadonlyArray<Range>;
} }
/** /**
@ -564,11 +564,11 @@ declare module 'vscode' {
/** /**
* The [text editor](#TextEditor) for which the options have changed. * The [text editor](#TextEditor) for which the options have changed.
*/ */
textEditor: TextEditor; readonly textEditor: TextEditor;
/** /**
* The new value for the [text editor's options](#TextEditor.options). * The new value for the [text editor's options](#TextEditor.options).
*/ */
options: TextEditorOptions; readonly options: TextEditorOptions;
} }
/** /**
@ -578,11 +578,11 @@ declare module 'vscode' {
/** /**
* The [text editor](#TextEditor) for which the view column has changed. * The [text editor](#TextEditor) for which the view column has changed.
*/ */
textEditor: TextEditor; readonly textEditor: TextEditor;
/** /**
* The new value for the [text editor's view column](#TextEditor.viewColumn). * The new value for the [text editor's view column](#TextEditor.viewColumn).
*/ */
viewColumn: ViewColumn; readonly viewColumn: ViewColumn;
} }
/** /**
@ -4203,7 +4203,7 @@ declare module 'vscode' {
/** /**
* An array of resources for which diagnostics have changed. * An array of resources for which diagnostics have changed.
*/ */
readonly uris: Uri[]; readonly uris: ReadonlyArray<Uri>;
} }
/** /**
@ -5331,7 +5331,7 @@ declare module 'vscode' {
/** /**
* The task item representing the task that got started. * The task item representing the task that got started.
*/ */
execution: TaskExecution; readonly execution: TaskExecution;
} }
/** /**
@ -5343,7 +5343,7 @@ declare module 'vscode' {
/** /**
* The task item representing the task that finished. * The task item representing the task that finished.
*/ */
execution: TaskExecution; readonly execution: TaskExecution;
} }
/** /**
@ -5355,12 +5355,12 @@ declare module 'vscode' {
/** /**
* The task execution for which the process got started. * The task execution for which the process got started.
*/ */
execution: TaskExecution; readonly execution: TaskExecution;
/** /**
* The underlying process id. * The underlying process id.
*/ */
processId: number; readonly processId: number;
} }
/** /**
@ -5372,12 +5372,12 @@ declare module 'vscode' {
/** /**
* The task execution for which the process got started. * The task execution for which the process got started.
*/ */
execution: TaskExecution; readonly execution: TaskExecution;
/** /**
* The process's exit code. * The process's exit code.
*/ */
exitCode: number; readonly exitCode: number;
} }
export interface TaskFilter { export interface TaskFilter {
@ -5584,12 +5584,12 @@ declare module 'vscode' {
/** /**
* The type of change. * The type of change.
*/ */
type: FileChangeType; readonly type: FileChangeType;
/** /**
* The uri of the file that has changed. * The uri of the file that has changed.
*/ */
uri: Uri; readonly uri: Uri;
} }
/** /**
@ -7331,12 +7331,12 @@ declare module 'vscode' {
/** /**
* The affected document. * The affected document.
*/ */
document: TextDocument; readonly document: TextDocument;
/** /**
* An array of content changes. * An array of content changes.
*/ */
contentChanges: TextDocumentContentChangeEvent[]; readonly contentChanges: ReadonlyArray<TextDocumentContentChangeEvent>;
} }
/** /**
@ -7373,12 +7373,12 @@ declare module 'vscode' {
/** /**
* The document that will be saved. * The document that will be saved.
*/ */
document: TextDocument; readonly document: TextDocument;
/** /**
* The reason why save was triggered. * The reason why save was triggered.
*/ */
reason: TextDocumentSaveReason; readonly reason: TextDocumentSaveReason;
/** /**
* Allows to pause the event loop and to apply [pre-save-edits](#TextEdit). * Allows to pause the event loop and to apply [pre-save-edits](#TextEdit).
@ -7419,12 +7419,12 @@ declare module 'vscode' {
/** /**
* Added workspace folders. * Added workspace folders.
*/ */
readonly added: WorkspaceFolder[]; readonly added: ReadonlyArray<WorkspaceFolder>;
/** /**
* Removed workspace folders. * Removed workspace folders.
*/ */
readonly removed: WorkspaceFolder[]; readonly removed: ReadonlyArray<WorkspaceFolder>;
} }
/** /**
@ -8500,17 +8500,17 @@ declare module 'vscode' {
/** /**
* The [debug session](#DebugSession) for which the custom event was received. * The [debug session](#DebugSession) for which the custom event was received.
*/ */
session: DebugSession; readonly session: DebugSession;
/** /**
* Type of event. * Type of event.
*/ */
event: string; readonly event: string;
/** /**
* Event specific information. * Event specific information.
*/ */
body?: any; readonly body?: any;
} }
/** /**
@ -8707,17 +8707,17 @@ declare module 'vscode' {
/** /**
* Added breakpoints. * Added breakpoints.
*/ */
readonly added: Breakpoint[]; readonly added: ReadonlyArray<Breakpoint>;
/** /**
* Removed breakpoints. * Removed breakpoints.
*/ */
readonly removed: Breakpoint[]; readonly removed: ReadonlyArray<Breakpoint>;
/** /**
* Changed breakpoints. * Changed breakpoints.
*/ */
readonly changed: Breakpoint[]; readonly changed: ReadonlyArray<Breakpoint>;
} }
/** /**

View file

@ -822,17 +822,17 @@ declare module 'vscode' {
/** /**
* Added comment threads. * Added comment threads.
*/ */
readonly added: CommentThread[]; readonly added: ReadonlyArray<CommentThread>;
/** /**
* Removed comment threads. * Removed comment threads.
*/ */
readonly removed: CommentThread[]; readonly removed: ReadonlyArray<CommentThread>;
/** /**
* Changed comment threads. * Changed comment threads.
*/ */
readonly changed: CommentThread[]; readonly changed: ReadonlyArray<CommentThread>;
/** /**
* Changed draft mode * Changed draft mode

View file

@ -85,7 +85,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
sub.dispose(); sub.dispose();
assert.ok(event); assert.ok(event);
assert.throws(() => { event.document = null!; }); assert.throws(() => { (event.document as any) = null!; });
}); });
}); });