Skip to content

Commit 070f5fc

Browse files
committed
(GH-61) Add click menu to Puppet status bar
Previously there was no way to restart the Language Client or view the Puppet Client logs easily. This commit adds a click menu which displays an option to either restart the Lanugage Client or view the connection logs. The location to click is on the Language Server status bar item in the bottom right corner.
1 parent 2cb85e3 commit 070f5fc

File tree

5 files changed

+71
-26
lines changed

5 files changed

+71
-26
lines changed

client/src/configuration.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
5+
import { ConnectionManager, IConnectionConfiguration, ConnectionType } from './connection';
6+
7+
export class ConnectionConfiguration implements IConnectionConfiguration {
8+
public type: ConnectionType = ConnectionType.Unknown;
9+
public host: string = undefined;
10+
public port: number = undefined;
11+
public timeout: number = undefined;
12+
public preLoadPuppet: boolean = undefined;
13+
public debugFilePath: string = undefined;
14+
public puppetAgentDir: string = undefined;
15+
16+
constructor(context: vscode.ExtensionContext) {
17+
let config = vscode.workspace.getConfiguration('puppet');
18+
19+
this.host = config['languageserver']['address'];
20+
this.port = config['languageserver']['port'];
21+
this.timeout = config['languageserver']['timeout'];
22+
this.preLoadPuppet = config['languageserver']['preLoadPuppet'];
23+
this.debugFilePath = config['languageserver']['debugFilePath'];
24+
25+
this.puppetAgentDir = config['puppetAgentDir'];
26+
}
27+
}

client/src/connection.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import vscode = require('vscode');
44
import cp = require('child_process');
55
import { Logger } from '../src/logging';
66
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
7+
import { ConnectionConfiguration } from './configuration';
78
import { setupPuppetCommands } from '../src/commands/puppetcommands';
89
import { setupPDKCommands } from '../src/commands/pdkcommands';
910
import { reporter } from './telemetry/telemetry';
@@ -39,6 +40,7 @@ export interface IConnectionConfiguration {
3940
export interface IConnectionManager {
4041
status: ConnectionStatus;
4142
languageClient: LanguageClient;
43+
showConnectionMenu();
4244
}
4345

4446
export class ConnectionManager implements IConnectionManager {
@@ -78,7 +80,7 @@ export class ConnectionManager implements IConnectionManager {
7880
this.terminal = vscode.window.createTerminal('Puppet PDK');
7981
this.terminal.processId.then(
8082
pid => {
81-
console.log("pdk shell started, pid: " + pid);
83+
this.logger.debug("pdk shell started, pid: " + pid);
8284
});
8385
setupPDKCommands(langID, this, this.extensionContext, this.logger, this.terminal);
8486
this.extensionContext.subscriptions.push(this.terminal);
@@ -395,8 +397,7 @@ export class ConnectionManager implements IConnectionManager {
395397
if (this.statusBarItem === undefined) {
396398
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1);
397399

398-
// TODO: Add a command here to show the connection menu
399-
// this.statusBarItem.command = this.ShowConnectionMenuCommandName;
400+
this.statusBarItem.command = messages.PuppetCommandStrings.PuppetShowConnectionMenuCommandId;
400401
this.statusBarItem.show();
401402
vscode.window.onDidChangeActiveTextEditor(textEditor => {
402403
if (textEditor === undefined || textEditor.document.languageId !== "puppet") {
@@ -409,6 +410,32 @@ export class ConnectionManager implements IConnectionManager {
409410
}
410411
}
411412

413+
public showConnectionMenu() {
414+
var menuItems: ConnectionMenuItem[] = [];
415+
416+
let currentConnectionConfig = this.connectionConfiguration;
417+
418+
menuItems.push(
419+
new ConnectionMenuItem(
420+
"Restart Current Puppet Session",
421+
() => {
422+
let configuration = new ConnectionConfiguration(this.extensionContext);
423+
this.restartConnection(configuration);
424+
}),
425+
)
426+
427+
menuItems.push(
428+
new ConnectionMenuItem(
429+
"Show Puppet Session Logs",
430+
() => { this.logger.show(); }),
431+
)
432+
433+
vscode
434+
.window
435+
.showQuickPick<ConnectionMenuItem>(menuItems)
436+
.then((selectedItem) => { selectedItem.callback(); });
437+
}
438+
412439
private setConnectionStatus(statusText: string, status: ConnectionStatus): void {
413440
// Set color and icon for 'Running' by default
414441
var statusIconText = "$(terminal) ";
@@ -432,3 +459,11 @@ export class ConnectionManager implements IConnectionManager {
432459
this.setConnectionStatus("Starting Error", ConnectionStatus.Failed);
433460
}
434461
}
462+
463+
class ConnectionMenuItem implements vscode.QuickPickItem {
464+
public description: string;
465+
466+
constructor(public readonly label: string, public readonly callback: () => void = () => { })
467+
{
468+
}
469+
}

client/src/extension.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode';
44
import * as path from 'path';
55

66
import { ConnectionManager, IConnectionConfiguration, ConnectionType } from './connection';
7+
import { ConnectionConfiguration } from './configuration';
78
import { Logger } from './logging';
89
import { Reporter } from './telemetry/telemetry';
910

@@ -13,28 +14,6 @@ var serverProc;
1314

1415
var connManager: ConnectionManager = undefined;
1516

16-
export class ConnectionConfiguration implements IConnectionConfiguration {
17-
public type: ConnectionType = ConnectionType.Unknown;
18-
public host: string = undefined;
19-
public port: number = undefined;
20-
public timeout: number = undefined;
21-
public preLoadPuppet: boolean = undefined;
22-
public debugFilePath: string = undefined;
23-
public puppetAgentDir: string = undefined;
24-
25-
constructor(context: vscode.ExtensionContext) {
26-
let config = vscode.workspace.getConfiguration('puppet');
27-
28-
this.host = config['languageserver']['address'];
29-
this.port = config['languageserver']['port'];
30-
this.timeout = config['languageserver']['timeout'];
31-
this.preLoadPuppet = config['languageserver']['preLoadPuppet'];
32-
this.debugFilePath = config['languageserver']['debugFilePath'];
33-
34-
this.puppetAgentDir = config['puppetAgentDir'];
35-
}
36-
}
37-
3817
export function activate(context: vscode.ExtensionContext) {
3918
const puppetExtension = vscode.extensions.getExtension('jpogran.puppet-vscode')!;
4019
const puppetExtensionVersion = puppetExtension.packageJSON.version;

client/src/logging.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export class Logger {
1919

2020
constructor() {
2121
this.logChannel = vscode.window.createOutputChannel("Puppet");
22-
this.logChannel.show();
2322

2423
let config = vscode.workspace.getConfiguration('puppet');
2524
let logLevelName = config['languageclient']['minimumUserLogLevel'];
@@ -33,6 +32,10 @@ export class Logger {
3332
}
3433
}
3534

35+
public show(){
36+
this.logChannel.show();
37+
}
38+
3639
public verbose(message: string) {
3740
this.logWithLevel(LogLevel.Verbose, message);
3841
}

client/src/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface CompileNodeGraphResponse {
4040
export class PuppetCommandStrings{
4141
static PuppetResourceCommandId:string = 'extension.puppetResource';
4242
static PuppetNodeGraphToTheSideCommandId = 'extension.puppetShowNodeGraphToSide';
43+
static PuppetShowConnectionMenuCommandId = 'extension.puppetShowConnectionMenu';
4344
}
4445

4546
export class PDKCommandStrings {

0 commit comments

Comments
 (0)