提交 275135a7 编写于 作者: D Daniel Imms

Prefer const

上级 20f9bf12
......@@ -65,7 +65,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
}
public $show(terminalId: number, preserveFocus: boolean): void {
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
const terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
this.terminalService.setActiveInstance(terminalInstance);
this.terminalService.showPanel(!preserveFocus);
......@@ -79,28 +79,28 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
}
public $dispose(terminalId: number): void {
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
const terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
terminalInstance.dispose();
}
}
public $write(terminalId: number, text: string): void {
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
const terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance && terminalInstance.shellLaunchConfig.isRendererOnly) {
terminalInstance.write(text);
}
}
public $sendText(terminalId: number, text: string, addNewLine: boolean): void {
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
const terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
terminalInstance.sendText(text, addNewLine);
}
}
public $registerOnDataListener(terminalId: number): void {
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
const terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
this._dataListeners[terminalId] = terminalInstance.onData(data => this._onTerminalData(terminalId, data));
terminalInstance.onDisposed(instance => delete this._dataListeners[terminalId]);
......
......@@ -18,7 +18,7 @@ import { ILogService } from 'vs/platform/log/common/log';
export class ExtHostTerminal implements vscode.Terminal {
private _id: number;
private _disposed: boolean;
private _disposed: boolean = false;
private _queuedRequests: ApiRequest[];
private _pidPromise: Promise<number>;
private _pidPromiseComplete: (value: number) => any;
......@@ -103,7 +103,7 @@ export class ExtHostTerminal implements vscode.Terminal {
}
private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) {
let request: ApiRequest = new ApiRequest(callback, args);
const request: ApiRequest = new ApiRequest(callback, args);
if (!this._id) {
this._queuedRequests.push(request);
return;
......@@ -120,7 +120,7 @@ export class ExtHostTerminal implements vscode.Terminal {
export class ExtHostTerminalRenderer implements vscode.TerminalRenderer {
private _id: number;
// private _disposed: boolean;
private _disposed: boolean = false;
private _queuedRequests: ApiRequest[];
public get name(): string { return this._name; }
......@@ -147,7 +147,7 @@ export class ExtHostTerminalRenderer implements vscode.TerminalRenderer {
}
private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) {
let request: ApiRequest = new ApiRequest(callback, args);
const request: ApiRequest = new ApiRequest(callback, args);
if (!this._id) {
this._queuedRequests.push(request);
return;
......@@ -278,7 +278,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
// Continue env initialization, merging in the env from the launch
// config and adding keys that are needed to create the process
const env = terminalEnvironment.createTerminalEnv(parentEnv, shellLaunchConfig, initialCwd, locale, cols, rows);
let cwd = Uri.parse(require.toUrl('../../parts/terminal/node')).fsPath;
const cwd = Uri.parse(require.toUrl('../../parts/terminal/node')).fsPath;
const options = { env, cwd, execArgv: [] };
// Fork the process and listen for messages
......@@ -333,7 +333,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
}
private _getTerminalById(id: number): ExtHostTerminal {
let index = this._getTerminalIndexById(id);
const index = this._getTerminalIndexById(id);
return index !== null ? this._terminals[index] : null;
}
......@@ -341,7 +341,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
let index: number = null;
this._terminals.some((terminal, i) => {
// TODO: This shouldn't be cas
let thisId = (<any>terminal)._id;
const thisId = (<any>terminal)._id;
if (thisId === id) {
index = i;
return true;
......
......@@ -21,13 +21,12 @@ export class TerminalFindWidget extends SimpleFindWidget {
}
public find(previous: boolean) {
let val = this.inputValue;
let instance = this._terminalService.getActiveInstance();
const instance = this._terminalService.getActiveInstance();
if (instance !== null) {
if (previous) {
instance.findPrevious(val);
instance.findPrevious(this.inputValue);
} else {
instance.findNext(val);
instance.findNext(this.inputValue);
}
}
}
......
......@@ -306,7 +306,7 @@ export class TerminalTab extends Disposable implements ITerminalTab {
// Adjust focus if the instance was active
if (wasActiveInstance && this._terminalInstances.length > 0) {
let newIndex = index < this._terminalInstances.length ? index : this._terminalInstances.length - 1;
const newIndex = index < this._terminalInstances.length ? index : this._terminalInstances.length - 1;
this.setActiveInstanceByIndex(newIndex);
// TODO: Only focus the new instance if the tab had focus?
this.activeInstance.focus(true);
......
......@@ -160,9 +160,9 @@ const ansiColorMap = {
};
export function registerColors(): void {
for (let id in ansiColorMap) {
let entry = ansiColorMap[id];
let colorName = id.substring(13);
for (const id in ansiColorMap) {
const entry = ansiColorMap[id];
const colorName = id.substring(13);
ansiColorIdentifiers[entry.index] = registerColor(id, entry.defaults, nls.localize('terminal.ansiColor', '\'{0}\' ANSI color in the terminal.', colorName));
}
}
......@@ -153,7 +153,7 @@ export abstract class TerminalService implements ITerminalService {
if (wasActiveTab && this._terminalTabs.length > 0) {
// TODO: Only focus the new tab if the removed tab had focus?
// const hasFocusOnExit = tab.activeInstance.hadFocusOnExit;
let newIndex = index < this._terminalTabs.length ? index : this._terminalTabs.length - 1;
const newIndex = index < this._terminalTabs.length ? index : this._terminalTabs.length - 1;
this.setActiveTabByIndex(newIndex);
this.getActiveInstance().focus(true);
}
......@@ -302,7 +302,7 @@ export abstract class TerminalService implements ITerminalService {
public showPanel(focus?: boolean): TPromise<void> {
return new TPromise<void>((complete) => {
let panel = this._panelService.getActivePanel();
const panel = this._panelService.getActivePanel();
if (!panel || panel.getId() !== TERMINAL_PANEL_ID) {
return this._panelService.openPanel(TERMINAL_PANEL_ID, focus).then(() => {
if (focus) {
......
......@@ -66,7 +66,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenTermAction, Q
const actionBarRegistry = Registry.as<IActionBarRegistry>(ActionBarExtensions.Actionbar);
actionBarRegistry.registerActionBarContributor(Scope.VIEWER, QuickOpenActionTermContributor);
let configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
const configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
configurationRegistry.registerConfiguration({
'id': 'terminal',
'order': 100,
......@@ -359,7 +359,7 @@ registerSingleton(ITerminalService, TerminalService);
// On mac cmd+` is reserved to cycle between windows, that's why the keybindings use WinCtrl
const category = nls.localize('terminalCategory', "Terminal");
let actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(KillTerminalAction, KillTerminalAction.ID, KillTerminalAction.LABEL), 'Terminal: Kill the Active Terminal Instance', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CopyTerminalSelectionAction, CopyTerminalSelectionAction.ID, CopyTerminalSelectionAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
......
......@@ -71,7 +71,7 @@ export class KillTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
this.terminalService.getActiveInstance().dispose();
if (this.terminalService.terminalInstances.length > 0) {
......@@ -121,7 +121,7 @@ export class CopyTerminalSelectionAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.copySelection();
}
......@@ -142,7 +142,7 @@ export class SelectAllTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.selectAll();
}
......@@ -161,7 +161,7 @@ export abstract class BaseSendTextTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this._terminalService.getActiveInstance();
const terminalInstance = this._terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.sendText(this._text, false);
}
......@@ -598,7 +598,7 @@ export class RunSelectedTextInTerminalAction extends Action {
if (selection.isEmpty()) {
text = editor.getModel().getLineContent(selection.selectionStartLineNumber).trim();
} else {
let endOfLinePreference = os.EOL === '\n' ? EndOfLinePreference.LF : EndOfLinePreference.CRLF;
const endOfLinePreference = os.EOL === '\n' ? EndOfLinePreference.LF : EndOfLinePreference.CRLF;
text = editor.getModel().getValueInRange(selection, endOfLinePreference);
}
instance.sendText(text, true);
......@@ -695,7 +695,7 @@ export class ScrollDownTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollDownLine();
}
......@@ -716,7 +716,7 @@ export class ScrollDownPageTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollDownPage();
}
......@@ -737,7 +737,7 @@ export class ScrollToBottomTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollToBottom();
}
......@@ -758,7 +758,7 @@ export class ScrollUpTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollUpLine();
}
......@@ -779,7 +779,7 @@ export class ScrollUpPageTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollUpPage();
}
......@@ -800,7 +800,7 @@ export class ScrollToTopTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollToTop();
}
......@@ -821,7 +821,7 @@ export class ClearTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.clear();
}
......@@ -842,7 +842,7 @@ export class ClearSelectionTerminalAction extends Action {
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
const terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance && terminalInstance.hasSelection()) {
terminalInstance.clearSelection();
}
......@@ -994,7 +994,7 @@ export class QuickOpenActionTermContributor extends ActionBarContributor {
}
public getActions(context: any): IAction[] {
let actions: Action[] = [];
const actions: Action[] = [];
if (context.element instanceof TerminalEntry) {
actions.push(this.instantiationService.createInstance(RenameTerminalQuickOpenAction, RenameTerminalQuickOpenAction.ID, RenameTerminalQuickOpenAction.LABEL, context.element));
actions.push(this.instantiationService.createInstance(QuickKillTerminalAction, QuickKillTerminalAction.ID, QuickKillTerminalAction.LABEL, context.element));
......
......@@ -50,12 +50,12 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
public configFontIsMonospace(): boolean {
this._createCharMeasureElementIfNecessary();
let fontSize = 15;
let fontFamily = this.config.fontFamily || this._configurationService.getValue<IEditorOptions>('editor').fontFamily;
let i_rect = this._getBoundingRectFor('i', fontFamily, fontSize);
let w_rect = this._getBoundingRectFor('w', fontFamily, fontSize);
const fontSize = 15;
const fontFamily = this.config.fontFamily || this._configurationService.getValue<IEditorOptions>('editor').fontFamily;
const i_rect = this._getBoundingRectFor('i', fontFamily, fontSize);
const w_rect = this._getBoundingRectFor('w', fontFamily, fontSize);
let invalidBounds = !i_rect.width || !w_rect.width;
const invalidBounds = !i_rect.width || !w_rect.width;
if (invalidBounds) {
// There is no reason to believe the font is not Monospace.
return true;
......@@ -88,7 +88,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
private _measureFont(fontFamily: string, fontSize: number, letterSpacing: number, lineHeight: number): ITerminalFont {
this._createCharMeasureElementIfNecessary();
let rect = this._getBoundingRectFor('X', fontFamily, fontSize);
const rect = this._getBoundingRectFor('X', fontFamily, fontSize);
// Bounding client rect was invalid, use last font measurement if available.
if (this._lastFontMeasurement && !rect.width && !rect.height) {
......@@ -122,7 +122,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
}
}
let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
const fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
const letterSpacing = this.config.letterSpacing ? Math.max(Math.floor(this.config.letterSpacing), MINIMUM_LETTER_SPACING) : DEFAULT_LETTER_SPACING;
const lineHeight = this.config.lineHeight ? Math.max(this.config.lineHeight, 1) : DEFAULT_LINE_HEIGHT;
......
......@@ -438,7 +438,7 @@ export class TerminalInstance implements ITerminalInstance {
}
private _measureRenderTime(): void {
let frameTimes: number[] = [];
const frameTimes: number[] = [];
const textRenderLayer = (<any>this._xterm).renderer._renderLayers[0];
const originalOnGridChanged = textRenderLayer.onGridChanged;
......
......@@ -172,7 +172,7 @@ export class TerminalLinkHandler {
}
private _handleHypertextLink(url: string): void {
let uri = Uri.parse(url);
const uri = Uri.parse(url);
this._openerService.open(uri);
}
......
......@@ -79,7 +79,7 @@ export class TerminalPanel extends Panel {
}
if (e.affectsConfiguration('terminal.integrated.fontFamily') || e.affectsConfiguration('editor.fontFamily')) {
let configHelper = this._terminalService.configHelper;
const configHelper = this._terminalService.configHelper;
if (configHelper instanceof TerminalConfigHelper) {
if (!configHelper.configFontIsMonospace()) {
const choices: IPromptChoice[] = [{
......@@ -226,7 +226,7 @@ export class TerminalPanel extends Panel {
this._terminalService.getActiveInstance().focus();
} else if (event.which === 3) {
if (this._terminalService.configHelper.config.rightClickBehavior === 'copyPaste') {
let terminal = this._terminalService.getActiveInstance();
const terminal = this._terminalService.getActiveInstance();
if (terminal.hasSelection()) {
terminal.copySelection();
terminal.clearSelection();
......@@ -253,7 +253,7 @@ export class TerminalPanel extends Panel {
}
if (event.which === 1) {
let terminal = this._terminalService.getActiveInstance();
const terminal = this._terminalService.getActiveInstance();
if (terminal.hasSelection()) {
terminal.copySelection();
}
......@@ -263,7 +263,7 @@ export class TerminalPanel extends Panel {
this._register(dom.addDisposableListener(this._parentDomElement, 'contextmenu', (event: MouseEvent) => {
if (!this._cancelContextMenu) {
const standardEvent = new StandardMouseEvent(event);
let anchor: { x: number, y: number } = { x: standardEvent.posx, y: standardEvent.posy };
const anchor: { x: number, y: number } = { x: standardEvent.posx, y: standardEvent.posy };
this._contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => TPromise.as(this._getContextMenuActions()),
......@@ -292,7 +292,7 @@ export class TerminalPanel extends Panel {
// Check if files were dragged from the tree explorer
let path: string;
let resources = e.dataTransfer.getData(DataTransfers.RESOURCES);
const resources = e.dataTransfer.getData(DataTransfers.RESOURCES);
if (resources) {
path = URI.parse(JSON.parse(resources)[0]).path;
} else if (e.dataTransfer.files.length > 0) {
......@@ -338,15 +338,15 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
}
// Borrow the editor's hover background for now
let hoverBackground = theme.getColor(editorHoverBackground);
const hoverBackground = theme.getColor(editorHoverBackground);
if (hoverBackground) {
collector.addRule(`.monaco-workbench .panel.integrated-terminal .terminal-message-widget { background-color: ${hoverBackground}; }`);
}
let hoverBorder = theme.getColor(editorHoverBorder);
const hoverBorder = theme.getColor(editorHoverBorder);
if (hoverBorder) {
collector.addRule(`.monaco-workbench .panel.integrated-terminal .terminal-message-widget { border: 1px solid ${hoverBorder}; }`);
}
let hoverForeground = theme.getColor(editorForeground);
const hoverForeground = theme.getColor(editorForeground);
if (hoverForeground) {
collector.addRule(`.monaco-workbench .panel.integrated-terminal .terminal-message-widget { color: ${hoverForeground}; }`);
}
......
......@@ -112,7 +112,7 @@ export class TerminalService extends AbstractTerminalService implements ITermina
public focusFindWidget(): TPromise<void> {
return this.showPanel(false).then(() => {
let panel = this._panelService.getActivePanel() as TerminalPanel;
const panel = this._panelService.getActivePanel() as TerminalPanel;
panel.focusFindWidget();
this._findWidgetVisible.set(true);
});
......
......@@ -194,7 +194,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
if (this._currentMarker === Boundary.Bottom) {
this._currentMarker = this._xterm.addMarker(this._getOffset() - 1);
} else {
let offset = this._getOffset();
const offset = this._getOffset();
if (this._isDisposable) {
this._currentMarker.dispose();
}
......@@ -217,7 +217,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
if (this._currentMarker === Boundary.Top) {
this._currentMarker = this._xterm.addMarker(this._getOffset() + 1);
} else {
let offset = this._getOffset();
const offset = this._getOffset();
if (this._isDisposable) {
this._currentMarker.dispose();
}
......
......@@ -25,9 +25,9 @@ export function mergeEnvironments(parent: IStringDictionary<string>, other: IStr
// On Windows apply the new values ignoring case, while still retaining
// the case of the original key.
if (platform.isWindows) {
for (let configKey in other) {
for (const configKey in other) {
let actualKey = configKey;
for (let envKey in parent) {
for (const envKey in parent) {
if (configKey.toLowerCase() === envKey.toLowerCase()) {
actualKey = envKey;
break;
......
......@@ -9,7 +9,7 @@ import * as pty from 'node-pty';
// The pty process needs to be run in its own child process to get around maxing out CPU on Mac,
// see https://github.com/electron/electron/issues/38
var shellName: string;
let shellName: string;
if (os.platform() === 'win32') {
shellName = path.basename(process.env.PTYSHELL);
} else {
......@@ -17,12 +17,12 @@ if (os.platform() === 'win32') {
// color prompt as defined in the default ~/.bashrc file.
shellName = 'xterm-256color';
}
var shell = process.env.PTYSHELL;
var args = getArgs();
var cwd = process.env.PTYCWD;
var cols = process.env.PTYCOLS;
var rows = process.env.PTYROWS;
var currentTitle = '';
const shell = process.env.PTYSHELL;
const args = getArgs();
const cwd = process.env.PTYCWD;
const cols = process.env.PTYCOLS;
const rows = process.env.PTYROWS;
let currentTitle = '';
setupPlanB(Number(process.env.PTYPID));
cleanEnv();
......@@ -34,7 +34,7 @@ interface IOptions {
rows?: number;
}
var options: IOptions = {
const options: IOptions = {
name: shellName,
cwd
};
......@@ -43,10 +43,10 @@ if (cols && rows) {
options.rows = parseInt(rows, 10);
}
var ptyProcess = pty.spawn(shell, args, options);
const ptyProcess = pty.spawn(shell, args, options);
var closeTimeout: number;
var exitCode: number;
let closeTimeout: number;
let exitCode: number;
// Allow any trailing data events to be sent before the exit event is sent.
// See https://github.com/Tyriar/node-pty/issues/72
......@@ -95,8 +95,8 @@ function getArgs(): string | string[] {
if (process.env['PTYSHELLCMDLINE']) {
return process.env['PTYSHELLCMDLINE'];
}
var args = [];
var i = 0;
const args = [];
let i = 0;
while (process.env['PTYSHELLARG' + i]) {
args.push(process.env['PTYSHELLARG' + i]);
i++;
......@@ -105,7 +105,7 @@ function getArgs(): string | string[] {
}
function cleanEnv() {
var keys = [
const keys = [
'AMD_ENTRYPOINT',
'ELECTRON_NO_ASAR',
'ELECTRON_RUN_AS_NODE',
......@@ -123,7 +123,7 @@ function cleanEnv() {
delete process.env[key];
}
});
var i = 0;
let i = 0;
while (process.env['PTYSHELLARG' + i]) {
delete process.env['PTYSHELLARG' + i];
i++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册