Skip to content
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

Frontend Cleanup #61

Merged
merged 4 commits into from
Aug 22, 2024
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
9 changes: 3 additions & 6 deletions src/common/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QuickPickItem, window } from 'vscode';
import * as fs from 'fs';
import { QuickPickItem, window } from 'vscode';
import * as vscode from 'vscode';

import { getWorkspaceFolders } from './vscodeapi';
import { LanguageClient, LanguageClientOptions, ServerOptions, State, integer } from 'vscode-languageclient/node';
export async function selectEnvironment() {
Expand Down Expand Up @@ -95,8 +96,4 @@ export async function executeServerDefinitionCommand(lsClient: LanguageClient |
);

}





}
23 changes: 23 additions & 0 deletions src/common/status_bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as vscode from 'vscode';
import {
getWorkspaceSettings,
} from './settings';
import { getProjectRoot } from './utilities';

export async function createStatusBar(commandName: string, serverId:string): Promise<vscode.StatusBarItem>{
// Create a status bar item
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.command = commandName;
// https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration
const projectRoot = await getProjectRoot();
const workspaceSetting = await getWorkspaceSettings(serverId, projectRoot, true);
let environment = 'base'; // todo: Assume base, better to take this from server as it could be changed in project settings.

if (workspaceSetting.environment) {
environment = workspaceSetting.environment;
}

statusBarItem.text = `$(kedro-logo) ${environment}`;
statusBarItem.show();
return statusBarItem;
}
43 changes: 13 additions & 30 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { selectEnvironment, executeServerCommand, executeServerDefinitionCommand } from './common/commands';
import * as vscode from 'vscode';
import { selectEnvironment, executeServerCommand, executeServerDefinitionCommand } from './common/commands';
import { LanguageClient } from 'vscode-languageclient/node';
import { registerLogger, traceError, traceLog, traceVerbose } from './common/log/logging';
import {
Expand All @@ -12,15 +12,10 @@ import {
resolveInterpreter,
} from './common/python';
import { restartServer } from './common/server';
import {
checkIfConfigurationChanged,
getExtensionSettings,
getGlobalSettings,
getInterpreterFromSetting,
getWorkspaceSettings,
} from './common/settings';
import { checkIfConfigurationChanged, getInterpreterFromSetting } from './common/settings';
import { loadServerDefaults } from './common/setup';
import { getLSClientTraceLevel, getProjectRoot } from './common/utilities';
import { createStatusBar } from './common/status_bar';
import { getLSClientTraceLevel } from './common/utilities';
import { createOutputChannel, onDidChangeConfiguration, registerCommand } from './common/vscodeapi';

let lsClient: LanguageClient | undefined;
Expand All @@ -31,10 +26,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
const serverName = serverInfo.name;
const serverId = serverInfo.module;

// Log Server information
traceLog(`Name: ${serverInfo.name}`);
traceLog(`Module: ${serverInfo.module}`);
traceVerbose(`Full Server Info: ${JSON.stringify(serverInfo)}`);

// List of commands
const CMD_RESTART_SERVER = `${serverId}.restart`;
const CMD_SELECT_ENV = `${serverId}.selectEnvironment`;

// Status Bar
const statusBarItem = await createStatusBar(CMD_SELECT_ENV, serverId);
context.subscriptions.push(statusBarItem);

// Setup logging
const outputChannel = createOutputChannel(serverName);
context.subscriptions.push(outputChannel, registerLogger(outputChannel));
Expand All @@ -53,11 +57,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}),
);

// Log Server information
traceLog(`Name: ${serverInfo.name}`);
traceLog(`Module: ${serverInfo.module}`);
traceVerbose(`Full Server Info: ${JSON.stringify(serverInfo)}`);

const runServer = async (selectedEnvironment?: vscode.QuickPickItem) => {
const interpreter = getInterpreterFromSetting(serverId);
let env = undefined;
Expand Down Expand Up @@ -91,22 +90,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
);
};

// Create a status bar item
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.command = CMD_SELECT_ENV;
// https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration
const projectRoot = await getProjectRoot();
const workspaceSetting = await getWorkspaceSettings(serverId, projectRoot, true);
let environment = 'base'; // todo: Assume base, better to take this from server as it could be changed in project settings.

if (workspaceSetting.environment) {
environment = workspaceSetting.environment;
}

statusBarItem.text = `$(kedro-logo) ${environment}`;
statusBarItem.show();
context.subscriptions.push(statusBarItem);

context.subscriptions.push(
onDidChangePythonInterpreter(async () => {
await runServer();
Expand Down