From 3988851e9e829260d0a94307c78a5c53890a85ef Mon Sep 17 00:00:00 2001 From: Michael Nilsson Date: Tue, 19 Sep 2023 21:51:46 +0200 Subject: [PATCH] Make import relative instead of absolute. Cant make it work after building otherwise: https://github.com/microsoft/TypeScript/issues/15479 --- .npmignore | 1 + README.md | 2 +- {src => example}/example.ts | 18 +++---- package.json | 2 +- src/vs/base/common/assert.ts | 2 +- src/vs/base/common/diff/diff.ts | 6 +-- src/vs/base/common/hash.ts | 2 +- src/vs/base/common/strings.ts | 2 +- src/vs/base/test/common/diff/diff.test.ts | 2 +- src/vs/editor/common/core/lineRange.ts | 6 +-- src/vs/editor/common/core/offsetRange.ts | 2 +- src/vs/editor/common/core/range.ts | 2 +- .../common/diff/advancedLinesDiffComputer.ts | 28 +++++------ .../common/diff/algorithms/diffAlgorithm.ts | 4 +- .../algorithms/dynamicProgrammingDiffing.ts | 6 +-- .../diff/algorithms/joinSequenceDiffs.ts | 6 +-- .../diff/algorithms/myersDiffAlgorithm.ts | 4 +- .../common/diff/legacyLinesDiffComputer.ts | 14 +++--- .../editor/common/diff/linesDiffComputer.ts | 5 +- tsconfig.build.json | 6 ++- tsconfig.json | 50 +++++++++---------- 21 files changed, 86 insertions(+), 84 deletions(-) rename {src => example}/example.ts (65%) diff --git a/.npmignore b/.npmignore index bb31bc1..9d4619e 100644 --- a/.npmignore +++ b/.npmignore @@ -4,4 +4,5 @@ tsconfig.json tsconfig.build.json .editorconfig knip.json +example node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index 863671f..6bbe71b 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ Steps for updating diff algorithm: * Verify with `npm run build` that all code is self-contained. * Verify with `npm run knip` that there are no unused files or exports. * Run `npm test` to run all the tests. -* Update [src/example.ts] on any API changes. +* Update [example/example.ts] on any API changes. * Run `npm run example` and update this README with example usage code and output. * Include VS Code version and commit hash in commit message. diff --git a/src/example.ts b/example/example.ts similarity index 65% rename from src/example.ts rename to example/example.ts index 42773e7..0013c56 100644 --- a/src/example.ts +++ b/example/example.ts @@ -1,13 +1,13 @@ -import { AdvancedLinesDiffComputer, DiffComputer, IDiffComputerOpts, ILineChange, ILinesDiffComputerOptions } from 'vscode-diff'; +import { AdvancedLinesDiffComputer, DiffComputer, IDiffComputerOpts, ILineChange, ILinesDiffComputerOptions } from '../dist'; let originalLines: string[] = ["hello", "original", "world"]; let modifiedLines: string[] = ["hello", "modified", "world", "foobar"]; let options: IDiffComputerOpts = { - shouldPostProcessCharChanges: true, - shouldIgnoreTrimWhitespace: true, - shouldMakePrettyDiff: true, - shouldComputeCharChanges: true, - maxComputationTime: 0 // time in milliseconds, 0 => no computation limit. + shouldPostProcessCharChanges: true, + shouldIgnoreTrimWhitespace: true, + shouldMakePrettyDiff: true, + shouldComputeCharChanges: true, + maxComputationTime: 0 // time in milliseconds, 0 => no computation limit. } let diffComputer = new DiffComputer(originalLines, modifiedLines, options); let lineChanges: ILineChange[] = diffComputer.computeDiff().changes; @@ -16,9 +16,9 @@ console.log(JSON.stringify(lineChanges, null, 2)); let advOptions: ILinesDiffComputerOptions = { - ignoreTrimWhitespace: true, - computeMoves: true, - maxComputationTimeMs: 0 + ignoreTrimWhitespace: true, + computeMoves: true, + maxComputationTimeMs: 0 } let advDiffComputer = new AdvancedLinesDiffComputer() let advLineChanges = advDiffComputer.computeDiff(originalLines, modifiedLines, advOptions).changes; diff --git a/package.json b/package.json index 9244dea..314ebaf 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "watch": "tsc --watch", "build": "tsc --project tsconfig.build.json", "knip": "knip", - "example": "ts-node src/example.ts" + "example": "yarn build && ts-node ./example/example.ts" }, "keywords": [ "diff", diff --git a/src/vs/base/common/assert.ts b/src/vs/base/common/assert.ts index 4264da5..fb1fd1a 100644 --- a/src/vs/base/common/assert.ts +++ b/src/vs/base/common/assert.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { BugIndicatingError, onUnexpectedError } from 'vs/base/common/errors'; +import { BugIndicatingError, onUnexpectedError } from './errors'; /** diff --git a/src/vs/base/common/diff/diff.ts b/src/vs/base/common/diff/diff.ts index 0a938b6..2402414 100644 --- a/src/vs/base/common/diff/diff.ts +++ b/src/vs/base/common/diff/diff.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DiffChange } from 'vs/base/common/diff/diffChange'; -import { stringHash } from 'vs/base/common/hash'; -import { Constants } from 'vs/base/common/uint'; +import { stringHash } from '../hash'; +import { Constants } from '../uint'; +import { DiffChange } from './diffChange'; export class StringDiffSequence implements ISequence { diff --git a/src/vs/base/common/hash.ts b/src/vs/base/common/hash.ts index b1ebac7..2f9ff51 100644 --- a/src/vs/base/common/hash.ts +++ b/src/vs/base/common/hash.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as strings from 'vs/base/common/strings'; +import * as strings from './strings'; export function doHash(obj: any, hashVal: number): number { switch (typeof obj) { diff --git a/src/vs/base/common/strings.ts b/src/vs/base/common/strings.ts index 353af4b..9558414 100644 --- a/src/vs/base/common/strings.ts +++ b/src/vs/base/common/strings.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CharCode } from 'vs/base/common/charCode'; +import { CharCode } from './charCode'; /** * Returns first index of the string that is not whitespace. diff --git a/src/vs/base/test/common/diff/diff.test.ts b/src/vs/base/test/common/diff/diff.test.ts index 0ccb5b5..71a56b1 100644 --- a/src/vs/base/test/common/diff/diff.test.ts +++ b/src/vs/base/test/common/diff/diff.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { IDiffChange, LcsDiff, StringDiffSequence } from 'vs/base/common/diff/diff'; +import { IDiffChange, LcsDiff, StringDiffSequence } from '../../../common/diff/diff'; function createArray(length: number, value: T): T[] { const r: T[] = []; diff --git a/src/vs/editor/common/core/lineRange.ts b/src/vs/editor/common/core/lineRange.ts index 70acb04..f33b878 100644 --- a/src/vs/editor/common/core/lineRange.ts +++ b/src/vs/editor/common/core/lineRange.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { BugIndicatingError } from 'vs/base/common/errors'; -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; -import { Range } from 'vs/editor/common/core/range'; +import { BugIndicatingError } from '../../../base/common/errors'; +import { OffsetRange } from './offsetRange'; +import { Range } from './range'; /** * A range of lines (1-based). diff --git a/src/vs/editor/common/core/offsetRange.ts b/src/vs/editor/common/core/offsetRange.ts index 27e60bc..fa4c473 100644 --- a/src/vs/editor/common/core/offsetRange.ts +++ b/src/vs/editor/common/core/offsetRange.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { BugIndicatingError } from 'vs/base/common/errors'; +import { BugIndicatingError } from '../../../base/common/errors'; /** * A range of offsets (0-based). diff --git a/src/vs/editor/common/core/range.ts b/src/vs/editor/common/core/range.ts index 7239639..a312089 100644 --- a/src/vs/editor/common/core/range.ts +++ b/src/vs/editor/common/core/range.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IPosition, Position } from 'vs/editor/common/core/position'; +import { IPosition, Position } from './position'; /** * A range in the editor. This interface is suitable for serialization. diff --git a/src/vs/editor/common/diff/advancedLinesDiffComputer.ts b/src/vs/editor/common/diff/advancedLinesDiffComputer.ts index 55166f1..1917c2e 100644 --- a/src/vs/editor/common/diff/advancedLinesDiffComputer.ts +++ b/src/vs/editor/common/diff/advancedLinesDiffComputer.ts @@ -3,20 +3,20 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Comparator, CompareResult, compareBy, equals, findLastIndex, numberComparator, reverseOrder } from 'vs/base/common/arrays'; -import { assertFn, checkAdjacentItems } from 'vs/base/common/assert'; -import { CharCode } from 'vs/base/common/charCode'; -import { SetMap } from 'vs/base/common/collections'; -import { BugIndicatingError } from 'vs/base/common/errors'; -import { LineRange } from 'vs/editor/common/core/lineRange'; -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; -import { Position } from 'vs/editor/common/core/position'; -import { Range } from 'vs/editor/common/core/range'; -import { DateTimeout, ISequence, ITimeout, InfiniteTimeout, SequenceDiff } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; -import { DynamicProgrammingDiffing } from 'vs/editor/common/diff/algorithms/dynamicProgrammingDiffing'; -import { optimizeSequenceDiffs, removeRandomLineMatches, removeRandomMatches, smoothenSequenceDiffs } from 'vs/editor/common/diff/algorithms/joinSequenceDiffs'; -import { MyersDiffAlgorithm } from 'vs/editor/common/diff/algorithms/myersDiffAlgorithm'; -import { ILinesDiffComputer, ILinesDiffComputerOptions, LineRangeMapping, LinesDiff, MovedText, RangeMapping, SimpleLineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer'; +import { Comparator, CompareResult, compareBy, equals, findLastIndex, numberComparator, reverseOrder } from '../../../base/common/arrays'; +import { assertFn, checkAdjacentItems } from '../../../base/common/assert'; +import { CharCode } from '../../../base/common/charCode'; +import { SetMap } from '../../../base/common/collections'; +import { BugIndicatingError } from '../../../base/common/errors'; +import { LineRange } from '../core/lineRange'; +import { OffsetRange } from '../core/offsetRange'; +import { Position } from '../core/position'; +import { Range } from '../core/range'; +import { DateTimeout, ISequence, ITimeout, InfiniteTimeout, SequenceDiff } from '../diff/algorithms/diffAlgorithm'; +import { DynamicProgrammingDiffing } from '../diff/algorithms/dynamicProgrammingDiffing'; +import { optimizeSequenceDiffs, removeRandomLineMatches, removeRandomMatches, smoothenSequenceDiffs } from '../diff/algorithms/joinSequenceDiffs'; +import { MyersDiffAlgorithm } from '../diff/algorithms/myersDiffAlgorithm'; +import { ILinesDiffComputer, ILinesDiffComputerOptions, LineRangeMapping, LinesDiff, MovedText, RangeMapping, SimpleLineRangeMapping } from './linesDiffComputer'; export class AdvancedLinesDiffComputer implements ILinesDiffComputer { private readonly dynamicProgrammingDiffing = new DynamicProgrammingDiffing(); diff --git a/src/vs/editor/common/diff/algorithms/diffAlgorithm.ts b/src/vs/editor/common/diff/algorithms/diffAlgorithm.ts index ce23a58..274d7be 100644 --- a/src/vs/editor/common/diff/algorithms/diffAlgorithm.ts +++ b/src/vs/editor/common/diff/algorithms/diffAlgorithm.ts @@ -3,8 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { BugIndicatingError } from 'vs/base/common/errors'; -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; +import { BugIndicatingError } from '../../../../base/common/errors'; +import { OffsetRange } from '../../core/offsetRange'; /** * Represents a synchronous diff algorithm. Should be executed in a worker. diff --git a/src/vs/editor/common/diff/algorithms/dynamicProgrammingDiffing.ts b/src/vs/editor/common/diff/algorithms/dynamicProgrammingDiffing.ts index 2212ebe..5773e65 100644 --- a/src/vs/editor/common/diff/algorithms/dynamicProgrammingDiffing.ts +++ b/src/vs/editor/common/diff/algorithms/dynamicProgrammingDiffing.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; -import { IDiffAlgorithm, SequenceDiff, ISequence, ITimeout, InfiniteTimeout, DiffAlgorithmResult } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; -import { Array2D } from 'vs/editor/common/diff/algorithms/utils'; +import { OffsetRange } from '../../core/offsetRange'; +import { DiffAlgorithmResult, IDiffAlgorithm, ISequence, ITimeout, InfiniteTimeout, SequenceDiff } from './diffAlgorithm'; +import { Array2D } from './utils'; /** * A O(MN) diffing algorithm that supports a score function. diff --git a/src/vs/editor/common/diff/algorithms/joinSequenceDiffs.ts b/src/vs/editor/common/diff/algorithms/joinSequenceDiffs.ts index cef14d4..a2741eb 100644 --- a/src/vs/editor/common/diff/algorithms/joinSequenceDiffs.ts +++ b/src/vs/editor/common/diff/algorithms/joinSequenceDiffs.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; -import { ISequence, SequenceDiff } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; -import { LineSequence, LinesSliceCharSequence } from 'vs/editor/common/diff/advancedLinesDiffComputer'; +import { OffsetRange } from '../../core/offsetRange'; +import { LineSequence, LinesSliceCharSequence } from '../advancedLinesDiffComputer'; +import { ISequence, SequenceDiff } from '../algorithms/diffAlgorithm'; export function optimizeSequenceDiffs(sequence1: ISequence, sequence2: ISequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] { let result = sequenceDiffs; diff --git a/src/vs/editor/common/diff/algorithms/myersDiffAlgorithm.ts b/src/vs/editor/common/diff/algorithms/myersDiffAlgorithm.ts index 049c5ff..410998c 100644 --- a/src/vs/editor/common/diff/algorithms/myersDiffAlgorithm.ts +++ b/src/vs/editor/common/diff/algorithms/myersDiffAlgorithm.ts @@ -3,8 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { OffsetRange } from 'vs/editor/common/core/offsetRange'; -import { DiffAlgorithmResult, IDiffAlgorithm, ISequence, ITimeout, InfiniteTimeout, SequenceDiff } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; +import { OffsetRange } from '../../core/offsetRange'; +import { DiffAlgorithmResult, IDiffAlgorithm, ISequence, ITimeout, InfiniteTimeout, SequenceDiff } from '../algorithms/diffAlgorithm'; /** * An O(ND) diff algorithm that has a quadratic space worst-case complexity. diff --git a/src/vs/editor/common/diff/legacyLinesDiffComputer.ts b/src/vs/editor/common/diff/legacyLinesDiffComputer.ts index 5ea6524..d5b3d52 100644 --- a/src/vs/editor/common/diff/legacyLinesDiffComputer.ts +++ b/src/vs/editor/common/diff/legacyLinesDiffComputer.ts @@ -3,13 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CharCode } from 'vs/base/common/charCode'; -import { IDiffChange, ISequence, LcsDiff, IDiffResult } from 'vs/base/common/diff/diff'; -import { ILinesDiffComputer, ILinesDiffComputerOptions, RangeMapping, LineRangeMapping, LinesDiff } from 'vs/editor/common/diff/linesDiffComputer'; -import * as strings from 'vs/base/common/strings'; -import { Range } from 'vs/editor/common/core/range'; -import { assertFn, checkAdjacentItems } from 'vs/base/common/assert'; -import { LineRange } from 'vs/editor/common/core/lineRange'; +import { assertFn, checkAdjacentItems } from "../../../base/common/assert"; +import { CharCode } from "../../../base/common/charCode"; +import { IDiffChange, IDiffResult, ISequence, LcsDiff } from "../../../base/common/diff/diff"; +import * as strings from "../../../base/common/strings"; +import { LineRange } from "../core/lineRange"; +import { Range } from "../core/range"; +import { ILinesDiffComputer, ILinesDiffComputerOptions, LineRangeMapping, LinesDiff, RangeMapping } from "./linesDiffComputer"; const MINIMUM_MATCHING_CHARACTER_LENGTH = 3; diff --git a/src/vs/editor/common/diff/linesDiffComputer.ts b/src/vs/editor/common/diff/linesDiffComputer.ts index d10888c..f1949f6 100644 --- a/src/vs/editor/common/diff/linesDiffComputer.ts +++ b/src/vs/editor/common/diff/linesDiffComputer.ts @@ -3,8 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { LineRange } from 'vs/editor/common/core/lineRange'; -import { Range } from 'vs/editor/common/core/range'; +import { LineRange } from "../core/lineRange"; +import { Range } from "../core/range"; + export interface ILinesDiffComputer { computeDiff(originalLines: string[], modifiedLines: string[], options: ILinesDiffComputerOptions): LinesDiff; diff --git a/tsconfig.build.json b/tsconfig.build.json index b853121..266dc82 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,4 +1,6 @@ { "extends": "./tsconfig.json", - "exclude": ["src/**/*.test.ts", "src/example.ts"] -} + "exclude": [ + "src/**/*.test.ts" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index dae3760..55ddf2e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,25 @@ { - "compilerOptions": { - "target": "es2021", - "lib": [ - "es2021", - "DOM" - ], - "module": "commonjs", - "declaration": true, - "outDir": "./dist", - "strict": true, - "useUnknownInCatchVariables": false, - "baseUrl": "./src", - "paths": { - "vscode-diff": ["./"], - } - }, - "ts-node": { - "require": ["tsconfig-paths/register"] - }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules" - ] -} + "compilerOptions": { + "target": "es2021", + "lib": [ + "es2021", + "DOM" + ], + "module": "commonjs", + "declaration": true, + "outDir": "./dist", + "strict": true, + "useUnknownInCatchVariables": false, + }, + "ts-node": { + "require": [ + "tsconfig-paths/register" + ] + }, + "include": [ + "src/**/*", + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file