Skip to content

Commit

Permalink
Merge branch 'main' into update_plugin_webview
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii committed Feb 3, 2025
2 parents eaa9bbd + d783854 commit 3f642ab
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 53 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"activationEvents": [
"onLanguage:yaml",
"onLanguage:yml",
"workspaceContains:tox-ansible.ini",
"onWebviewPanel:ansible-home"
],
Expand Down Expand Up @@ -444,6 +445,10 @@
{
"command": "ansible.open-language-server-logs",
"title": "Ansible: Open Language Server Logs"
},
{
"command": "extension.buildExecutionEnvironment",
"title": "Build Ansible execution environment"
}
],
"configuration": [
Expand Down Expand Up @@ -795,13 +800,23 @@
"group": "2_main@1",
"command": "ansible.lightspeed.playbookExplanation",
"when": "redhat.ansible.lightspeedSuggestionsEnabled && editorLangId == ansible"
},
{
"when": "resourceFilename == 'execution-environment.yml' || resourceFilename == 'execution-environment.yaml'",
"command": "extension.buildExecutionEnvironment",
"group": "navigation"
}
],
"explorer/context": [
{
"group": "2_main@1",
"submenu": "ansible.playbook.run",
"when": "isFileSystemResource && resourceLangId == ansible"
},
{
"when": "resourceFilename == 'execution-environment.yml' || resourceFilename == 'execution-environment.yaml'",
"command": "extension.buildExecutionEnvironment",
"group": "navigation"
}
],
"view/title": [
Expand Down
14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { PlaybookFeedbackEvent } from "./interfaces/lightspeed";
import { CreateDevfile } from "./features/contentCreator/createDevfilePage";
import { CreateSampleExecutionEnv } from "./features/contentCreator/createSampleExecutionEnvPage";
import { CreateDevcontainer } from "./features/contentCreator/createDevcontainerPage";
import { rightClickEEBuildCommand } from "./features/utils/buildExecutionEnvironment";

export let client: LanguageClient;
export let lightSpeedManager: LightSpeedManager;
Expand Down Expand Up @@ -146,7 +147,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
// handle python status bar
const pythonInterpreterManager = new PythonInterpreterManager(
context,
client,
telemetry,
extSettings,
);
Expand All @@ -159,15 +159,14 @@ export async function activate(context: ExtensionContext): Promise<void> {
/**
* Handle "Ansible Lightspeed" in the extension
*/
lightSpeedManager = new LightSpeedManager(
context,
client,
extSettings,
telemetry,
);
lightSpeedManager = new LightSpeedManager(context, extSettings, telemetry);

vscode.commands.executeCommand("setContext", "lightspeedConnectReady", true);

const eeBuilderCommand = rightClickEEBuildCommand(
"extension.buildExecutionEnvironment",
);

context.subscriptions.push(
vscode.commands.registerCommand(
LightSpeedCommands.LIGHTSPEED_STATUS_BAR_CLICK,
Expand Down Expand Up @@ -827,6 +826,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
lsOutputChannel.show();
}),
);
context.subscriptions.push(eeBuilderCommand);
}

