diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 03dc91cd19e..660e6de1dfa 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -154,4 +154,13 @@ declare module 'vscode' { export function getResourceFromURI(uri: Uri): SCMResource | SCMResourceGroup | undefined; export function registerSCMProvider(id: string, provider: SCMProvider): Disposable; } + + export interface LineChange { + readonly originalStartLineNumber: number; + readonly originalEndLineNumber: number; + readonly modifiedStartLineNumber: number; + readonly modifiedEndLineNumber: number; + } + + export function computeDiff(oneDocument: TextDocument, otherDocument: TextDocument): Thenable; } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 4ba4cd1e85d..0d69b51aad9 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -32,6 +32,7 @@ import { ExtHostEditors } from 'vs/workbench/api/node/extHostEditors'; import { ExtHostLanguages } from 'vs/workbench/api/node/extHostLanguages'; import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFeatures'; import { ExtHostApiCommands } from 'vs/workbench/api/node/extHostApiCommands'; +import { computeDiff } from 'vs/workbench/api/node/extHostFunctions'; import * as extHostTypes from 'vs/workbench/api/node/extHostTypes'; import URI from 'vs/base/common/uri'; import Severity from 'vs/base/common/severity'; @@ -490,6 +491,8 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ Uri: URI, ViewColumn: extHostTypes.ViewColumn, WorkspaceEdit: extHostTypes.WorkspaceEdit, + // functions + computeDiff }; }; } diff --git a/src/vs/workbench/api/node/extHostFunctions.ts b/src/vs/workbench/api/node/extHostFunctions.ts new file mode 100644 index 00000000000..cb21a24ea0e --- /dev/null +++ b/src/vs/workbench/api/node/extHostFunctions.ts @@ -0,0 +1,30 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import * as vscode from 'vscode'; +import { toThenable } from 'vs/base/common/async'; +import { DiffComputer } from 'vs/editor/common/diff/diffComputer'; + +function getTextDocumentLines(document: vscode.TextDocument): string[] { + const result = []; + for (let i = 0; i < document.lineCount; i++) { + result.push(document.lineAt(i).text); + } + return result; +} + +export function computeDiff(oneDocument: vscode.TextDocument, otherDocument: vscode.TextDocument): Thenable { + const oneLines = getTextDocumentLines(oneDocument); + const otherLines = getTextDocumentLines(otherDocument); + const computer = new DiffComputer(oneLines, otherLines, { + shouldPostProcessCharChanges: false, + shouldIgnoreTrimWhitespace: false, // options? + shouldConsiderTrimWhitespaceInEmptyCase: false + }); + + return toThenable(computer.computeDiff()); +} \ No newline at end of file