+
Skip to content

Add a button to open a folder if there isn't one open #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/BaseIoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import LicenseProviderFactory from 'license/LicenseProviderFactory';
import LogFactory from 'log/LogFactory';
import LogFile from 'log/LogFile';
import LogProviderFactory from 'log/LogProviderFactory';
import NativeCommandFactory from 'job/NativeComandFactory';
import ParsedConfig from 'config/ParsedConfig';
import Persistence from 'process/Persistence';
import PipelineParameter from 'config/PipelineParameter';
Expand Down Expand Up @@ -94,6 +95,7 @@ export default class BaseIoc {
this.container.bind(LicenseInput).toSelf();
this.container.bind(LicenseProviderFactory).toSelf();
this.container.bind(LogProviderFactory).toSelf();
this.container.bind(NativeCommandFactory).toSelf();
this.container.bind(ParsedConfig).toSelf();
this.container.bind(Persistence).toSelf();
this.container.bind(PipelineParameter).toSelf();
Expand Down
26 changes: 26 additions & 0 deletions src/config/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type vscode from 'vscode';
import Types from 'common/Types';
import AllConfigFiles from './AllConfigFiles';
import EditorGateway from 'gateway/EditorGateway';
import ReporterGateway from 'gateway/ReporterGateway';
import {
CREATE_CONFIG_FILE_COMMAND,
SELECTED_CONFIG_PATH,
Expand All @@ -17,6 +18,9 @@ export default class ConfigFile {
@inject(Types.IEditorGateway)
editorGateway!: EditorGateway;

@inject(Types.IReporterGateway)
reporterGateway!: ReporterGateway;

/**
* Gets the absolute path of the selected .circleci/config.yml to run the jobs on.
*
Expand All @@ -36,6 +40,28 @@ export default class ConfigFile {
return Promise.resolve(selectedConfigPath);
}

if (!this.editorGateway.editor.workspace.workspaceFolders?.length) {
this.reporterGateway.reporter.sendTelemetryErrorEvent('noFolderOpen');

const openFolderText = 'Open folder';
this.editorGateway.editor.window
.showInformationMessage(
'Please open a folder so you can run Local CI',
{ detail: 'There is no folder selected' },
openFolderText
)
.then((clicked) => {
if (clicked === openFolderText) {
this.reporterGateway.reporter.sendTelemetryEvent('openFolder');
this.editorGateway.editor.commands.executeCommand(
'workbench.action.files.openFileFolder'
);
}
});

return '';
}

const allConfigFilePaths = await this.allConfigFiles.getPaths(context);
if (!allConfigFilePaths.length) {
const createConfigText = 'Create a config for me';
Expand Down
16 changes: 16 additions & 0 deletions src/job/Children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type vscode from 'vscode';
import CommandFactory from './ComandFactory';
import JobFactory from './JobFactory';
import JobTreeItem from './JobTreeItem';
import NativeCommandFactory from './NativeComandFactory';
import WarningFactory from './WarningFactory';
import WarningCommandFactory from './WarningCommandFactory';
import type EditorGateway from 'gateway/EditorGateway';
Expand Down Expand Up @@ -38,6 +39,9 @@ export default class Children {
@inject(LogFactory)
logFactory!: LogFactory;

@inject(NativeCommandFactory)
nativeCommandFactory!: NativeCommandFactory;

@inject(WarningCommandFactory)
warningCommandFactory!: WarningCommandFactory;

Expand Down Expand Up @@ -147,6 +151,18 @@ export default class Children {
this.commandFactory.create('Enter License', ENTER_LICENSE_COMMAND),
this.commandFactory.create('Complain To Me', COMPLAIN_COMMAND),
];
case JobError.NoFolderOpen:
return [
this.warningCommandFactory.create(
'Please open a folder',
'workbench.action.files.openFileFolder'
),
this.nativeCommandFactory.create(
'Open a folder',
'workbench.action.files.openFileFolder'
),
this.commandFactory.create('Complain to me', COMPLAIN_COMMAND),
];
case JobError.NoConfigFilePathInWorkspace:
return [
this.warningFactory.create('Error: No .circleci/config.yml found'),
Expand Down
7 changes: 7 additions & 0 deletions src/job/JobProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum JobError {
LicenseKey,
NoConfigFilePathInWorkspace,
NoConfigFilePathSelected,
NoFolderOpen,
ProcessFile,
}

Expand Down Expand Up @@ -104,6 +105,12 @@ export default class JobProvider
if (!configFilePath || !this.fsGateway.fs.existsSync(configFilePath)) {
this.reporterGateway.reporter.sendTelemetryEvent('configFilePath');

if (!this.editorGateway.editor.workspace.workspaceFolders?.length) {
this.reporterGateway.reporter.sendTelemetryErrorEvent('noFolderOpen');
this.setError(JobError.NoFolderOpen);
return;
}

const doExistConfigPaths = !!(
await this.allConfigFiles.getPaths(this.context)
).length;
Expand Down
9 changes: 9 additions & 0 deletions src/job/NativeComandFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { injectable } from 'inversify';
import NativeCommandTreeItem from './NativeCommandTreeItem';

@injectable()
export default class NativeCommandFactory {
create(label: string, command: string) {
return new NativeCommandTreeItem(label, command);
}
}
21 changes: 21 additions & 0 deletions src/job/NativeCommandTreeItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type vscode from 'vscode';

/**
* TreeItem for a native VS Code command.
*
* Simpler, as this doesn't have a running state,
* and doesn't pass arguments to command.
*/
export default class NativeCommandTreeItem implements vscode.TreeItem {
command: vscode.Command;
tooltip: string;

constructor(public label: string, commandName: string) {
this.tooltip = label;
this.command = {
command: commandName,
title: label,
tooltip: label,
};
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载