const startClient = async (
Expand Down
1 change: 1 addition & 0 deletions src/features/contentCreator/addPluginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class AddPlugin {
<vscode-single-select id="plugin-dropdown">
<vscode-option>filter</vscode-option>
<vscode-option>lookup</vscode-option>
<vscode-option>action</vscode-option>
</vscode-single-select>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/features/contentCreator/createDevcontainerPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class CreateDevcontainer {
</vscode-button>
<vscode-button id="open-file-button" form="devcontainer-form" disabled>
<span class="codicon codicon-go-to-file"></span>
&nbsp; Explore Devcontainer
&nbsp; Open Devcontainer
</vscode-button>
</div>
</section>
Expand Down
4 changes: 2 additions & 2 deletions src/features/contentCreator/createSampleExecutionEnvPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CreateSampleExecutionEnv {
<body>
<div class="title-div">
<h1>Create a sample Ansible Execution Environment file</h1>
<h1>Create a sample Ansible execution environment file</h1>
<p class="subtitle">Streamlining automation</p>
</div>
Expand Down Expand Up @@ -175,7 +175,7 @@ export class CreateSampleExecutionEnv {
</vscode-button>
<vscode-button id="open-file-button" form="init-form" disabled>
<span class="codicon codicon-go-to-file"></span>
&nbsp; Open Execution Environment file
&nbsp; Open Execution environment file
</vscode-button>
</div>
</section>
Expand Down
6 changes: 0 additions & 6 deletions src/features/lightspeed/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { LightSpeedAPI } from "./api";
import { TelemetryManager } from "../../utils/telemetryUtils";
import { SettingsManager } from "../../settings";
Expand All @@ -25,7 +24,6 @@ import { LightspeedExplorerWebviewViewProvider } from "./explorerWebviewViewProv

export class LightSpeedManager {
private context;
public client;
public settingsManager: SettingsManager;
public telemetry: TelemetryManager;
public apiInstance: LightSpeedAPI;
Expand All @@ -43,12 +41,10 @@ export class LightSpeedManager {

constructor(
context: vscode.ExtensionContext,
client: LanguageClient,
settingsManager: SettingsManager,
telemetry: TelemetryManager,
) {
this.context = context;
this.client = client;
this.settingsManager = settingsManager;
this.telemetry = telemetry;
this.lightSpeedActivityTracker = {};
Expand Down Expand Up @@ -78,7 +74,6 @@ export class LightSpeedManager {
);
this.contentMatchesProvider = new ContentMatchesWebview(
this.context,
this.client,
this.settingsManager,
this.apiInstance,
this.lightspeedAuthenticatedUser,
Expand All @@ -89,7 +84,6 @@ export class LightSpeedManager {
this.apiInstance,
this.lightspeedAuthenticatedUser,
context,
client,
settingsManager,
);

Expand Down
17 changes: 1 addition & 16 deletions src/features/lightspeed/contentMatchesWebview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { LightSpeedAPI } from "./api";
import { SettingsManager } from "../../settings";
import {
Expand All @@ -10,7 +9,6 @@ import {
IContentMatchParams,
ISuggestionDetails,
} from "../../interfaces/lightspeed";
import { getCurrentUTCDateTime } from "../utils/dateTime";
import * as yaml from "yaml";
import { LightspeedUser } from "./lightspeedUser";
import { parsePlays } from "./utils/parsePlays";
Expand All @@ -22,20 +20,17 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
private _extensionUri: vscode.Uri;
private context;
private lightspeedAuthenticatedUser: LightspeedUser;
public client;
public settingsManager: SettingsManager;
public apiInstance: LightSpeedAPI;
public suggestionDetails: ISuggestionDetails[] = [];

constructor(
context: vscode.ExtensionContext,
client: LanguageClient,
settingsManager: SettingsManager,
apiInstance: LightSpeedAPI,
lightspeedAuthenticatedUser: LightspeedUser,
) {
this.context = context;
this.client = client;
this.settingsManager = settingsManager;
this.apiInstance = apiInstance;
this._extensionUri = context.extensionUri;
Expand Down Expand Up @@ -83,19 +78,9 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
contentMatchesRequestData.model = model;
}

this.client.outputChannel?.appendLine(
`${getCurrentUTCDateTime().toISOString()}: request content matches from Ansible Lightspeed:\n${JSON.stringify(
contentMatchesRequestData,
)}`,
);

const outputData: ContentMatchesResponseParams | IError =
await this.apiInstance.contentMatchesRequest(contentMatchesRequestData);
this.client.outputChannel?.appendLine(
`${getCurrentUTCDateTime().toISOString()}: response data from Ansible lightspeed:\n${JSON.stringify(
outputData,
)}`,
);

return outputData;
}

Expand Down
7 changes: 0 additions & 7 deletions src/features/lightspeed/statusBar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { LightSpeedAPI } from "./api";
import { SettingsManager } from "../../settings";
import {
Expand All @@ -15,21 +14,18 @@ export class LightspeedStatusBar {
private apiInstance: LightSpeedAPI;
private lightspeedAuthenticatedUser: LightspeedUser;
private context;
public client;
public settingsManager: SettingsManager;
public statusBar: vscode.StatusBarItem;

constructor(
apiInstance: LightSpeedAPI,
lightspeedAuthenticatedUser: LightspeedUser,
context: vscode.ExtensionContext,
client: LanguageClient,
settingsManager: SettingsManager,
) {
this.apiInstance = apiInstance;
this.lightspeedAuthenticatedUser = lightspeedAuthenticatedUser;
this.context = context;
this.client = client;
this.settingsManager = settingsManager;
// create a new project lightspeed status bar item that we can manage
this.statusBar = this.initialiseStatusBar();
Expand Down Expand Up @@ -73,9 +69,6 @@ export class LightspeedStatusBar {
}

private handleStatusBar() {
if (!this.client.isRunning()) {
return;
}
try {
this.getLightSpeedStatusBarText().then((text) => {
this.statusBar.text = text;
Expand Down
7 changes: 0 additions & 7 deletions src/features/pythonMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ import {
ThemeColor,
workspace,
} from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { TelemetryManager } from "../utils/telemetryUtils";
import { SettingsManager } from "../settings";
import { AnsibleCommands } from "../definitions/constants";
import { execSync } from "child_process";

export class PythonInterpreterManager {
private context;
private client;
private pythonInterpreterStatusBarItem: StatusBarItem;
private telemetry: TelemetryManager;
private extensionSettings: SettingsManager;

constructor(
context: ExtensionContext,
client: LanguageClient,
telemetry: TelemetryManager,
extensionSettings: SettingsManager,
) {
this.context = context;
this.client = client;
this.telemetry = telemetry;
this.extensionSettings = extensionSettings;

Expand Down Expand Up @@ -62,9 +58,6 @@ export class PythonInterpreterManager {
* and receives notification from the server with ansible meta data associated with the opened file as param
*/
public async updatePythonInfo(): Promise<void> {
if (!this.client.isRunning()) {
return;
}
this.pythonInterpreterStatusBarItem.tooltip = new MarkdownString(
` Change environment `,
true,
Expand Down
2 changes: 1 addition & 1 deletion src/features/quickLinks/quickLinksView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function getWebviewQuickLinks(webview: Webview, extensionUri: Uri) {
<div class="catalogue">
<h3>
<a href="command:ansible.content-creator.create-sample-execution-env-file" title="Create a sample Execution Environment file.">
<span class="codicon codicon-new-file"></span> Execution environment template
<span class="codicon codicon-new-file"></span> Execution environment
<span class="new-badge">NEW</span>
</a>
</h3>
Expand Down
70 changes: 70 additions & 0 deletions src/features/utils/buildExecutionEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as vscode from "vscode";
import * as path from "path";
import { withInterpreter } from "../utils/commandRunner";
import { SettingsManager } from "../../settings";
import { runCommand } from "../contentCreator/utils";

export function rightClickEEBuildCommand(commandId: string): vscode.Disposable {
return vscode.commands.registerCommand(commandId, async (uri: vscode.Uri) => {
if (!uri?.fsPath) {
const getFileFromEditor = vscode.window.activeTextEditor;
if (!getFileFromEditor) {
vscode.window.showErrorMessage(
"No file selected and no active file found!",
);
return;
}
const filePath = getFileFromEditor.document.uri.fsPath;
if (
!filePath.endsWith("execution-environment.yml") &&
!filePath.endsWith("execution-environment.yaml")
) {
vscode.window.showErrorMessage(
"Active file is not an execution environment file!",
);
return;
}
uri = getFileFromEditor.document.uri;
}

const filePath = uri.fsPath;
const dirPath = path.dirname(filePath);

const builderCommand = `ansible-builder build -f ${filePath} -c ${dirPath}/context`;

vscode.window.showInformationMessage(`Running: ${builderCommand}`);

if (!dirPath) {
vscode.window.showErrorMessage("Could not determine workspace folder.");
return;
}

try {
const extSettings = new SettingsManager();
await extSettings.initialize();

const { command, env } = withInterpreter(
extSettings.settings,
builderCommand,
"",
);

const result = await runCommand(command, env);

if (result.status === "failed") {
vscode.window.showErrorMessage(
`Build failed with status ${result.status}: \n${result.output.trim()}`,
);
return;
}

vscode.window.showInformationMessage(
`Build successful:\n${result.output.trim()}`,
);
} catch (error) {
vscode.window.showErrorMessage(
`Unexpected error: ${(error as Error).message}`,
);
}
});
}
Loading

0 comments on commit 3f642ab

Please sign in to comment.