Skip to content

Commit

Permalink
Kedro viz server removed
Browse files Browse the repository at this point in the history
Signed-off-by: Jitendra Gundaniya <[email protected]>
  • Loading branch information
jitu5 committed Aug 20, 2024
1 parent 64bcc58 commit 9024210
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 70 deletions.
17 changes: 17 additions & 0 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
)
from pygls.server import LanguageServer

from kedro_viz.server import load_and_populate_data
from kedro_viz.api.rest.responses import get_json_data

class KedroLanguageServer(LanguageServer):
"""Store Kedro-specific information in the language server."""
Expand Down Expand Up @@ -553,6 +555,21 @@ def definition_from_flowchart(ls, word):
result = definition(LSP_SERVER, params=None, word=word)
return result

@LSP_SERVER.command("kedro.getProjectData")
def get_porject_data_from_viz(lsClient):
"""Get project data from kedro viz
"""
data = None
try:
load_and_populate_data(Path.cwd())
data = get_json_data()
return data
except Exception as e:
print(f"An error occurred: {e}")
finally:
print("Execution completed.")
return data

### End of kedro-lsp


Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
"dependencies": {
"@vscode/python-extension": "^1.0.5",
"fs-extra": "^11.2.0",
"node-fetch": "^3.3.2",
"vscode-languageclient": "^8.1.0"
},
"devDependencies": {
Expand Down
17 changes: 16 additions & 1 deletion src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export async function executeServerDefinitionCommand(lsClient: LanguageClient |
const result: any[] | undefined = await vscode.commands.executeCommand(
commandName /* if your command accepts arguments you can pass them here */,
target,

);
logger.info(`${commandName} result: ${JSON.stringify(result, undefined, 2)}`);
if (result && result.length > 0) {
Expand All @@ -97,3 +96,19 @@ export async function executeServerDefinitionCommand(lsClient: LanguageClient |
});
}
}

export async function executeGetProjectDataCommand(lsClient: LanguageClient | undefined) {
if (!lsClient || lsClient.state !== State.Running) {
await vscode.window.showErrorMessage('There is no language server running.');
return;
}
if (!lsClient.initializeResult) {
await vscode.window.showErrorMessage('The Language Server fail to initialise.');
return;
}

const commandName = 'kedro.getProjectData';
logger.info(`executing command: '${commandName}'`);
const result = await vscode.commands.executeCommand(commandName);
return result;
}
8 changes: 0 additions & 8 deletions src/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as path from 'path';
import { LogLevel, Uri, WorkspaceFolder } from 'vscode';
import { Trace } from 'vscode-jsonrpc/node';
import { getWorkspaceFolders } from './vscodeapi';
import fetch from 'node-fetch';
import KedroVizPanel from '../webview/vizWebView';

function logLevelToTrace(logLevel: LogLevel): Trace {
Expand Down Expand Up @@ -67,10 +66,3 @@ export async function getProjectRoot(): Promise<WorkspaceFolder> {
return rootWorkspace;
}
}

export async function fetchAndUpdateProjectData(): Promise<void> {
fetch('http://127.0.0.1:3131/api/main')
.then((response: { text: () => any }) => response.text())
.then((data: string) => KedroVizPanel.currentPanel?.updateData(data))
.catch((err: { message: string }) => console.error('Error: ' + err.message));
}
23 changes: 9 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { selectEnvironment, executeServerCommand, executeServerDefinitionCommand } from './common/commands';
import {
selectEnvironment,
executeServerCommand,
executeServerDefinitionCommand,
executeGetProjectDataCommand,
} from './common/commands';
import * as vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient/node';
import { registerLogger, traceError, traceLog, traceVerbose } from './common/log/logging';
Expand All @@ -23,10 +28,8 @@ import { loadServerDefaults } from './common/setup';
import { getLSClientTraceLevel, getProjectRoot } from './common/utilities';
import { createOutputChannel, onDidChangeConfiguration, registerCommand } from './common/vscodeapi';
import KedroVizPanel from './webview/vizWebView';
import { runKedroVizServer } from './webview/vizServer';

let lsClient: LanguageClient | undefined;
let kedroVizProcess: any;

export async function activate(context: vscode.ExtensionContext): Promise<void> {
// This is required to get server name and module. This should be
Expand Down Expand Up @@ -58,8 +61,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
);

context.subscriptions.push(
vscode.commands.registerCommand('kedro.runKedroViz', () => {
vscode.commands.registerCommand('kedro.runKedroViz', async () => {
KedroVizPanel.createOrShow(context.extensionUri, lsClient);
const projectData = await executeGetProjectDataCommand(lsClient);
KedroVizPanel.currentPanel?.updateData(projectData);
}),
);

Expand Down Expand Up @@ -88,12 +93,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
console.log(interpreterDetails);
console.log('===============DEBUG============');

// Start kedro viz server
if (kedroVizProcess) {
process.kill(-kedroVizProcess.pid);
}
kedroVizProcess = await runKedroVizServer();

if (interpreterDetails.path) {
traceVerbose(`Using interpreter from Python extension: ${interpreterDetails.path.join(' ')}`);
lsClient = await restartServer(serverId, serverName, outputChannel, lsClient, env);
Expand Down Expand Up @@ -168,8 +167,4 @@ export async function deactivate(): Promise<void> {
if (lsClient) {
await lsClient.stop();
}
if (kedroVizProcess) {
process.kill(-kedroVizProcess.pid);
kedroVizProcess = null; // Reset the reference after killing the process
}
}
3 changes: 2 additions & 1 deletion src/webview/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export async function goToDefinition(message: Message) {
let filePattern = '**/*.yml';

if (message.type === 'task') {
filePattern = '**/*.py';
// Looking only in pipelines folders
filePattern = '**/pipelines/**/*.py';
}

const files = await vscode.workspace.findFiles(filePattern);
Expand Down
36 changes: 0 additions & 36 deletions src/webview/vizServer.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/webview/vizWebView.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as vscode from 'vscode';
import fetch from 'node-fetch';
import { goToDefinition } from './goToDefinition';
import { fetchAndUpdateProjectData } from '../common/utilities';
import { LanguageClient } from 'vscode-languageclient/node';
import { executeServerDefinitionCommand } from '../common/commands';

Expand Down Expand Up @@ -37,7 +35,6 @@ export default class KedroVizPanel {
});

KedroVizPanel.currentPanel = new KedroVizPanel(panel, extensionUri, lsClient);
fetchAndUpdateProjectData();
}

public static revive(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
Expand Down Expand Up @@ -84,11 +81,6 @@ export default class KedroVizPanel {
);
}

public updateTheme() {
// Send a message to the webview.
this._panel.webview.postMessage({ command: 'updateTheme', theme: 'light' });
}

public updateData(data: any) {
// Send a message to the webview.
this._panel.webview.postMessage({ command: 'updateData', data });
Expand Down
2 changes: 1 addition & 1 deletion webview/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function App() {
const message = event.data;
switch (message.command) {
case "updateData":
setData(JSON.parse(message.data));
setData(message.data);
setLoading(false);
break;
default:
Expand Down

0 comments on commit 9024210

Please sign in to comment.