Skip to content

Commit

Permalink
better names for TextDocumentSaveReason, #12830
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 28, 2016
1 parent 5c602c0 commit e7376ad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
7 changes: 4 additions & 3 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3588,14 +3588,15 @@ declare namespace vscode {
export enum TextDocumentSaveReason {

/**
* Explicitly triggered, e.g. by the user pressing save or by an API call.
* Manually triggered, e.g. by the user pressing save, by starting debugging,
* or by an API call.
*/
Explicit = 1,
Manual = 1,

/**
* Automatic after a delay.
*/
Auto = 2,
AfterDelay = 2,

/**
* When the editor lost focus.
Expand Down
38 changes: 19 additions & 19 deletions src/vs/workbench/api/node/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import {ExtHostCommands} from 'vs/workbench/api/node/extHostCommands';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import Severity from 'vs/base/common/severity';
import {isFalsyOrEmpty} from 'vs/base/common/arrays';
import {IDisposable} from 'vs/base/common/lifecycle';
import {stringDiff} from 'vs/base/common/diff/diff';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { IDisposable } from 'vs/base/common/lifecycle';
import { stringDiff } from 'vs/base/common/diff/diff';
import * as modes from 'vs/editor/common/modes';
import * as types from './extHostTypes';
import {Position as EditorPosition} from 'vs/platform/editor/common/editor';
import {IPosition, ISelection, IRange, IDecorationOptions, ISingleEditOperation} from 'vs/editor/common/editorCommon';
import {IWorkspaceSymbol} from 'vs/workbench/parts/search/common/search';
import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { IPosition, ISelection, IRange, IDecorationOptions, ISingleEditOperation } from 'vs/editor/common/editorCommon';
import { IWorkspaceSymbol } from 'vs/workbench/parts/search/common/search';
import * as vscode from 'vscode';
import URI from 'vs/base/common/uri';
import { SaveReason } from 'vs/workbench/parts/files/common/files';
Expand Down Expand Up @@ -69,8 +69,8 @@ export function toPosition(position: IPosition): types.Position {
return new types.Position(position.lineNumber - 1, position.column - 1);
}

export function fromPosition(position: types.Position):IPosition {
return { lineNumber: position.line + 1, column: position.character + 1};
export function fromPosition(position: types.Position): IPosition {
return { lineNumber: position.line + 1, column: position.character + 1 };
}

export function fromDiagnosticSeverity(value: number): Severity {
Expand Down Expand Up @@ -118,26 +118,26 @@ export function toViewColumn(position?: EditorPosition): vscode.ViewColumn {
return;
}
if (position === EditorPosition.LEFT) {
return <number> types.ViewColumn.One;
return <number>types.ViewColumn.One;
} else if (position === EditorPosition.CENTER) {
return <number> types.ViewColumn.Two;
return <number>types.ViewColumn.Two;
} else if (position === EditorPosition.RIGHT) {
return <number> types.ViewColumn.Three;
return <number>types.ViewColumn.Three;
}
}

function isDecorationOptions(something: any): something is vscode.DecorationOptions {
return (typeof something.range !== 'undefined');
}

function isDecorationOptionsArr(something: vscode.Range[]|vscode.DecorationOptions[]): something is vscode.DecorationOptions[] {
function isDecorationOptionsArr(something: vscode.Range[] | vscode.DecorationOptions[]): something is vscode.DecorationOptions[] {
if (something.length === 0) {
return true;
}
return isDecorationOptions(something[0]) ? true : false;
}

export function fromRangeOrRangeWithMessage(ranges:vscode.Range[]|vscode.DecorationOptions[]): IDecorationOptions[] {
export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.DecorationOptions[]): IDecorationOptions[] {
if (isDecorationOptionsArr(ranges)) {
return ranges.map((r): IDecorationOptions => {
return {
Expand Down Expand Up @@ -182,8 +182,8 @@ export const TextEdit = {

for (let j = 0; j < changes.length; j++) {
const {originalStart, originalLength, modifiedStart, modifiedLength} = changes[j];
const start = fromPosition(<types.Position> document.positionAt(editOffset + originalStart));
const end = fromPosition(<types.Position> document.positionAt(editOffset + originalStart + originalLength));
const start = fromPosition(<types.Position>document.positionAt(editOffset + originalStart));
const end = fromPosition(<types.Position>document.positionAt(editOffset + originalStart + originalLength));

result.push({
text: modified.substr(modifiedStart, modifiedLength),
Expand All @@ -195,7 +195,7 @@ export const TextEdit = {
return result;
},

from(edit: vscode.TextEdit): ISingleEditOperation{
from(edit: vscode.TextEdit): ISingleEditOperation {
return <ISingleEditOperation>{
text: edit.newText,
range: fromRange(edit.range)
Expand Down Expand Up @@ -443,9 +443,9 @@ export namespace TextDocumentSaveReason {
export function to(reason: SaveReason): vscode.TextDocumentSaveReason {
switch (reason) {
case SaveReason.AUTO:
return types.TextDocumentSaveReason.Auto;
return types.TextDocumentSaveReason.AfterDelay;
case SaveReason.EXPLICIT:
return types.TextDocumentSaveReason.Explicit;
return types.TextDocumentSaveReason.Manual;
case SaveReason.FOCUS_CHANGE:
case SaveReason.WINDOW_CHANGE:
return types.TextDocumentSaveReason.FocusOut;
Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

import URI from 'vs/base/common/uri';
import {illegalArgument} from 'vs/base/common/errors';
import { illegalArgument } from 'vs/base/common/errors';

export class Disposable {

Expand Down Expand Up @@ -149,7 +149,7 @@ export class Position {
}
}

translate(change: { lineDelta?: number; characterDelta?: number;}): Position;
translate(change: { lineDelta?: number; characterDelta?: number; }): Position;
translate(lineDelta?: number, characterDelta?: number): Position;
translate(lineDeltaOrChange: number | { lineDelta?: number; characterDelta?: number; }, characterDelta: number = 0): Position {

Expand Down Expand Up @@ -230,7 +230,7 @@ export class Range {

constructor(start: Position, end: Position);
constructor(startLine: number, startColumn: number, endLine: number, endColumn: number);
constructor(startLineOrStart: number|Position, startColumnOrEnd: number|Position, endLine?: number, endColumn?: number) {
constructor(startLineOrStart: number | Position, startColumnOrEnd: number | Position, endLine?: number, endColumn?: number) {
let start: Position;
let end: Position;

Expand Down Expand Up @@ -367,7 +367,7 @@ export class Selection extends Range {

constructor(anchor: Position, active: Position);
constructor(anchorLine: number, anchorColumn: number, activeLine: number, activeColumn: number);
constructor(anchorLineOrAnchor: number|Position, anchorColumnOrActive: number|Position, activeLine?: number, activeColumn?: number) {
constructor(anchorLineOrAnchor: number | Position, anchorColumnOrActive: number | Position, activeLine?: number, activeColumn?: number) {
let anchor: Position;
let active: Position;

Expand Down Expand Up @@ -679,7 +679,7 @@ export class SymbolInformation {
if (locationOrUri instanceof Location) {
this.location = locationOrUri;
} else if (rangeOrContainer instanceof Range) {
this.location = new Location(<URI> locationOrUri, rangeOrContainer);
this.location = new Location(<URI>locationOrUri, rangeOrContainer);
}
}

Expand Down Expand Up @@ -832,8 +832,8 @@ export enum TextEditorLineNumbersStyle {
}

export enum TextDocumentSaveReason {
Explicit = 1,
Auto = 2,
Manual = 1,
AfterDelay = 2,
FocusOut = 3
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {ExtHostDocuments} from 'vs/workbench/api/node/extHostDocuments';
import {TextDocumentSaveReason, TextEdit, Position} from 'vs/workbench/api/node/extHostTypes';
import {MainThreadWorkspaceShape} from 'vs/workbench/api/node/extHost.protocol';
import {ExtHostDocumentSaveParticipant} from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
import {OneGetThreadService} from './testThreadService';
import { TPromise } from 'vs/base/common/winjs.base';
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import { TextDocumentSaveReason, TextEdit, Position } from 'vs/workbench/api/node/extHostTypes';
import { MainThreadWorkspaceShape } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
import { OneGetThreadService } from './testThreadService';
import * as EditorCommon from 'vs/editor/common/editorCommon';
import {IResourceEdit} from 'vs/editor/common/services/bulkEdit';
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
import { SaveReason } from 'vs/workbench/parts/files/common/files';

suite('ExtHostDocumentSaveParticipant', () => {
Expand Down Expand Up @@ -62,7 +62,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
sub.dispose();

assert.ok(event);
assert.equal(event.reason, TextDocumentSaveReason.Explicit);
assert.equal(event.reason, TextDocumentSaveReason.Manual);
assert.equal(typeof event.waitUntil, 'function');
});
});
Expand Down

0 comments on commit e7376ad

Please sign in to comment.