提交 45906d91 编写于 作者: A Alex Dima

Add ability to change a document's EOL

上级 e8d5a793
...@@ -796,6 +796,20 @@ declare namespace vscode { ...@@ -796,6 +796,20 @@ declare namespace vscode {
hide(): void; hide(): void;
} }
/**
* Represents an end of line character sequence in a [document](#Document).
*/
export enum EndOfLine {
/**
* The line feed `\n` character.
*/
LF = 1,
/**
* The carriage return line feed `\r\n` sequence.
*/
CRLF = 2
}
/** /**
* A complex edit that will be applied in one transaction on a TextEditor. * A complex edit that will be applied in one transaction on a TextEditor.
* This holds a description of the edits and if the edits are valid (i.e. no overlapping regions, document was not changed in the meantime, etc.) * This holds a description of the edits and if the edits are valid (i.e. no overlapping regions, document was not changed in the meantime, etc.)
...@@ -828,6 +842,13 @@ declare namespace vscode { ...@@ -828,6 +842,13 @@ declare namespace vscode {
* @param location The range this operation should remove. * @param location The range this operation should remove.
*/ */
delete(location: Range | Selection): void; delete(location: Range | Selection): void;
/**
* Set the end of line sequence.
*
* @param endOfLine The new end of line for the [document](#Document).
*/
setEndOfLine(endOfLine:EndOfLine): void;
} }
/** /**
......
...@@ -85,6 +85,7 @@ export class ExtHostAPIImplementation { ...@@ -85,6 +85,7 @@ export class ExtHostAPIImplementation {
IndentAction: typeof vscode.IndentAction; IndentAction: typeof vscode.IndentAction;
OverviewRulerLane: typeof vscode.OverviewRulerLane; OverviewRulerLane: typeof vscode.OverviewRulerLane;
TextEditorRevealType: typeof vscode.TextEditorRevealType; TextEditorRevealType: typeof vscode.TextEditorRevealType;
EndOfLine: typeof vscode.EndOfLine;
commands: typeof vscode.commands; commands: typeof vscode.commands;
window: typeof vscode.window; window: typeof vscode.window;
workspace: typeof vscode.workspace; workspace: typeof vscode.workspace;
...@@ -103,8 +104,8 @@ export class ExtHostAPIImplementation { ...@@ -103,8 +104,8 @@ export class ExtHostAPIImplementation {
this.version = contextService.getConfiguration().env.version; this.version = contextService.getConfiguration().env.version;
this.Uri = URI; this.Uri = URI;
this.Location = extHostTypes.Location; this.Location = extHostTypes.Location;
this.Diagnostic = <any> extHostTypes.Diagnostic; this.Diagnostic = extHostTypes.Diagnostic;
this.DiagnosticSeverity = <any>extHostTypes.DiagnosticSeverity; this.DiagnosticSeverity = extHostTypes.DiagnosticSeverity;
this.EventEmitter = Emitter; this.EventEmitter = Emitter;
this.Disposable = extHostTypes.Disposable; this.Disposable = extHostTypes.Disposable;
this.TextEdit = extHostTypes.TextEdit; this.TextEdit = extHostTypes.TextEdit;
...@@ -114,22 +115,23 @@ export class ExtHostAPIImplementation { ...@@ -114,22 +115,23 @@ export class ExtHostAPIImplementation {
this.Selection = extHostTypes.Selection; this.Selection = extHostTypes.Selection;
this.CancellationTokenSource = CancellationTokenSource; this.CancellationTokenSource = CancellationTokenSource;
this.Hover = extHostTypes.Hover; this.Hover = extHostTypes.Hover;
this.SymbolKind = <any>extHostTypes.SymbolKind; this.SymbolKind = extHostTypes.SymbolKind;
this.SymbolInformation = <any>extHostTypes.SymbolInformation; this.SymbolInformation = extHostTypes.SymbolInformation;
this.DocumentHighlightKind = <any>extHostTypes.DocumentHighlightKind; this.DocumentHighlightKind = extHostTypes.DocumentHighlightKind;
this.DocumentHighlight = <any>extHostTypes.DocumentHighlight; this.DocumentHighlight = extHostTypes.DocumentHighlight;
this.CodeLens = extHostTypes.CodeLens; this.CodeLens = extHostTypes.CodeLens;
this.ParameterInformation = extHostTypes.ParameterInformation; this.ParameterInformation = extHostTypes.ParameterInformation;
this.SignatureInformation = extHostTypes.SignatureInformation; this.SignatureInformation = extHostTypes.SignatureInformation;
this.SignatureHelp = extHostTypes.SignatureHelp; this.SignatureHelp = extHostTypes.SignatureHelp;
this.CompletionItem = <any>extHostTypes.CompletionItem; this.CompletionItem = extHostTypes.CompletionItem;
this.CompletionItemKind = <any>extHostTypes.CompletionItemKind; this.CompletionItemKind = extHostTypes.CompletionItemKind;
this.CompletionList = extHostTypes.CompletionList; this.CompletionList = extHostTypes.CompletionList;
this.ViewColumn = <any>extHostTypes.ViewColumn; this.ViewColumn = extHostTypes.ViewColumn;
this.StatusBarAlignment = <any>extHostTypes.StatusBarAlignment; this.StatusBarAlignment = extHostTypes.StatusBarAlignment;
this.IndentAction = <any>Modes.IndentAction; this.IndentAction = Modes.IndentAction;
this.OverviewRulerLane = <any>EditorCommon.OverviewRulerLane; this.OverviewRulerLane = EditorCommon.OverviewRulerLane;
this.TextEditorRevealType = <any>TextEditorRevealType; this.TextEditorRevealType = TextEditorRevealType;
this.EndOfLine = extHostTypes.EndOfLine;
errors.setUnexpectedErrorHandler((err) => { errors.setUnexpectedErrorHandler((err) => {
this._proxy.onUnexpectedExtHostError(errors.transformErrorForSerialization(err)); this._proxy.onUnexpectedExtHostError(errors.transformErrorForSerialization(err));
......
...@@ -10,7 +10,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle'; ...@@ -10,7 +10,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base'; import {TPromise} from 'vs/base/common/winjs.base';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread'; import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {ExtHostModelService, ExtHostDocumentData} from 'vs/workbench/api/node/extHostDocuments'; import {ExtHostModelService, ExtHostDocumentData} from 'vs/workbench/api/node/extHostDocuments';
import {Selection, Range, Position, EditorOptions} from './extHostTypes'; import {Selection, Range, Position, EditorOptions, EndOfLine} from './extHostTypes';
import {ISingleEditOperation, ISelection, IRange, IEditor, EditorType, ICommonCodeEditor, ICommonDiffEditor, IDecorationRenderOptions, IRangeWithMessage} from 'vs/editor/common/editorCommon'; import {ISingleEditOperation, ISelection, IRange, IEditor, EditorType, ICommonCodeEditor, ICommonDiffEditor, IDecorationRenderOptions, IRangeWithMessage} from 'vs/editor/common/editorCommon';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService'; import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
...@@ -196,22 +196,26 @@ export interface ITextEditOperation { ...@@ -196,22 +196,26 @@ export interface ITextEditOperation {
export interface IEditData { export interface IEditData {
documentVersionId: number; documentVersionId: number;
edits: ITextEditOperation[]; edits: ITextEditOperation[];
setEndOfLine: EndOfLine;
} }
export class TextEditorEdit { export class TextEditorEdit {
private _documentVersionId: number; private _documentVersionId: number;
private _collectedEdits: ITextEditOperation[]; private _collectedEdits: ITextEditOperation[];
private _setEndOfLine: EndOfLine;
constructor(document: vscode.TextDocument) { constructor(document: vscode.TextDocument) {
this._documentVersionId = document.version; this._documentVersionId = document.version;
this._collectedEdits = []; this._collectedEdits = [];
this._setEndOfLine = 0;
} }
finalize(): IEditData { finalize(): IEditData {
return { return {
documentVersionId: this._documentVersionId, documentVersionId: this._documentVersionId,
edits: this._collectedEdits edits: this._collectedEdits,
setEndOfLine: this._setEndOfLine
}; };
} }
...@@ -260,6 +264,14 @@ export class TextEditorEdit { ...@@ -260,6 +264,14 @@ export class TextEditorEdit {
forceMoveMarkers: true forceMoveMarkers: true
}); });
} }
setEndOfLine(endOfLine:EndOfLine): void {
if (endOfLine !== EndOfLine.LF && endOfLine !== EndOfLine.CRLF) {
throw illegalArg('endOfLine');
}
this._setEndOfLine = endOfLine;
}
} }
function readonly(name: string, alt?: string) { function readonly(name: string, alt?: string) {
...@@ -435,7 +447,7 @@ class ExtHostTextEditor implements vscode.TextEditor { ...@@ -435,7 +447,7 @@ class ExtHostTextEditor implements vscode.TextEditor {
}; };
}); });
return this._proxy._tryApplyEdits(this._id, editData.documentVersionId, edits); return this._proxy._tryApplyEdits(this._id, editData.documentVersionId, edits, editData.setEndOfLine);
} }
// ---- util // ---- util
...@@ -705,11 +717,11 @@ export class MainThreadEditors { ...@@ -705,11 +717,11 @@ export class MainThreadEditors {
return TPromise.as(null); return TPromise.as(null);
} }
_tryApplyEdits(id: string, modelVersionId: number, edits: ISingleEditOperation[]): TPromise<boolean> { _tryApplyEdits(id: string, modelVersionId: number, edits: ISingleEditOperation[], setEndOfLine:EndOfLine): TPromise<boolean> {
if (!this._textEditorsMap[id]) { if (!this._textEditorsMap[id]) {
return TPromise.wrapError('TextEditor disposed'); return TPromise.wrapError('TextEditor disposed');
} }
return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits)); return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits, setEndOfLine));
} }
_registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void { _registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void {
......
...@@ -688,3 +688,8 @@ export enum StatusBarAlignment { ...@@ -688,3 +688,8 @@ export enum StatusBarAlignment {
Left = 1, Left = 1,
Right = 2 Right = 2
} }
export enum EndOfLine {
LF = 1,
CRLF = 2
}
\ No newline at end of file
...@@ -13,6 +13,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle'; ...@@ -13,6 +13,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
import {RunOnceScheduler} from 'vs/base/common/async'; import {RunOnceScheduler} from 'vs/base/common/async';
import {Range} from 'vs/editor/common/core/range'; import {Range} from 'vs/editor/common/core/range';
import {Selection} from 'vs/editor/common/core/selection'; import {Selection} from 'vs/editor/common/core/selection';
import {EndOfLine} from 'vs/workbench/api/node/extHostTypes';
export interface ITextEditorConfigurationUpdate { export interface ITextEditorConfigurationUpdate {
tabSize?: number | string; tabSize?: number | string;
...@@ -262,7 +263,7 @@ export class MainThreadTextEditor { ...@@ -262,7 +263,7 @@ export class MainThreadTextEditor {
return editor.getControl() === this._codeEditor; return editor.getControl() === this._codeEditor;
} }
public applyEdits(versionIdCheck:number, edits:EditorCommon.ISingleEditOperation[]): boolean { public applyEdits(versionIdCheck:number, edits:EditorCommon.ISingleEditOperation[], setEndOfLine:EndOfLine): boolean {
if (this._model.getVersionId() !== versionIdCheck) { if (this._model.getVersionId() !== versionIdCheck) {
console.warn('Model has changed in the meantime!'); console.warn('Model has changed in the meantime!');
// throw new Error('Model has changed in the meantime!'); // throw new Error('Model has changed in the meantime!');
...@@ -271,6 +272,12 @@ export class MainThreadTextEditor { ...@@ -271,6 +272,12 @@ export class MainThreadTextEditor {
} }
if (this._codeEditor) { if (this._codeEditor) {
if (setEndOfLine === EndOfLine.CRLF) {
this._model.setEOL(EditorCommon.EndOfLineSequence.CRLF);
} else if (setEndOfLine === EndOfLine.LF) {
this._model.setEOL(EditorCommon.EndOfLineSequence.LF);
}
let transformedEdits = edits.map((edit): EditorCommon.IIdentifiedSingleEditOperation => { let transformedEdits = edits.map((edit): EditorCommon.IIdentifiedSingleEditOperation => {
return { return {
identifier: null, identifier: null,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册