Skip to content

Update copied VS sources #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions script/setup/copySources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ async function doIt(filepaths: string[]) {
newSource = newSource.slice(0, edit.pos + 1) + edit.newText + newSource.slice(edit.end + 1);
}

if (filepath.endsWith('src/vs/nls.ts')) {
newSource = 'declare var document: any;\n\n' + newSource;
}
newSource = '//!!! DO NOT modify, this file was COPIED from \'microsoft/vscode\'\n\n' + newSource;

seen.set(filepath, {
Expand Down Expand Up @@ -137,6 +134,7 @@ async function doIt(filepaths: string[]) {
'vs/base/common/cancellation.ts',
'vs/base/common/charCode.ts',
'vs/base/common/errors.ts',
'vs/base/common/errorMessage.ts',
'vs/base/common/event.ts',
'vs/base/common/functional.ts',
'vs/base/common/glob.ts',
Expand All @@ -149,6 +147,7 @@ async function doIt(filepaths: string[]) {
'vs/base/common/numbers.ts',
'vs/base/common/objects.ts',
'vs/base/common/resources.ts',
'vs/base/common/sseParser.ts',
'vs/base/common/strings.ts',
'vs/base/common/ternarySearchTree.ts',
'vs/base/common/themables.ts',
Expand All @@ -164,6 +163,9 @@ async function doIt(filepaths: string[]) {

'vs/platform/instantiation/common/instantiationService.ts',

'vs/editor/common/core/edits/lineEdit.ts',
'vs/editor/common/core/text/positionToOffset.ts',

// SPECIAL IMPLICIT DEPENDENCIES
'typings/vscode-globals-nls.d.ts',
'typings/vscode-globals-product.d.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const debugContextKey = 'github.copilot.chat.debug';
export class ContextKeysContribution extends Disposable {

private _needsOfflineCheck = false;
private _scheduledOfflineCheck: NodeJS.Timeout | undefined;
private _scheduledOfflineCheck: TimeoutHandle | undefined;
private _showLogView = false;

constructor(
Expand Down
3 changes: 3 additions & 0 deletions src/extension/inlineEdits/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import { IDisposable, toDisposable } from '../../../util/vs/base/common/lifecycle';
import { ensureDependenciesAreSet } from '../../../util/vs/editor/common/core/text/positionToOffset';

export function createTimeout(ms: number, cb: () => void): IDisposable {
const t = setTimeout(cb, ms);
return toDisposable(() => clearTimeout(t));
}

ensureDependenciesAreSet();
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export class NextEditProviderTelemetryBuilder extends Disposable {

export class TelemetrySender implements IDisposable {

private readonly _map = new Map<INextEditResult, { builder: NextEditProviderTelemetryBuilder; timeout: NodeJS.Timeout }>();
private readonly _map = new Map<INextEditResult, { builder: NextEditProviderTelemetryBuilder; timeout: Timeout }>();

constructor(
@ITelemetryService private readonly _telemetryService: ITelemetryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ServerPoweredInlineEditProvider implements IStatelessNextEditProvid
const edits = response.edits.map(e => LineReplacement.deserialize(e));
const sortingPermutation = Permutation.createSortPermutation(edits, (a, b) => a.lineRange.startLineNumber - b.lineRange.startLineNumber);
const lineEdit = new LineEdit(sortingPermutation.apply(edits));
lineEdit.edits.forEach(edit => pushEdit(Result.ok({ edit })));
lineEdit.replacements.forEach(edit => pushEdit(Result.ok({ edit })));
pushEdit(Result.error(new NoNextEditReason.NoSuggestions(request.documentBeforeEdits, undefined)));
return StatelessNextEditResult.streaming(telemetryBuilder);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FooBar {
`);

const lineEdit = RootedEdit.toLineEdit(await computeDiff(doc1, doc2));
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.edits[0], 'typescript', doc1.getLines())).toBe(true);
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.replacements[0], 'typescript', doc1.getLines())).toBe(true);
});


Expand All @@ -69,7 +69,7 @@ class FooBar {
`);

const lineEdit = RootedEdit.toLineEdit(await computeDiff(doc1, doc2));
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.edits[0], 'typescript', doc1.getLines())).toBe(true);
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.replacements[0], 'typescript', doc1.getLines())).toBe(true);
});

test('ImportChange', async () => {
Expand All @@ -88,7 +88,7 @@ class FooBar {
`);

const lineEdit = RootedEdit.toLineEdit(await computeDiff(doc1, doc2));
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.edits[0], 'typescript', doc1.getLines())).toBe(true);
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.replacements[0], 'typescript', doc1.getLines())).toBe(true);
});


Expand All @@ -109,6 +109,6 @@ class FooBar {
`);

const lineEdit = RootedEdit.toLineEdit(await computeDiff(doc1, doc2));
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.edits[0], 'typescript', doc1.getLines())).toBe(false);
expect(IgnoreImportChangesAspect.isImportChange(lineEdit.replacements[0], 'typescript', doc1.getLines())).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('NextEditProvider Caching', () => {
)
]
);
lineEdit.edits.forEach(edit => pushEdit(Result.ok({ edit })));
lineEdit.replacements.forEach(edit => pushEdit(Result.ok({ edit })));
pushEdit(Result.error(new NoNextEditReason.NoSuggestions(request.documentBeforeEdits, undefined)));
return StatelessNextEditResult.streaming(telemetryBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LogContextRecorder extends Disposable {
public readonly logFilePath: string;
private readonly _impl: Promise<LogContextRecorderImpl>;

private readonly _shownSuggestions: DisposableMap<number, { timeout: NodeJS.Timeout; dispose: () => void }>;
private readonly _shownSuggestions: DisposableMap<number, { timeout: Timeout; dispose: () => void }>;

constructor(
public readonly recordingDirPath: string,
Expand Down
6 changes: 3 additions & 3 deletions src/extension/inlineEdits/vscode-node/inlineEditModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class LastChange extends Disposable {
public lastEditedTimestamp: number;
public lineNumberTriggers: Map<number /* lineNumber */, number /* timestamp */>;

private _timeout: NodeJS.Timeout | undefined;
public set timeout(value: NodeJS.Timeout | undefined) {
private _timeout: Timeout | undefined;
public set timeout(value: Timeout | undefined) {
if (value !== undefined) {
// TODO: we can end up collecting multiple timeouts, but also they could be cleared as debouncing happens
this._register(toDisposable(() => clearTimeout(value)));
}
this._timeout = value;
}
public get timeout(): NodeJS.Timeout | undefined {
public get timeout(): Timeout | undefined {
return this._timeout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { OffsetRange } from '../../../../util/vs/editor/common/core/ranges/offse
import { StringText } from '../../../../util/vs/editor/common/core/text/abstractText';
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
import { toInternalTextEdit } from '../utils/translations';
import { assertStoreNotDisposed } from '../../../../util/common/lifecycle';

export class VSCodeWorkspace extends ObservableWorkspace implements IDisposable {
private readonly _openDocuments = observableValue<readonly IVSCodeObservableDocument[], { added: readonly IVSCodeObservableDocument[]; removed: readonly IVSCodeObservableDocument[] }>(this, []);
Expand Down Expand Up @@ -344,7 +345,7 @@ export class VSCodeWorkspace extends ObservableWorkspace implements IDisposable
* Returns undefined for documents that are not tracked (e.g. filtered out).
*/
public getDocumentByTextDocument(doc: TextDocument, reader?: IReader): IVSCodeObservableDocument | undefined {
this._store.assertNotDisposed();
assertStoreNotDisposed(this._store);

const internalDoc = this._getInternalDocument(doc.uri, reader);
if (!internalDoc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TextLengthOfSubstr, TextLengthSum } from '../../../../../util/common/textLength';
import { Lazy } from '../../../../../util/vs/base/common/lazy';
import { StringEdit, StringReplacement } from '../../../../../util/vs/editor/common/core/edits/stringEdit';
import { OffsetRange } from '../../../../../util/vs/editor/common/core/ranges/offsetRange';
Expand Down Expand Up @@ -99,7 +100,7 @@ export class OriginalStringFragment extends StringFragment {
return null;
}

private readonly _textLength = new Lazy(() => TextLength.ofSubstr(this.originalText, this.range));
private readonly _textLength = new Lazy(() => TextLengthOfSubstr(this.originalText, this.range));

get textLength() { return this._textLength.value; }
}
Expand Down Expand Up @@ -127,7 +128,7 @@ export class ConcatenatedStringFragment extends StringFragment {
return this.fragments.map(f => f.text).join('');
}

private readonly _textLength = new Lazy(() => TextLength.sum(this.fragments, f => f.textLength));
private readonly _textLength = new Lazy(() => TextLengthSum(this.fragments, f => f.textLength));

get textLength() { return this._textLength.value; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import { AbstractDocument } from '../../../../../platform/editing/common/abstractText';
import { OverlayNode } from '../../../../../platform/parser/node/nodes';
import { min } from '../../../../../util/common/arrays';
import { TextLengthSum } from '../../../../../util/common/textLength';
import { compareBy, groupAdjacentBy, numberComparator, sumBy } from '../../../../../util/vs/base/common/arrays';
import { CachedFunction } from '../../../../../util/vs/base/common/cache';
import { StringEdit, StringReplacement } from '../../../../../util/vs/editor/common/core/edits/stringEdit';
import { Position } from '../../../../../util/vs/editor/common/core/position';
import { OffsetRange } from '../../../../../util/vs/editor/common/core/ranges/offsetRange';
import { PositionOffsetTransformer } from '../../../../../util/vs/editor/common/core/text/positionToOffset';
import { TextLength } from '../../../../../util/vs/editor/common/core/text/textLength';
import { Range } from '../../../../../vscodeTypes';
import { IAstVisualization, subtractRange, toAstNode } from '../visualization';
import { ConcatenatedStringFragment, LiteralStringFragment, OriginalStringFragment, pushFragment, StringFragment } from './fragments';
Expand Down Expand Up @@ -213,7 +213,7 @@ export function summarizeDocumentsSyncImpl<TDocument extends AbstractDocument>(
// total length of all nodes
let totalLength = sumBy(rootMarkedNodes, c => c.getTextFragment().length);
if (settings.lineNumberStyle === SummarizedDocumentLineNumberStyle.Full) {
const textLen = TextLength.sum(rootMarkedNodes, c => c.getTextFragment().textLength);
const textLen = TextLengthSum(rootMarkedNodes, c => c.getTextFragment().textLength);
const maxLineNumber = docs[docIdx].document.getLineCount();
const totalLineNumberChars = textLen.lineCount * getLineNumberText(maxLineNumber).length; // This is an upper bound approximation.
totalLength += totalLineNumberChars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ProjectedText {
}

public projectOffsetEdit(edit: StringEdit): StringEdit {
return edit.tryRebase(this.edits, false);
return edit.rebaseSkipConflicting(this.edits);
}

public tryRebase(originalEdit: StringEdit): { edit: StringEdit; text: ProjectedText } | undefined {
Expand All @@ -66,7 +66,7 @@ export class ProjectedText {
}

public projectBackOffsetEdit(edit: StringEdit): StringEdit {
return edit.tryRebase(this.edits.inverse(this.originalText), false);
return edit.rebaseSkipConflicting(this.edits.inverse(this.originalText));
}

public projectBackTextEdit(edits: readonly vscode.TextEdit[]): vscode.TextEdit[] {
Expand Down
6 changes: 3 additions & 3 deletions src/extension/prompts/node/inline/workingCopies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export class WorkingCopyDerivedDocument {
const s0 = this._derivedDocument;
const e_sum = s0.edits;
const e_ai = toOffsetEdits(s0.positionOffsetTransformer, value.edits);
const e_ai_r = e_ai.tryRebase(e_sum.inverse(d0.text), false);
const e_sum_r = e_sum.tryRebase(e_ai_r, false);
const e_ai_r = e_ai.rebaseSkipConflicting(e_sum.inverse(d0.text));
const e_sum_r = e_sum.rebaseSkipConflicting(e_ai_r);

const transformedProgressItem = new ChatResponseTextEditPart(value.uri, fromOffsetEdits(d0.transformer, e_ai_r));

Expand All @@ -103,7 +103,7 @@ export class WorkingCopyDerivedDocument {
const s0 = this._derivedDocument;
const e_sum = s0.edits;
const e_ai = toOffsetEdits(s0.positionOffsetTransformer, edits);
const e_ai_r = e_ai.tryRebase(e_sum.inverse(d0.text), false);
const e_ai_r = e_ai.rebaseSkipConflicting(e_sum.inverse(d0.text));
return fromOffsetEdits(d0.transformer, e_ai_r);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ThrottledDebouncer implements Disposable {
private static readonly DELAY_INCREMENT = 10;
private static readonly MAX_DELAY = 500;

private timeoutId: NodeJS.Timeout | undefined;
private timeoutId: Timeout | undefined;
private currentDelay: number;
private readonly initialDelay: number;
private readonly increment: number;
Expand Down
2 changes: 1 addition & 1 deletion src/extension/xtab/common/promptCrafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function generateDocDiff(entry: IXtabHistoryEditEntry, workspacePath: string | u

const lineEdit = RootedEdit.toLineEdit(entry.edit);

for (const singleLineEdit of lineEdit.edits) {
for (const singleLineEdit of lineEdit.replacements) {
const oldLines = entry.edit.base.getLines().slice(singleLineEdit.lineRange.startLineNumber - 1, singleLineEdit.lineRange.endLineNumberExclusive - 1);
const newLines = singleLineEdit.newLines;

Expand Down
3 changes: 2 additions & 1 deletion src/extension/xtab/node/xtabProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { IWorkspaceService } from '../../../platform/workspace/common/workspaceS
import * as errors from '../../../util/common/errors';
import { Result } from '../../../util/common/result';
import { createTracer, ITracer } from '../../../util/common/tracing';
import { AsyncIterableObject, DeferredPromise, raceFilter, raceTimeout, timeout } from '../../../util/vs/base/common/async';
import { AsyncIterableObject, DeferredPromise, raceTimeout, timeout } from '../../../util/vs/base/common/async';
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
import { StopWatch } from '../../../util/vs/base/common/stopwatch';
import { LineEdit, LineReplacement } from '../../../util/vs/editor/common/core/edits/lineEdit';
Expand All @@ -48,6 +48,7 @@ import { IgnoreImportChangesAspect } from '../../inlineEdits/node/importFilterin
import { AREA_AROUND_END_TAG, AREA_AROUND_START_TAG, CODE_TO_EDIT_END_TAG, CODE_TO_EDIT_START_TAG, createTaggedCurrentFileContentUsingPagedClipping, CURSOR_TAG, getUserPrompt, N_LINES_ABOVE, N_LINES_AS_CONTEXT, N_LINES_BELOW, nes41Miniv3SystemPrompt, simplifiedPrompt, systemPromptTemplate, unifiedModelSystemPrompt, xtab275SystemPrompt } from '../common/promptCrafting';
import { XtabEndpoint } from './xtabEndpoint';
import { linesWithBackticksRemoved, toLines } from './xtabUtils';
import { raceFilter } from '../../../util/common/async';

export const IGNORE_TEXT_BEFORE = /```[^\n]*\n/;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class MemFS implements vscode.FileSystemProvider {

private _emitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>();
private _bufferedEvents: vscode.FileChangeEvent[] = [];
private _fireSoonHandle?: NodeJS.Timeout;
private _fireSoonHandle?: Timeout;

readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = this._emitter.event;

Expand Down
5 changes: 4 additions & 1 deletion src/platform/inlineEdits/common/dataTypes/rootedLineEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import { LineEdit, LineReplacement } from '../../../../util/vs/editor/common/core/edits/lineEdit';
import { BaseStringEdit, StringEdit } from '../../../../util/vs/editor/common/core/edits/stringEdit';
import { StringText } from '../../../../util/vs/editor/common/core/text/abstractText';
import { ensureDependenciesAreSet } from '../../../../util/vs/editor/common/core/text/positionToOffset';
import { RootedEdit } from './edit';

ensureDependenciesAreSet();

export class RootedLineEdit {
public static fromEdit<TEdit extends BaseStringEdit>(edit: RootedEdit<TEdit>): RootedLineEdit {
const lineEdit = LineEdit.fromEdit(edit.edit, edit.base);
Expand Down Expand Up @@ -40,7 +43,7 @@ export class RootedLineEdit {

public removeCommonSuffixPrefixLines(): RootedLineEdit {
const isNotEmptyEdit = (edit: LineReplacement) => !edit.lineRange.isEmpty || edit.newLines.length > 0;
const newEdit = this.edit.edits.map(e => e.removeCommonSuffixPrefixLines(this.base)).filter(e => isNotEmptyEdit(e));
const newEdit = this.edit.replacements.map(e => e.removeCommonSuffixPrefixLines(this.base)).filter(e => isNotEmptyEdit(e));
return new RootedLineEdit(this.base, new LineEdit(newEdit));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class DocumentState {
const potentialRecentEdit = e.edit.compose(recentEdit);
const potentialLineEdit = RootedEdit.toLineEdit(new RootedEdit(lastValue, potentialRecentEdit));
const rootedLineEdit = new RootedLineEdit(lastValue, potentialLineEdit).removeCommonSuffixPrefixLines(); // do not take into account no-op edits
const editLineCount = rootedLineEdit.edit.edits.length;
const editLineCount = rootedLineEdit.edit.replacements.length;
if (editLineCount > maxEditCount) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class NesXtabHistoryTracker extends Disposable {

const currentLineEdit = RootedEdit.toLineEdit(currentRootedEdit);

if (!currentLineEdit.isEmpty() && !lastLineEdit.isEmpty() && lastLineEdit.edits[0].lineRange.startLineNumber === currentLineEdit.edits[0].lineRange.startLineNumber) {
if (!currentLineEdit.isEmpty() && !lastLineEdit.isEmpty() && lastLineEdit.replacements[0].lineRange.startLineNumber === currentLineEdit.replacements[0].lineRange.startLineNumber) {
// merge edits
previousRecord.removeFromHistory();
const composedEdit = lastRootedEdit.edit.compose(currentEdit);
Expand Down
6 changes: 5 additions & 1 deletion src/platform/test/node/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export class TestingServicesAccessor implements ITestingServicesAccessor {
}

getIfExists<T>(id: ServiceIdentifier<T>): T | undefined {
return this._instaService.invokeFunction(accessor => accessor.getIfExists(id));
try {
return this._instaService.invokeFunction(accessor => accessor.get(id));
} catch {
return undefined;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/tokenizer/node/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class BPETokenizer extends Disposable implements ITokenizer {
this._tokenizer = undefined;
});

let timeout: NodeJS.Timeout;
let timeout: Timeout;

return {
encode: (text, allowedSpecial) => {
Expand Down
26 changes: 26 additions & 0 deletions src/util/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,29 @@ export class BatchedProcessor<TArg, TResult> {
}
}
}

export function raceFilter<T>(promises: Promise<T>[], filter: (result: T) => boolean): Promise<T | undefined> {
return new Promise((resolve, reject) => {
if (promises.length === 0) {
resolve(undefined);
return;
}

let resolved = false;
let unresolvedCount = promises.length;
for (const promise of promises) {
promise.then(result => {
unresolvedCount--;
if (!resolved) {
if (filter(result)) {
resolved = true;
resolve(result);
} else if (unresolvedCount === 0) {
// Last one has to resolve the promise
resolve(undefined);
}
}
}).catch(reject);
}
});
}
Loading
Loading