Skip to content

Commit

Permalink
Add refresh button to process picker (#2895)
Browse files Browse the repository at this point in the history
* Add attach QuickView with refresh

* vscode engine 1.23 -> 1.26

* Clean up disposables

* Add entry to CHANGELOG

* Provide refresh image for dark and light themes

* Add title to QuickPick
  • Loading branch information
mbise1993 authored and WardenGnaw committed Dec 10, 2018
1 parent 8c53c02 commit bb962b9
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# C/C++ for Visual Studio Code Change Log

* Add refresh button to process picker. [#2885](https://github.com/Microsoft/vscode-cpptools/issues/2885)

## Version 0.21.0-insiders2: November 20, 2018
* Fix some IntelliSense process crashes. [#1785](https://github.com/Microsoft/vscode-cpptools/issues/1785)
* Fix incorrect IntelliSense error with Mac clang 10.0 libraries. [#2608](https://github.com/Microsoft/vscode-cpptools/issues/2608)
Expand Down
1 change: 1 addition & 0 deletions Extension/assets/Refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Extension/assets/Refresh_inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
"vscode": "^1.23.0"
"vscode": "^1.26.0"
},
"bugs": {
"url": "https://github.com/Microsoft/vscode-cpptools/issues",
Expand Down
70 changes: 70 additions & 0 deletions Extension/src/Debugger/attachQuickPick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as util from '../common';
import * as vscode from 'vscode';

class RefreshButton implements vscode.QuickInputButton {
get iconPath(): { dark: vscode.Uri; light: vscode.Uri } {
const refreshImagePathDark: string = util.getExtensionFilePath("assets/Refresh_inverse.svg");
const refreshImagePathLight: string = util.getExtensionFilePath("assets/Refresh.svg");

return {
dark: vscode.Uri.file(refreshImagePathDark),
light: vscode.Uri.file(refreshImagePathLight)
};
}

get tooltip(): string {
return "Refresh process list";
}
}

export interface AttachItem extends vscode.QuickPickItem {
id: string;
}

export function showQuickPick(getAttachItems: () => Promise<AttachItem[]>): Promise<string> {
return getAttachItems().then(processEntries => {
return new Promise<string>((resolve, reject) => {
let quickPick: vscode.QuickPick<AttachItem> = vscode.window.createQuickPick<AttachItem>();
quickPick.title = "Attach to process";
quickPick.canSelectMany = false;
quickPick.matchOnDescription = true;
quickPick.matchOnDetail = true;
quickPick.placeholder = "Select the process to attach to";
quickPick.items = processEntries;
quickPick.buttons = [new RefreshButton()];

let disposables: vscode.Disposable[] = [];

quickPick.onDidTriggerButton(button => {
getAttachItems().then(processEntries => quickPick.items = processEntries);
}, undefined, disposables);

quickPick.onDidAccept(() => {
if (quickPick.selectedItems.length !== 1) {
reject(new Error("Process not selected"));
}

let selectedId: string = quickPick.selectedItems[0].id;

disposables.forEach(item => item.dispose());
quickPick.dispose();

resolve(selectedId);
}, undefined, disposables);

quickPick.onDidHide(() => {
disposables.forEach(item => item.dispose());
quickPick.dispose();

reject(new Error("Process not selected."));
}, undefined, disposables);

quickPick.show();
});
});
}
23 changes: 4 additions & 19 deletions Extension/src/Debugger/attachToProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { execChildProcess } from '../common';
import { PsProcessParser } from './nativeAttach';
import { AttachItem, showQuickPick } from './attachQuickPick';

import * as debugUtils from './utils';
import * as fs from 'fs';
Expand All @@ -13,10 +14,6 @@ import * as path from 'path';
import * as util from '../common';
import * as vscode from 'vscode';

export interface AttachItem extends vscode.QuickPickItem {
id: string;
}

export interface AttachItemsProvider {
getAttachItems(): Promise<AttachItem[]>;
}
Expand All @@ -29,19 +26,7 @@ export class AttachPicker {
if (!ready) {
util.displayExtensionNotReadyPrompt();
} else {
return this.attachItemsProvider.getAttachItems()
.then(processEntries => {
let attachPickOptions: vscode.QuickPickOptions = {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: "Select the process to attach to"
};

return vscode.window.showQuickPick(processEntries, attachPickOptions)
.then(chosenProcess => {
return chosenProcess ? chosenProcess.id : Promise.reject<string>(new Error("Process not selected."));
});
});
return showQuickPick(() => this.attachItemsProvider.getAttachItems());
}
});
}
Expand Down Expand Up @@ -74,7 +59,7 @@ export class RemoteAttachPicker {
!fs.existsSync(pipeTransport.pipeProgram)) {
const pipeProgramStr: string = pipeTransport.pipeProgram.toLowerCase().trim();
const expectedArch: debugUtils.ArchType = debugUtils.ArchType[process.arch];

// Check for pipeProgram
if (!fs.existsSync(config.pipeTransport.pipeProgram)) {
pipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(pipeProgramStr, expectedArch);
Expand All @@ -84,7 +69,7 @@ export class RemoteAttachPicker {
if (!pipeProgram && config.pipeTransport.pipeCwd) {
const pipeCwdStr: string = config.pipeTransport.pipeCwd.toLowerCase().trim();
const newPipeProgramStr: string = path.join(pipeCwdStr, pipeProgramStr);

if (!fs.existsSync(newPipeProgramStr)) {
pipeProgram = debugUtils.ArchitectureReplacer.checkAndReplaceWSLPipeProgram(newPipeProgramStr, expectedArch);
}
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/Debugger/nativeAttach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import * as child_process from 'child_process';
import * as os from 'os';
import { AttachItem, AttachItemsProvider } from './attachToProcess';
import { AttachItemsProvider } from './attachToProcess';
import { AttachItem } from './attachQuickPick';

class Process {
constructor(public name: string, public pid: string, public commandLine: string) { }
Expand Down

0 comments on commit bb962b9

Please sign in to comment.