Skip to content

Commit 7d2fce0

Browse files
committed
Add some types and check, better behavior when fpDebug not installed
1 parent 8136b2d commit 7d2fce0

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ See `scripts` in `package.json`.
3838
```
3939
npm run compile
4040
npm run lint
41-
npm run test
41+
npm run test # actually this already runs 2 commands above, and more
4242
```
4343

4444
# Helpful information from the original README.md

src/castleDebugProvider.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class CastleDebugProvider implements vscode.DebugConfigurationProvider
2626
return [config];
2727
} else {
2828
//console.log('CastleDebugProvider.provideDebugConfigurations, returning 0 configs, debugging is NOT available');
29-
return undefined;
29+
return [];
3030
}
3131
}
3232

@@ -46,7 +46,7 @@ export class CastleDebugProvider implements vscode.DebugConfigurationProvider
4646
* Return DebugConfiguration representing debugging current application
4747
* using fpDebug.
4848
*/
49-
private async getDebugConfig(): Promise<vscode.DebugConfiguration>
49+
private async getDebugConfig(): Promise<vscode.DebugConfiguration | undefined>
5050
{
5151
let result: vscode.DebugConfiguration = {
5252
type: 'fpDebug', // castleDebug is used only as alias for fpDebug
@@ -62,19 +62,24 @@ export class CastleDebugProvider implements vscode.DebugConfigurationProvider
6262
// debug configuration provider is created and
6363
// new configuration can be not valid when buildToolPath === ''
6464
if (this._castleConfig.buildToolPath === '') {
65-
console.log('resolveDebugConfiguration aborted - cannot find build tool');
65+
console.log('getDebugConfig aborted - cannot find build tool');
6666
return undefined; // abort launch
6767
}
6868

6969
let executableName: string = await castleExec.executeFileAndReturnValue(
7070
this._castleConfig.buildToolPath, ['output', 'executable-name']);
7171
executableName = executableName + castlePath.exeExtension();
7272
result.program = '${workspaceFolder}/' + executableName;
73-
//console.log('resolveDebugConfiguration got program name as ' + result.program);
73+
//console.log('getDebugConfig got program name as ' + result.program);
7474

7575
// workaround fpDebug 0.6 bug with fpdserver executable not set properly
7676
if (process.platform === 'win32') {
77-
let fpDebugExtPath = vscode.extensions.getExtension("cnoc.fpdebug").extensionPath;
77+
let fpDebugExtension: vscode.Extension<any> | undefined = vscode.extensions.getExtension("cnoc.fpdebug");
78+
if (fpDebugExtension === undefined) {
79+
console.log('getDebugConfig aborted - fpDebug not installed');
80+
return undefined; // abort launch
81+
}
82+
let fpDebugExtPath = fpDebugExtension.extensionPath;
7883
if (this._castleConfig.fpcTargetCpu === 'x86_64') {
7984
result.fpdserver = { executable: fpDebugExtPath + '\\bin\\fpdserver-x86_64.exe' };
8085
} else if (this._castleConfig.fpcTargetCpu === 'i386') {

src/castleStatusBar.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as vscode from 'vscode';
22
import { CastleConfiguration, CastleBuildModes } from './castleConfiguration';
3+
import { CastlePascalLanguageServer } from './castlePascalLanguageServer';
4+
import { CastleTaskProvider } from './castleTaskProvider';
35
import * as castlePath from './castlePath';
46

5-
export class CastleStatusBar {
6-
private _castleConfig;
7-
private _context;
8-
private _castleLanguageServer;
9-
private _castleTaskProvider;
7+
export class CastleStatusBar
8+
{
9+
private _castleConfig: CastleConfiguration;
10+
private _context: vscode.ExtensionContext;
11+
private _castleLanguageServer: CastlePascalLanguageServer;
12+
private _castleTaskProvider: CastleTaskProvider;
1013
private _buildModesButton: vscode.StatusBarItem;
1114
private _compileButton: vscode.StatusBarItem;
1215
private _runButton: vscode.StatusBarItem;
@@ -17,12 +20,9 @@ export class CastleStatusBar {
1720

1821
/**
1922
* Constructor
20-
* @param {vscode.ExtensionContext} context
21-
* @param {castleConfiguration.CastleConfiguration} castleConfig
22-
* @param {castleLanguageServer.castleLanguageServer} castleLanguageServer
23-
* @param {CastleTaskProvider.castleTaskProvider} castleTaskProvider
2423
*/
25-
constructor(context, castleConfig, castleLanguageServer, castleTaskProvider) {
24+
constructor(context: vscode.ExtensionContext, castleConfig: CastleConfiguration, castleLanguageServer: CastlePascalLanguageServer, castleTaskProvider: CastleTaskProvider)
25+
{
2626
this._castleConfig = castleConfig;
2727
this._context = context;
2828
this._castleLanguageServer = castleLanguageServer;
@@ -37,7 +37,8 @@ export class CastleStatusBar {
3737
this.updateButtonsVisibility();
3838
}
3939

40-
createBuildModeSwitch() {
40+
private createBuildModeSwitch(): void
41+
{
4142
let command = vscode.commands.registerCommand(this._castleConfig.commandId.showBuildModes, async () => {
4243
const chosenBuildMode = await vscode.window.showQuickPick(['Debug', 'Release'], { placeHolder: 'Select build type' });
4344
if (!chosenBuildMode === undefined) {
@@ -61,11 +62,13 @@ export class CastleStatusBar {
6162
this._buildModesButton.tooltip = 'Click to select build mode (debug or release)';
6263
}
6364

64-
updateBuildModesButtonText() {
65+
private updateBuildModesButtonText(): void
66+
{
6567
this._buildModesButton.text = 'CGE: [' + this._castleConfig.buildMode.name + ']';
6668
}
6769

68-
createCompileButton() {
70+
private createCompileButton(): void
71+
{
6972
this._compileButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 19);
7073
this._context.subscriptions.push(this._compileButton);
7174
this._compileButton.command = this._castleConfig.commandId.compile;
@@ -74,7 +77,8 @@ export class CastleStatusBar {
7477
this._compileButton.show();
7578
}
7679

77-
createDebugButton() {
80+
private createDebugButton(): void
81+
{
7882
this._debugButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 18);
7983
this._context.subscriptions.push(this._runButton);
8084
this._debugButton.command = this._castleConfig.commandId.debug;
@@ -83,7 +87,8 @@ export class CastleStatusBar {
8387
this._debugButton.show();
8488
}
8589

86-
createRunButton() {
90+
private createRunButton(): void
91+
{
8792
this._runButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 18);
8893
this._context.subscriptions.push(this._runButton);
8994
this._runButton.command = this._castleConfig.commandId.run;
@@ -92,7 +97,8 @@ export class CastleStatusBar {
9297
this._runButton.show();
9398
}
9499

95-
createCleanButton() {
100+
private createCleanButton(): void
101+
{
96102
this._cleanButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 18);
97103
this._context.subscriptions.push(this._cleanButton);
98104
this._cleanButton.command = this._castleConfig.commandId.clean;
@@ -101,7 +107,8 @@ export class CastleStatusBar {
101107
this._cleanButton.show();
102108
}
103109

104-
createOpenInEditorButton() {
110+
private createOpenInEditorButton(): void
111+
{
105112
this._openInEditorButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 18);
106113
this._context.subscriptions.push(this._openInEditorButton);
107114
this._openInEditorButton.command = this._castleConfig.commandId.openInCastleEditor;
@@ -110,7 +117,8 @@ export class CastleStatusBar {
110117
this._openInEditorButton.show();
111118
}
112119

113-
createConfigErrorButton() {
120+
private createConfigErrorButton(): void
121+
{
114122
this._openSettingsButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 18);
115123
this._context.subscriptions.push(this._openSettingsButton);
116124
this._openSettingsButton.command = this._castleConfig.commandId.validateAndOpenSettings;
@@ -120,7 +128,8 @@ export class CastleStatusBar {
120128
this._openSettingsButton.show();
121129
}
122130

123-
updateButtonsVisibility() {
131+
private updateButtonsVisibility(): void
132+
{
124133
let cgeFolder = castlePath.bestWorkspaceFolderStrict();
125134
if (cgeFolder === undefined) {
126135
/* Not a CGE project, so don't show any status buttons.

0 commit comments

Comments
 (0)