mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Add ability to change a document's EOL
This commit is contained in:
@@ -85,6 +85,7 @@ export class ExtHostAPIImplementation {
|
||||
IndentAction: typeof vscode.IndentAction;
|
||||
OverviewRulerLane: typeof vscode.OverviewRulerLane;
|
||||
TextEditorRevealType: typeof vscode.TextEditorRevealType;
|
||||
EndOfLine: typeof vscode.EndOfLine;
|
||||
commands: typeof vscode.commands;
|
||||
window: typeof vscode.window;
|
||||
workspace: typeof vscode.workspace;
|
||||
@@ -103,8 +104,8 @@ export class ExtHostAPIImplementation {
|
||||
this.version = contextService.getConfiguration().env.version;
|
||||
this.Uri = URI;
|
||||
this.Location = extHostTypes.Location;
|
||||
this.Diagnostic = <any> extHostTypes.Diagnostic;
|
||||
this.DiagnosticSeverity = <any>extHostTypes.DiagnosticSeverity;
|
||||
this.Diagnostic = extHostTypes.Diagnostic;
|
||||
this.DiagnosticSeverity = extHostTypes.DiagnosticSeverity;
|
||||
this.EventEmitter = Emitter;
|
||||
this.Disposable = extHostTypes.Disposable;
|
||||
this.TextEdit = extHostTypes.TextEdit;
|
||||
@@ -114,22 +115,23 @@ export class ExtHostAPIImplementation {
|
||||
this.Selection = extHostTypes.Selection;
|
||||
this.CancellationTokenSource = CancellationTokenSource;
|
||||
this.Hover = extHostTypes.Hover;
|
||||
this.SymbolKind = <any>extHostTypes.SymbolKind;
|
||||
this.SymbolInformation = <any>extHostTypes.SymbolInformation;
|
||||
this.DocumentHighlightKind = <any>extHostTypes.DocumentHighlightKind;
|
||||
this.DocumentHighlight = <any>extHostTypes.DocumentHighlight;
|
||||
this.SymbolKind = extHostTypes.SymbolKind;
|
||||
this.SymbolInformation = extHostTypes.SymbolInformation;
|
||||
this.DocumentHighlightKind = extHostTypes.DocumentHighlightKind;
|
||||
this.DocumentHighlight = extHostTypes.DocumentHighlight;
|
||||
this.CodeLens = extHostTypes.CodeLens;
|
||||
this.ParameterInformation = extHostTypes.ParameterInformation;
|
||||
this.SignatureInformation = extHostTypes.SignatureInformation;
|
||||
this.SignatureHelp = extHostTypes.SignatureHelp;
|
||||
this.CompletionItem = <any>extHostTypes.CompletionItem;
|
||||
this.CompletionItemKind = <any>extHostTypes.CompletionItemKind;
|
||||
this.CompletionItem = extHostTypes.CompletionItem;
|
||||
this.CompletionItemKind = extHostTypes.CompletionItemKind;
|
||||
this.CompletionList = extHostTypes.CompletionList;
|
||||
this.ViewColumn = <any>extHostTypes.ViewColumn;
|
||||
this.StatusBarAlignment = <any>extHostTypes.StatusBarAlignment;
|
||||
this.IndentAction = <any>Modes.IndentAction;
|
||||
this.OverviewRulerLane = <any>EditorCommon.OverviewRulerLane;
|
||||
this.TextEditorRevealType = <any>TextEditorRevealType;
|
||||
this.ViewColumn = extHostTypes.ViewColumn;
|
||||
this.StatusBarAlignment = extHostTypes.StatusBarAlignment;
|
||||
this.IndentAction = Modes.IndentAction;
|
||||
this.OverviewRulerLane = EditorCommon.OverviewRulerLane;
|
||||
this.TextEditorRevealType = TextEditorRevealType;
|
||||
this.EndOfLine = extHostTypes.EndOfLine;
|
||||
|
||||
errors.setUnexpectedErrorHandler((err) => {
|
||||
this._proxy.onUnexpectedExtHostError(errors.transformErrorForSerialization(err));
|
||||
|
||||
@@ -10,7 +10,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
|
||||
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 {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
|
||||
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
|
||||
@@ -196,22 +196,26 @@ export interface ITextEditOperation {
|
||||
export interface IEditData {
|
||||
documentVersionId: number;
|
||||
edits: ITextEditOperation[];
|
||||
setEndOfLine: EndOfLine;
|
||||
}
|
||||
|
||||
export class TextEditorEdit {
|
||||
|
||||
private _documentVersionId: number;
|
||||
private _collectedEdits: ITextEditOperation[];
|
||||
private _setEndOfLine: EndOfLine;
|
||||
|
||||
constructor(document: vscode.TextDocument) {
|
||||
this._documentVersionId = document.version;
|
||||
this._collectedEdits = [];
|
||||
this._setEndOfLine = 0;
|
||||
}
|
||||
|
||||
finalize(): IEditData {
|
||||
return {
|
||||
documentVersionId: this._documentVersionId,
|
||||
edits: this._collectedEdits
|
||||
edits: this._collectedEdits,
|
||||
setEndOfLine: this._setEndOfLine
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,6 +264,14 @@ export class TextEditorEdit {
|
||||
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) {
|
||||
@@ -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
|
||||
@@ -705,11 +717,11 @@ export class MainThreadEditors {
|
||||
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]) {
|
||||
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 {
|
||||
|
||||
@@ -688,3 +688,8 @@ export enum StatusBarAlignment {
|
||||
Left = 1,
|
||||
Right = 2
|
||||
}
|
||||
|
||||
export enum EndOfLine {
|
||||
LF = 1,
|
||||
CRLF = 2
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
|
||||
import {RunOnceScheduler} from 'vs/base/common/async';
|
||||
import {Range} from 'vs/editor/common/core/range';
|
||||
import {Selection} from 'vs/editor/common/core/selection';
|
||||
import {EndOfLine} from 'vs/workbench/api/node/extHostTypes';
|
||||
|
||||
export interface ITextEditorConfigurationUpdate {
|
||||
tabSize?: number | string;
|
||||
@@ -262,7 +263,7 @@ export class MainThreadTextEditor {
|
||||
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) {
|
||||
console.warn('Model has changed in the meantime!');
|
||||
// throw new Error('Model has changed in the meantime!');
|
||||
@@ -271,6 +272,12 @@ export class MainThreadTextEditor {
|
||||
}
|
||||
|
||||
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 => {
|
||||
return {
|
||||
identifier: null,
|
||||
|
||||
Reference in New Issue
Block a user