提交 307fda26 编写于 作者: A Alex Dima

Clarify extension host protocol

上级 922389d7
......@@ -5,9 +5,32 @@
'use strict';
import URI from 'vs/base/common/uri';
import { IModelContentChangedEvent2, IPosition, IRange } from 'vs/editor/common/editorCommon';
import { IPosition, IRange } from 'vs/editor/common/editorCommon';
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
export interface IModelChangedData {
/**
* The range that got replaced.
*/
readonly range: IRange;
/**
* The length of the range that got replaced.
*/
readonly rangeLength: number;
/**
* The new text for the range.
*/
readonly text: string;
/**
* The (new) end-of-line character.
*/
readonly eol: string;
/**
* The new version id the model has transitioned to.
*/
readonly versionId: number;
}
export class MirrorModel2 {
protected _uri: URI;
......@@ -35,7 +58,7 @@ export class MirrorModel2 {
return this._lines.join(this._eol);
}
onEvents(events: IModelContentChangedEvent2[]): void {
onEvents(events: IModelChangedData[]): void {
let newEOL: string = null;
for (let i = 0, len = events.length; i < len; i++) {
let e = events[i];
......
......@@ -38,6 +38,7 @@ import { IApplyEditsOptions, IUndoStopOptions, TextEditorRevealType, ITextEditor
import { InternalTreeExplorerNodeContent } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
import { TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
import { IModelChangedData } from 'vs/editor/common/model/mirrorModel2';
export interface IEnvironment {
enableProposedApi: boolean;
......@@ -312,7 +313,7 @@ export abstract class ExtHostDocumentsShape {
$acceptModelSaved(strURL: string): void { throw ni(); }
$acceptModelDirty(strURL: string): void { throw ni(); }
$acceptModelReverted(strURL: string): void { throw ni(); }
$acceptModelChanged(strURL: string, events: editorCommon.IModelContentChangedEvent2[], isDirty: boolean): void { throw ni(); }
$acceptModelChanged(strURL: string, events: IModelChangedData[], isDirty: boolean): void { throw ni(); }
}
export abstract class ExtHostDocumentSaveParticipantShape {
......
......@@ -19,6 +19,7 @@ import { TextSource } from 'vs/editor/common/model/textSource';
import { MainContext, MainThreadDocumentsShape, ExtHostDocumentsShape } from './extHost.protocol';
import { ExtHostDocumentData, setWordDefinitionFor } from './extHostDocumentData';
import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors';
import { IModelChangedData } from 'vs/editor/common/model/mirrorModel2';
export class ExtHostDocuments extends ExtHostDocumentsShape {
......@@ -184,7 +185,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
document._acceptIsDirty(false);
}
public $acceptModelChanged(strURL: string, events: editorCommon.IModelContentChangedEvent2[], isDirty: boolean): void {
public $acceptModelChanged(strURL: string, events: IModelChangedData[], isDirty: boolean): void {
let data = this._documentsAndEditors.getDocument(strURL);
data._acceptIsDirty(isDirty);
data.onEvents(events);
......
......@@ -10,9 +10,9 @@ import URI from 'vs/base/common/uri';
import { ExtHostDocumentData } from 'vs/workbench/api/node/extHostDocumentData';
import { Position } from 'vs/workbench/api/node/extHostTypes';
import { Range as CodeEditorRange } from 'vs/editor/common/core/range';
import * as EditorCommon from 'vs/editor/common/editorCommon';
import { MainThreadDocumentsShape } from 'vs/workbench/api/node/extHost.protocol';
import { TPromise } from 'vs/base/common/winjs.base';
import { IModelChangedData } from 'vs/editor/common/model/mirrorModel2';
suite('ExtHostDocumentData', () => {
......@@ -101,8 +101,6 @@ suite('ExtHostDocumentData', () => {
range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 },
text: '\t ',
eol: undefined,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
}]);
......@@ -157,8 +155,6 @@ suite('ExtHostDocumentData', () => {
range: { startLineNumber: 1, startColumn: 3, endLineNumber: 1, endColumn: 6 },
text: '',
eol: undefined,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
}]);
......@@ -174,8 +170,6 @@ suite('ExtHostDocumentData', () => {
range: { startLineNumber: 1, startColumn: 3, endLineNumber: 1, endColumn: 6 },
text: 'is could be',
eol: undefined,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
}]);
......@@ -191,8 +185,6 @@ suite('ExtHostDocumentData', () => {
range: { startLineNumber: 1, startColumn: 3, endLineNumber: 1, endColumn: 6 },
text: 'is could be\na line with number',
eol: undefined,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
}]);
......@@ -211,8 +203,6 @@ suite('ExtHostDocumentData', () => {
range: { startLineNumber: 1, startColumn: 3, endLineNumber: 2, endColumn: 6 },
text: '',
eol: undefined,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
}]);
......@@ -311,19 +301,17 @@ suite('ExtHostDocumentData updates line mapping', () => {
}
}
function createChangeEvent(range: CodeEditorRange, text: string, eol?: string): EditorCommon.IModelContentChangedEvent2 {
function createChangeEvent(range: CodeEditorRange, text: string, eol?: string): IModelChangedData {
return {
range: range,
text: text,
eol: eol,
isRedoing: undefined,
isUndoing: undefined,
versionId: undefined,
rangeLength: undefined,
};
}
function testLineMappingDirectionAfterEvents(lines: string[], eol: string, direction: AssertDocumentLineMappingDirection, events: EditorCommon.IModelContentChangedEvent2[]): void {
function testLineMappingDirectionAfterEvents(lines: string[], eol: string, direction: AssertDocumentLineMappingDirection, events: IModelChangedData[]): void {
let myDocument = new ExtHostDocumentData(undefined, URI.file(''), lines.slice(0), eol, 'text', 1, false);
assertDocumentLineMapping(myDocument, direction);
......@@ -331,7 +319,7 @@ suite('ExtHostDocumentData updates line mapping', () => {
assertDocumentLineMapping(myDocument, direction);
}
function testLineMappingAfterEvents(lines: string[], events: EditorCommon.IModelContentChangedEvent2[]): void {
function testLineMappingAfterEvents(lines: string[], events: IModelChangedData[]): void {
testLineMappingDirectionAfterEvents(lines, '\n', AssertDocumentLineMappingDirection.PositionToOffset, events);
testLineMappingDirectionAfterEvents(lines, '\n', AssertDocumentLineMappingDirection.OffsetToPosition, events);
......
......@@ -289,7 +289,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
versionId: 2,
range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 },
text: 'bar',
rangeLength: undefined, eol: undefined, isRedoing: undefined, isUndoing: undefined,
rangeLength: undefined, eol: undefined
}], true);
e.waitUntil(TPromise.as([TextEdit.insert(new Position(0, 0), 'bar')]));
......@@ -314,7 +314,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
range,
text: newText,
versionId: documents.getDocumentData(resource).version + 1,
rangeLength: undefined, eol: undefined, isRedoing: undefined, isUndoing: undefined,
rangeLength: undefined, eol: undefined
}], true);
}
return TPromise.as(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册