mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Merge pull request #269985 from microsoft/tyriar/more_terminal_any
Remove more as any from terminal
This commit is contained in:
@@ -66,33 +66,38 @@ async function getAliases(options: ExecOptionsWithStringEncoding, existingComman
|
|||||||
console.error('Error parsing output:', e);
|
console.error('Error parsing output:', e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return (json as any[]).map(e => {
|
if (!Array.isArray(json)) {
|
||||||
// Aliases sometimes use the same Name and DisplayName, show them as methods in this case.
|
return [];
|
||||||
const isAlias = e.Name !== e.DisplayName;
|
}
|
||||||
const detailParts: string[] = [];
|
return (json as unknown[])
|
||||||
if (e.Definition) {
|
.filter(isPwshGetCommandEntry)
|
||||||
detailParts.push(e.Definition);
|
.map(e => {
|
||||||
}
|
// Aliases sometimes use the same Name and DisplayName, show them as methods in this case.
|
||||||
if (e.ModuleName && e.Version) {
|
const isAlias = e.Name !== e.DisplayName;
|
||||||
detailParts.push(`${e.ModuleName} v${e.Version}`);
|
const detailParts: string[] = [];
|
||||||
}
|
if (e.Definition) {
|
||||||
let definitionCommand = undefined;
|
detailParts.push(e.Definition);
|
||||||
if (e.Definition) {
|
|
||||||
let definitionIndex = e.Definition.indexOf(' ');
|
|
||||||
if (definitionIndex === -1) {
|
|
||||||
definitionIndex = e.Definition.length;
|
|
||||||
definitionCommand = e.Definition.substring(0, definitionIndex);
|
|
||||||
}
|
}
|
||||||
}
|
if (e.ModuleName && e.Version) {
|
||||||
return {
|
detailParts.push(`${e.ModuleName} v${e.Version}`);
|
||||||
label: e.Name,
|
}
|
||||||
detail: detailParts.join('\n\n'),
|
let definitionCommand = undefined;
|
||||||
kind: (isAlias
|
if (e.Definition) {
|
||||||
? vscode.TerminalCompletionItemKind.Alias
|
let definitionIndex = e.Definition.indexOf(' ');
|
||||||
: vscode.TerminalCompletionItemKind.Method),
|
if (definitionIndex === -1) {
|
||||||
definitionCommand,
|
definitionIndex = e.Definition.length;
|
||||||
};
|
definitionCommand = e.Definition.substring(0, definitionIndex);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label: e.Name,
|
||||||
|
detail: detailParts.join('\n\n'),
|
||||||
|
kind: (isAlias
|
||||||
|
? vscode.TerminalCompletionItemKind.Alias
|
||||||
|
: vscode.TerminalCompletionItemKind.Method),
|
||||||
|
definitionCommand,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCommands(options: ExecOptionsWithStringEncoding, existingCommands?: Set<string>): Promise<ICompletionResource[]> {
|
async function getCommands(options: ExecOptionsWithStringEncoding, existingCommands?: Set<string>): Promise<ICompletionResource[]> {
|
||||||
@@ -100,15 +105,19 @@ async function getCommands(options: ExecOptionsWithStringEncoding, existingComma
|
|||||||
...options,
|
...options,
|
||||||
maxBuffer: 1024 * 1024 * 100 // This is a lot of content, increase buffer size
|
maxBuffer: 1024 * 1024 * 100 // This is a lot of content, increase buffer size
|
||||||
});
|
});
|
||||||
let json: any;
|
let json: unknown;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(output);
|
json = JSON.parse(output);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error parsing pwsh output:', e);
|
console.error('Error parsing pwsh output:', e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
if (!Array.isArray(json)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
(json as any[])
|
(json as unknown[])
|
||||||
|
.filter(isPwshGetCommandEntry)
|
||||||
.filter(e => e.CommandType !== PwshCommandType.Alias)
|
.filter(e => e.CommandType !== PwshCommandType.Alias)
|
||||||
.map(e => {
|
.map(e => {
|
||||||
const detailParts: string[] = [];
|
const detailParts: string[] = [];
|
||||||
@@ -126,3 +135,39 @@ async function getCommands(options: ExecOptionsWithStringEncoding, existingComma
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IPwshGetCommandEntry {
|
||||||
|
Name: string;
|
||||||
|
CommandType: PwshCommandType;
|
||||||
|
DisplayName?: string | null;
|
||||||
|
Definition?: string | null;
|
||||||
|
ModuleName?: string | null;
|
||||||
|
Version?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPwshGetCommandEntry(entry: unknown): entry is IPwshGetCommandEntry {
|
||||||
|
return (
|
||||||
|
isObject(entry) &&
|
||||||
|
'Name' in entry && typeof entry.Name === 'string' &&
|
||||||
|
'CommandType' in entry && typeof entry.CommandType === 'number' &&
|
||||||
|
(!('DisplayName' in entry) || typeof entry.DisplayName === 'string' || entry.DisplayName === null) &&
|
||||||
|
(!('Definition' in entry) || typeof entry.Definition === 'string' || entry.Definition === null) &&
|
||||||
|
(!('ModuleName' in entry) || typeof entry.ModuleName === 'string' || entry.ModuleName === null) &&
|
||||||
|
(!('Version' in entry) || typeof entry.Version === 'string' || entry.Version === null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns whether the provided parameter is of type `object` but **not**
|
||||||
|
* `null`, an `array`, a `regexp`, nor a `date`.
|
||||||
|
*/
|
||||||
|
export function isObject(obj: unknown): obj is Object {
|
||||||
|
// The method can't do a type cast since there are type (like strings) which
|
||||||
|
// are subclasses of any put not positvely matched by the function. Hence type
|
||||||
|
// narrowing results in wrong results.
|
||||||
|
return typeof obj === 'object'
|
||||||
|
&& obj !== null
|
||||||
|
&& !Array.isArray(obj)
|
||||||
|
&& !(obj instanceof RegExp)
|
||||||
|
&& !(obj instanceof Date);
|
||||||
|
}
|
||||||
|
|||||||
@@ -91,8 +91,7 @@ registerTerminalAction({
|
|||||||
}
|
}
|
||||||
escapedData = escapedData.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + escapedData.slice(match.index + 4);
|
escapedData = escapedData.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + escapedData.slice(match.index + 4);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
const xterm = instance.xterm as IInternalXtermTerminal;
|
||||||
const xterm = instance.xterm as any as IInternalXtermTerminal;
|
|
||||||
xterm._writeText(escapedData);
|
xterm._writeText(escapedData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -149,8 +149,10 @@ export class TerminalLinkManager extends DisposableStore {
|
|||||||
activeHoverDisposable = undefined;
|
activeHoverDisposable = undefined;
|
||||||
activeTooltipScheduler?.dispose();
|
activeTooltipScheduler?.dispose();
|
||||||
activeTooltipScheduler = new RunOnceScheduler(() => {
|
activeTooltipScheduler = new RunOnceScheduler(() => {
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
interface XtermWithCore extends Terminal {
|
||||||
const core = (this._xterm as any)._core as IXtermCore;
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
const core = (this._xterm as XtermWithCore)._core;
|
||||||
const cellDimensions = {
|
const cellDimensions = {
|
||||||
width: core._renderService.dimensions.css.cell.width,
|
width: core._renderService.dimensions.css.cell.width,
|
||||||
height: core._renderService.dimensions.css.cell.height
|
height: core._renderService.dimensions.css.cell.height
|
||||||
@@ -348,8 +350,10 @@ export class TerminalLinkManager extends DisposableStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
interface XtermWithCore extends Terminal {
|
||||||
const core = (this._xterm as any)._core as IXtermCore;
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
const core = (this._xterm as XtermWithCore)._core;
|
||||||
const cellDimensions = {
|
const cellDimensions = {
|
||||||
width: core._renderService.dimensions.css.cell.width,
|
width: core._renderService.dimensions.css.cell.width,
|
||||||
height: core._renderService.dimensions.css.cell.height
|
height: core._renderService.dimensions.css.cell.height
|
||||||
|
|||||||
@@ -406,8 +406,10 @@ export class TerminalStickyScrollOverlay extends Disposable {
|
|||||||
}
|
}
|
||||||
hoverOverlay.title = hoverTitle;
|
hoverOverlay.title = hoverTitle;
|
||||||
|
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
interface XtermWithCore extends XTermTerminal {
|
||||||
const scrollBarWidth = (this._xterm.raw as any as { _core: IXtermCore })._core.viewport?.scrollBarWidth;
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
const scrollBarWidth = (this._xterm.raw as XtermWithCore)._core.viewport?.scrollBarWidth;
|
||||||
if (scrollBarWidth !== undefined) {
|
if (scrollBarWidth !== undefined) {
|
||||||
this._element.style.right = `${scrollBarWidth}px`;
|
this._element.style.right = `${scrollBarWidth}px`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -682,8 +682,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getTerminalDimensions(): { width: number; height: number } {
|
private _getTerminalDimensions(): { width: number; height: number } {
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
interface XtermWithCore extends Terminal {
|
||||||
const cssCellDims = (this._terminal as any as { _core: IXtermCore })._core._renderService.dimensions.css.cell;
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
const cssCellDims = (this._terminal as XtermWithCore)._core._renderService.dimensions.css.cell;
|
||||||
return {
|
return {
|
||||||
width: cssCellDims.width,
|
width: cssCellDims.width,
|
||||||
height: cssCellDims.height,
|
height: cssCellDims.height,
|
||||||
@@ -708,8 +710,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
|
|||||||
return this._cachedFontInfo;
|
return this._cachedFontInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
interface XtermWithCore extends Terminal {
|
||||||
const core = (this._terminal as any)._core as IXtermCore;
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
const core = (this._terminal as XtermWithCore)._core;
|
||||||
const font = this._terminalConfigurationService.getFont(dom.getActiveWindow(), core);
|
const font = this._terminalConfigurationService.getFont(dom.getActiveWindow(), core);
|
||||||
let lineHeight: number = font.lineHeight;
|
let lineHeight: number = font.lineHeight;
|
||||||
const fontSize: number = font.fontSize;
|
const fontSize: number = font.fontSize;
|
||||||
|
|||||||
@@ -50,8 +50,12 @@ const enum StatsConstants {
|
|||||||
*/
|
*/
|
||||||
const PREDICTION_OMIT_RE = /^(\x1b\[(\??25[hl]|\??[0-9;]+n))+/;
|
const PREDICTION_OMIT_RE = /^(\x1b\[(\??25[hl]|\??[0-9;]+n))+/;
|
||||||
|
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
const core = (terminal: Terminal): IXtermCore => {
|
||||||
const core = (terminal: Terminal): IXtermCore => (terminal as any)._core;
|
interface XtermWithCore extends Terminal {
|
||||||
|
_core: IXtermCore;
|
||||||
|
}
|
||||||
|
return (terminal as XtermWithCore)._core;
|
||||||
|
};
|
||||||
const flushOutput = (terminal: Terminal) => {
|
const flushOutput = (terminal: Terminal) => {
|
||||||
// TODO: Flushing output is not possible anymore without async
|
// TODO: Flushing output is not possible anymore without async
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -71,43 +71,46 @@ class TerminalMouseWheelZoomContribution extends Disposable implements ITerminal
|
|||||||
let gestureHasZoomModifiers = false;
|
let gestureHasZoomModifiers = false;
|
||||||
let gestureAccumulatedDelta = 0;
|
let gestureAccumulatedDelta = 0;
|
||||||
|
|
||||||
raw.attachCustomWheelEventHandler((e: WheelEvent) => {
|
raw.attachCustomWheelEventHandler((browserEvent: WheelEvent) => {
|
||||||
// eslint-disable-next-line local/code-no-any-casts
|
function isWheelEvent(e: MouseEvent): e is IMouseWheelEvent {
|
||||||
const browserEvent = e as any as IMouseWheelEvent;
|
return 'wheelDelta' in e && 'wheelDeltaX' in e && 'wheelDeltaY' in e;
|
||||||
if (classifier.isPhysicalMouseWheel()) {
|
}
|
||||||
if (this._hasMouseWheelZoomModifiers(browserEvent)) {
|
if (isWheelEvent(browserEvent)) {
|
||||||
const delta = browserEvent.deltaY > 0 ? -1 : 1;
|
if (classifier.isPhysicalMouseWheel()) {
|
||||||
const newFontSize = this._clampFontSize(this._getConfigFontSize() + delta);
|
if (this._hasMouseWheelZoomModifiers(browserEvent)) {
|
||||||
this._configurationService.updateValue(TerminalSettingId.FontSize, newFontSize);
|
const delta = browserEvent.deltaY > 0 ? -1 : 1;
|
||||||
// EditorZoom.setZoomLevel(zoomLevel + delta);
|
const newFontSize = this._clampFontSize(this._getConfigFontSize() + delta);
|
||||||
browserEvent.preventDefault();
|
this._configurationService.updateValue(TerminalSettingId.FontSize, newFontSize);
|
||||||
browserEvent.stopPropagation();
|
// EditorZoom.setZoomLevel(zoomLevel + delta);
|
||||||
return false;
|
browserEvent.preventDefault();
|
||||||
}
|
browserEvent.stopPropagation();
|
||||||
} else {
|
return false;
|
||||||
// we consider mousewheel events that occur within 50ms of each other to be part of the same gesture
|
}
|
||||||
// we don't want to consider mouse wheel events where ctrl/cmd is pressed during the inertia phase
|
} else {
|
||||||
// we also want to accumulate deltaY values from the same gesture and use that to set the zoom level
|
// we consider mousewheel events that occur within 50ms of each other to be part of the same gesture
|
||||||
if (Date.now() - prevMouseWheelTime > 50) {
|
// we don't want to consider mouse wheel events where ctrl/cmd is pressed during the inertia phase
|
||||||
// reset if more than 50ms have passed
|
// we also want to accumulate deltaY values from the same gesture and use that to set the zoom level
|
||||||
gestureStartFontSize = this._getConfigFontSize();
|
if (Date.now() - prevMouseWheelTime > 50) {
|
||||||
gestureHasZoomModifiers = this._hasMouseWheelZoomModifiers(browserEvent);
|
// reset if more than 50ms have passed
|
||||||
gestureAccumulatedDelta = 0;
|
gestureStartFontSize = this._getConfigFontSize();
|
||||||
}
|
gestureHasZoomModifiers = this._hasMouseWheelZoomModifiers(browserEvent);
|
||||||
|
gestureAccumulatedDelta = 0;
|
||||||
|
}
|
||||||
|
|
||||||
prevMouseWheelTime = Date.now();
|
prevMouseWheelTime = Date.now();
|
||||||
gestureAccumulatedDelta += browserEvent.deltaY;
|
|
||||||
|
|
||||||
if (gestureHasZoomModifiers) {
|
|
||||||
const deltaAbs = Math.ceil(Math.abs(gestureAccumulatedDelta / 5));
|
|
||||||
const deltaDirection = gestureAccumulatedDelta > 0 ? -1 : 1;
|
|
||||||
const delta = deltaAbs * deltaDirection;
|
|
||||||
const newFontSize = this._clampFontSize(gestureStartFontSize + delta);
|
|
||||||
this._configurationService.updateValue(TerminalSettingId.FontSize, newFontSize);
|
|
||||||
gestureAccumulatedDelta += browserEvent.deltaY;
|
gestureAccumulatedDelta += browserEvent.deltaY;
|
||||||
browserEvent.preventDefault();
|
|
||||||
browserEvent.stopPropagation();
|
if (gestureHasZoomModifiers) {
|
||||||
return false;
|
const deltaAbs = Math.ceil(Math.abs(gestureAccumulatedDelta / 5));
|
||||||
|
const deltaDirection = gestureAccumulatedDelta > 0 ? -1 : 1;
|
||||||
|
const delta = deltaAbs * deltaDirection;
|
||||||
|
const newFontSize = this._clampFontSize(gestureStartFontSize + delta);
|
||||||
|
this._configurationService.updateValue(TerminalSettingId.FontSize, newFontSize);
|
||||||
|
gestureAccumulatedDelta += browserEvent.deltaY;
|
||||||
|
browserEvent.preventDefault();
|
||||||
|
browserEvent.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user