Skip to content

Commit

Permalink
Rebase against the upstream a016c0b
Browse files Browse the repository at this point in the history
vscode-upstream-sha1: a016c0b
  • Loading branch information
Eclipse Che Sync committed Jan 9, 2025
2 parents dcd46a2 + a016c0b commit ecfbdc2
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 28 deletions.
21 changes: 18 additions & 3 deletions code/extensions/git/src/timelineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CancellationToken, ConfigurationChangeEvent, Disposable, env, Event, EventEmitter, MarkdownString, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace, l10n } from 'vscode';
import { CancellationToken, ConfigurationChangeEvent, Disposable, env, Event, EventEmitter, MarkdownString, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace, l10n, Command } from 'vscode';
import { Model } from './model';
import { Repository, Resource } from './repository';
import { debounce } from './decorators';
Expand All @@ -12,6 +12,7 @@ import { CommandCenter } from './commands';
import { OperationKind, OperationResult } from './operation';
import { getCommitShortHash } from './util';
import { CommitShortStat } from './git';
import { getRemoteSourceControlHistoryItemCommands } from './remoteSource';

export class GitTimelineItem extends TimelineItem {
static is(item: TimelineItem): item is GitTimelineItem {
Expand Down Expand Up @@ -50,7 +51,7 @@ export class GitTimelineItem extends TimelineItem {
return this.shortenRef(this.previousRef);
}

setItemDetails(uri: Uri, hash: string | undefined, author: string, email: string | undefined, date: string, message: string, shortStat?: CommitShortStat): void {
setItemDetails(uri: Uri, hash: string | undefined, author: string, email: string | undefined, date: string, message: string, shortStat?: CommitShortStat, remoteSourceCommands: Command[] = []): void {
this.tooltip = new MarkdownString('', true);
this.tooltip.isTrusted = true;
this.tooltip.supportHtml = true;
Expand Down Expand Up @@ -89,6 +90,15 @@ export class GitTimelineItem extends TimelineItem {
this.tooltip.appendMarkdown(`[\`$(git-commit) ${getCommitShortHash(uri, hash)} \`](command:git.viewCommit?${encodeURIComponent(JSON.stringify([uri, hash]))} "${l10n.t('View Commit')}")`);
this.tooltip.appendMarkdown(' ');
this.tooltip.appendMarkdown(`[$(copy)](command:git.copyContentToClipboard?${encodeURIComponent(JSON.stringify(hash))} "${l10n.t('Copy Commit Hash')}")`);

// Remote commands
if (remoteSourceCommands.length > 0) {
this.tooltip.appendMarkdown('  |  ');

const remoteCommandsMarkdown = remoteSourceCommands
.map(command => `[${command.title}](command:${command.command}?${encodeURIComponent(JSON.stringify([...command.arguments ?? [], hash]))} "${command.tooltip}")`);
this.tooltip.appendMarkdown(remoteCommandsMarkdown.join(' '));
}
}
}

Expand Down Expand Up @@ -204,6 +214,11 @@ export class GitTimelineProvider implements TimelineProvider {

const openComparison = l10n.t('Open Comparison');

const defaultRemote = repo.getDefaultRemote();
const remoteSourceCommands: Command[] = defaultRemote?.fetchUrl
? await getRemoteSourceControlHistoryItemCommands(defaultRemote.fetchUrl)
: [];

const items = commits.map<GitTimelineItem>((c, i) => {
const date = dateType === 'authored' ? c.authorDate : c.commitDate;

Expand All @@ -215,7 +230,7 @@ export class GitTimelineProvider implements TimelineProvider {
item.description = c.authorName;
}

item.setItemDetails(uri, c.hash, c.authorName!, c.authorEmail, dateFormatter.format(date), message, c.shortStat);
item.setItemDetails(uri, c.hash, c.authorName!, c.authorEmail, dateFormatter.format(date), message, c.shortStat, remoteSourceCommands);

const cmd = this.commands.resolveTimelineOpenDiffCommand(item, uri);
if (cmd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] got result`);
// Check expiration of id token and if it's 5min before expiration, force a refresh.
// this is what MSAL does for access tokens already so we're just adding it for id tokens since we care about those.
// NOTE: Once we stop depending on id tokens for some things we can remove all of this.
const idTokenExpirationInSecs = (result.idTokenClaims as { exp?: number }).exp;
if (idTokenExpirationInSecs) {
const fiveMinutesBefore = new Date(
Expand All @@ -106,12 +107,35 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
? { ...request, claims: '{ "id_token": {}}' }
: { ...request, forceRefresh: true };
result = await this._sequencer.queue(() => this._pca.acquireTokenSilent(newRequest));
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] got refreshed result`);
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] got forced result`);
}
const newIdTokenExpirationInSecs = (result.idTokenClaims as { exp?: number }).exp;
if (newIdTokenExpirationInSecs) {
if (new Date(newIdTokenExpirationInSecs * 1000) < new Date()) {
const fiveMinutesBefore = new Date(
(newIdTokenExpirationInSecs - 5 * 60) // subtract 5 minutes
* 1000 // convert to milliseconds
);
if (fiveMinutesBefore < new Date()) {
this._logger.error(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] id token is still expired.`);

// HACK: Only for the Broker we try one more time with different claims to force a refresh. Why? We've seen the Broker caching tokens by the claims requested, thus
// there has been a situation where both tokens are expired.
if (this._isBrokerAvailable) {
this._logger.error(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] forcing refresh with different claims...`);
const newRequest = { ...request, claims: '{ "access_token": {}}' };
result = await this._sequencer.queue(() => this._pca.acquireTokenSilent(newRequest));
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] got forced result with different claims`);
const newIdTokenExpirationInSecs = (result.idTokenClaims as { exp?: number }).exp;
if (newIdTokenExpirationInSecs) {
const fiveMinutesBefore = new Date(
(newIdTokenExpirationInSecs - 5 * 60) // subtract 5 minutes
* 1000 // convert to milliseconds
);
if (fiveMinutesBefore < new Date()) {
this._logger.error(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] id token is still expired.`);
}
}
}
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions code/src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4200,7 +4200,6 @@ export interface IInlineSuggestOptions {
useWordInsertionView?: 'never' | 'whenPossible';
useWordReplacementView?: 'never' | 'whenPossible';

onlyShowWhenCloseToCursor?: boolean;
useGutterIndicator?: boolean;
};
};
Expand Down Expand Up @@ -4235,7 +4234,6 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
useInterleavedLinesDiff: 'never',
useWordInsertionView: 'whenPossible',
useWordReplacementView: 'whenPossible',
onlyShowWhenCloseToCursor: true,
useGutterIndicator: true,
},
},
Expand Down Expand Up @@ -4304,11 +4302,6 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
description: nls.localize('inlineSuggest.edits.experimental.useWordReplacementView', "Controls whether to enable experimental word replacement view in inline suggestions."),
enum: ['never', 'whenPossible'],
},
'editor.inlineSuggest.edits.experimental.onlyShowWhenCloseToCursor': {
type: 'boolean',
default: defaults.edits.experimental.onlyShowWhenCloseToCursor,
description: nls.localize('inlineSuggest.edits.experimental.onlyShowWhenCloseToCursor', "Controls whether to only show inline suggestions when the cursor is close to the suggestion.")
},
'editor.inlineSuggest.edits.experimental.useGutterIndicator': {
type: 'boolean',
default: defaults.edits.experimental.useGutterIndicator,
Expand Down Expand Up @@ -4338,7 +4331,6 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
useInterleavedLinesDiff: stringSet(input.edits?.experimental?.useInterleavedLinesDiff, this.defaultValue.edits.experimental.useInterleavedLinesDiff, ['never', 'always', 'afterJump']),
useWordInsertionView: stringSet(input.edits?.experimental?.useWordInsertionView, this.defaultValue.edits.experimental.useWordInsertionView, ['never', 'whenPossible']),
useWordReplacementView: stringSet(input.edits?.experimental?.useWordReplacementView, this.defaultValue.edits.experimental.useWordReplacementView, ['never', 'whenPossible']),
onlyShowWhenCloseToCursor: boolean(input.edits?.experimental?.onlyShowWhenCloseToCursor, this.defaultValue.edits.experimental.onlyShowWhenCloseToCursor),
useGutterIndicator: boolean(input.edits?.experimental?.useGutterIndicator, this.defaultValue.edits.experimental.useGutterIndicator),
},
},
Expand Down
3 changes: 3 additions & 0 deletions code/src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ export interface InlineCompletion {
readonly completeBracketPairs?: boolean;

readonly isInlineEdit?: boolean;

readonly showRange?: IRange;
}

export interface InlineCompletions<TItem extends InlineCompletion = InlineCompletion> {
Expand Down Expand Up @@ -2396,6 +2398,7 @@ export interface MappedEditsProvider {
export interface IInlineEdit {
text: string;
range: IRange;
showRange?: IRange;
accepted?: Command;
rejected?: Command;
shown?: Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class InlineCompletionsModel extends Disposable {

private readonly _editorObs = observableCodeEditor(this._editor);

private readonly _onlyShowWhenCloseToCursor = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => !!v.edits.experimental.onlyShowWhenCloseToCursor);
private readonly _suggestPreviewEnabled = this._editorObs.getOption(EditorOption.suggest).map(v => v.preview);
private readonly _suggestPreviewMode = this._editorObs.getOption(EditorOption.suggest).map(v => v.previewMode);
private readonly _inlineSuggestMode = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => v.mode);
Expand Down Expand Up @@ -358,12 +357,13 @@ export class InlineCompletionsModel extends Disposable {

const cursorPos = this.primaryPosition.read(reader);
const cursorAtInlineEdit = LineRange.fromRangeInclusive(edit.range).addMargin(1, 1).contains(cursorPos.lineNumber);
const cursorInsideShowRange = cursorAtInlineEdit || (item.inlineEdit.inlineCompletion.cursorShowRange?.containsPosition(cursorPos) ?? true);

const cursorDist = LineRange.fromRange(edit.range).distanceToLine(this.primaryPosition.read(reader).lineNumber);

if (this._onlyShowWhenCloseToCursor.read(reader) && cursorDist > 3 && !item.inlineEdit.request.isExplicitRequest && !this._inAcceptFlow.read(reader)) {
if (!cursorInsideShowRange && !this._inAcceptFlow.read(reader)) {
return undefined;
}

const cursorDist = LineRange.fromRange(edit.range).distanceToLine(this.primaryPosition.read(reader).lineNumber);
const disableCollapsing = true;
const currentItemIsCollapsed = !disableCollapsing && (cursorDist > 1 && this._collapsedInlineEditId.read(reader) === item.inlineEdit.semanticId);

Expand Down Expand Up @@ -575,6 +575,7 @@ export class InlineCompletionsModel extends Disposable {

editor.pushUndoStop();
if (completion.snippetInfo) {
// ...
editor.executeEdits(
'inlineSuggestion.accept',
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class InlineEditsAdapter extends Disposable {
items: definedEdits.map(e => {
return {
range: e.result.range,
showRange: e.result.showRange,
insertText: e.result.text,
command: e.result.accepted,
shownCommand: e.result.shown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export class InlineCompletionItem {
range,
insertText,
snippetInfo,
Range.lift(inlineCompletion.showRange) ?? undefined,
inlineCompletion.additionalTextEdits || getReadonlyEmptyArray(),
inlineCompletion,
source,
Expand All @@ -345,6 +346,7 @@ export class InlineCompletionItem {
readonly range: Range,
readonly insertText: string,
readonly snippetInfo: SnippetInfo | undefined,
readonly cursorShowRange: Range | undefined,

readonly additionalTextEdits: readonly ISingleEditOperation[],

Expand Down Expand Up @@ -380,6 +382,7 @@ export class InlineCompletionItem {
updatedRange,
this.insertText,
this.snippetInfo,
this.cursorShowRange,
this.additionalTextEdits,
this.sourceInlineCompletion,
this.source,
Expand Down
3 changes: 2 additions & 1 deletion code/src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4607,7 +4607,6 @@ declare namespace monaco.editor {
useInterleavedLinesDiff?: 'never' | 'always' | 'afterJump';
useWordInsertionView?: 'never' | 'whenPossible';
useWordReplacementView?: 'never' | 'whenPossible';
onlyShowWhenCloseToCursor?: boolean;
useGutterIndicator?: boolean;
};
};
Expand Down Expand Up @@ -7277,6 +7276,7 @@ declare namespace monaco.languages {
*/
readonly completeBracketPairs?: boolean;
readonly isInlineEdit?: boolean;
readonly showRange?: IRange;
}

export interface InlineCompletions<TItem extends InlineCompletion = InlineCompletion> {
Expand Down Expand Up @@ -8164,6 +8164,7 @@ declare namespace monaco.languages {
export interface IInlineEdit {
text: string;
range: IRange;
showRange?: IRange;
accepted?: Command;
rejected?: Command;
shown?: Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
}
}));

// onDidChangeTerminalShellIntegration
// onDidchangeTerminalShellIntegration initial state
for (const terminal of this._terminalService.instances) {
if (terminal.capabilities.has(TerminalCapability.CommandDetection)) {
this._proxy.$shellIntegrationChange(terminal.instanceId);
const cwdDetection = terminal.capabilities.get(TerminalCapability.CwdDetection);
if (cwdDetection) {
this._proxy.$cwdChange(terminal.instanceId, this._convertCwdToUri(cwdDetection.getCwd()));
}
}
}

// onDidChangeTerminalShellIntegration via command detection
const onDidAddCommandDetection = this._store.add(this._terminalService.createOnInstanceEvent(instance => {
return Event.map(
Event.filter(instance.capabilities.onDidAddCapabilityType, e => {
Expand All @@ -43,6 +54,12 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
})).event;
this._store.add(onDidAddCommandDetection(e => this._proxy.$shellIntegrationChange(e.instanceId)));

// onDidChangeTerminalShellIntegration via cwd
const cwdChangeEvent = this._store.add(this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CwdDetection, e => e.onDidChangeCwd));
this._store.add(cwdChangeEvent.event(e => {
this._proxy.$cwdChange(e.instance.instanceId, this._convertCwdToUri(e.data));
}));

// onDidStartTerminalShellExecution
const commandDetectionStartEvent = this._store.add(this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CommandDetection, e => e.onCommandExecuted));
let currentCommand: ITerminalCommand | undefined;
Expand Down Expand Up @@ -75,12 +92,6 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma
});
}));

// onDidChangeTerminalShellIntegration via cwd
const cwdChangeEvent = this._store.add(this._terminalService.createOnInstanceCapabilityEvent(TerminalCapability.CwdDetection, e => e.onDidChangeCwd));
this._store.add(cwdChangeEvent.event(e => {
this._proxy.$cwdChange(e.instance.instanceId, this._convertCwdToUri(e.data));
}));

// Clean up after dispose
this._store.add(this._terminalService.onDidDisposeInstance(e => this._proxy.$closeTerminal(e.instanceId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ class InlineEditAdapter {
pid,
text: result.text,
range: typeConvert.Range.from(result.range),
showRange: typeConvert.Range.from(result.showRange),
accepted: acceptCommand,
rejected: rejectCommand,
shown: shownCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ export class TerminalChatWidget extends Disposable {
const model = this._model.value;
if (model) {
this._inlineChatWidget.setChatModel(model, this._loadViewState());
model.waitForInitialization().then(() => {
if (token.isCancellationRequested) {
return;
}
this._resetPlaceholder();
});
}
if (!this._model.value) {
throw new Error('Failed to start chat session');
Expand Down
12 changes: 9 additions & 3 deletions code/src/vscode-dts/vscode.proposed.inlineEdit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ declare module 'vscode' {
readonly text: string;

/**
* An range that will be replaced by the text of the inline edit.
* If change is only additive, this can be empty (same start and end position).
* A range that will be replaced by the text of the inline edit.
* If the change is only additive, this can be empty (same start and end position).
*/
readonly range: Range;

/**
* A range specifying when the edit can be shown based on the cursor position.
* If the cursor is within this range, the inline edit can be displayed.
*/
readonly showRange?: Range;

/**
* An optional command that will be executed after applying the inline edit.
*/
Expand All @@ -36,7 +42,7 @@ declare module 'vscode' {
* Creates a new inline edit.
*
* @param text The new text for this edit.
* @param replaceRange An range that will be replaced by the text of the inline edit.
* @param range A range that will be replaced by the text of the inline edit.
*/
constructor(text: string, range: Range);
}
Expand Down

0 comments on commit ecfbdc2

Please sign in to comment.