mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
add TextEdit#newEol, adopt for workspace edit and onWillSave-event
This commit is contained in:
@@ -12,7 +12,7 @@ import { illegalState } from 'vs/base/common/errors';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { MainThreadWorkspaceShape, ExtHostDocumentSaveParticipantShape } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { TextEdit } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { fromRange, TextDocumentSaveReason } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { fromRange, TextDocumentSaveReason, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
@@ -138,11 +138,12 @@ export class ExtHostDocumentSaveParticipant extends ExtHostDocumentSaveParticipa
|
||||
|
||||
for (const value of values) {
|
||||
if (Array.isArray(value) && (<vscode.TextEdit[]>value).every(e => e instanceof TextEdit)) {
|
||||
for (const { newText, range } of value) {
|
||||
for (const { newText, newEol, range } of value) {
|
||||
edits.push({
|
||||
resource: <URI>document.uri,
|
||||
range: fromRange(range),
|
||||
newText
|
||||
range: range && fromRange(range),
|
||||
newText,
|
||||
newEol: EndOfLine.from(newEol)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,12 +366,15 @@ export namespace TextDocumentSaveReason {
|
||||
}
|
||||
|
||||
|
||||
export function fromEOL(eol: vscode.EndOfLine): EndOfLineSequence {
|
||||
if (eol === types.EndOfLine.CRLF) {
|
||||
return EndOfLineSequence.CRLF;
|
||||
} else if (eol === types.EndOfLine.LF) {
|
||||
return EndOfLineSequence.LF;
|
||||
export namespace EndOfLine {
|
||||
|
||||
export function from(eol: vscode.EndOfLine): EndOfLineSequence {
|
||||
if (eol === types.EndOfLine.CRLF) {
|
||||
return EndOfLineSequence.CRLF;
|
||||
} else if (eol === types.EndOfLine.LF) {
|
||||
return EndOfLineSequence.LF;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,16 +429,22 @@ export class TextEdit {
|
||||
return TextEdit.replace(range, '');
|
||||
}
|
||||
|
||||
protected _range: Range;
|
||||
static setEndOfLine(eol: EndOfLine): TextEdit {
|
||||
let ret = new TextEdit(undefined, undefined);
|
||||
ret.newEol = eol;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected _range: Range;
|
||||
protected _newText: string;
|
||||
protected _newEol: EndOfLine;
|
||||
|
||||
get range(): Range {
|
||||
return this._range;
|
||||
}
|
||||
|
||||
set range(value: Range) {
|
||||
if (!value) {
|
||||
if (value && !Range.isRange(value)) {
|
||||
throw illegalArgument('range');
|
||||
}
|
||||
this._range = value;
|
||||
@@ -448,10 +454,24 @@ export class TextEdit {
|
||||
return this._newText || '';
|
||||
}
|
||||
|
||||
set newText(value) {
|
||||
set newText(value: string) {
|
||||
if (value && typeof value !== 'string') {
|
||||
throw illegalArgument('newText');
|
||||
}
|
||||
this._newText = value;
|
||||
}
|
||||
|
||||
get newEol(): EndOfLine {
|
||||
return this._newEol;
|
||||
}
|
||||
|
||||
set newEol(value: EndOfLine) {
|
||||
if (value && typeof value !== 'number') {
|
||||
throw illegalArgument('newEol');
|
||||
}
|
||||
this._newEol = value;
|
||||
}
|
||||
|
||||
constructor(range: Range, newText: string) {
|
||||
this.range = range;
|
||||
this.newText = newText;
|
||||
@@ -460,7 +480,8 @@ export class TextEdit {
|
||||
toJSON(): any {
|
||||
return {
|
||||
range: this.range,
|
||||
newText: this.newText
|
||||
newText: this.newText,
|
||||
newEol: this._newEol
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1186,4 +1207,4 @@ export class ShellTask extends BaseTask {
|
||||
}
|
||||
this._options = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import URI from 'vs/base/common/uri';
|
||||
import { normalize } from 'vs/base/common/paths';
|
||||
import { relative } from 'path';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { IResourceTextEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { fromRange } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { fromRange, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { MainContext, MainThreadWorkspaceShape } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
@@ -70,7 +70,7 @@ export class ExtHostWorkspace {
|
||||
|
||||
appyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
|
||||
|
||||
let resourceEdits: IResourceTextEdit[] = [];
|
||||
let resourceEdits: IResourceEdit[] = [];
|
||||
|
||||
let entries = edit.entries();
|
||||
for (let entry of entries) {
|
||||
@@ -80,7 +80,8 @@ export class ExtHostWorkspace {
|
||||
resourceEdits.push({
|
||||
resource: <URI>uri,
|
||||
newText: edit.newText,
|
||||
range: fromRange(edit.range)
|
||||
newEol: EndOfLine.from(edit.newEol),
|
||||
range: edit.range && fromRange(edit.range)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user