From 3479319bf3ae9122007ffb725baab43c6f0b7c3e Mon Sep 17 00:00:00 2001 From: Pavel Grivachev Date: Sun, 18 Jun 2023 11:27:33 +0200 Subject: [PATCH] Fix restart issue (#1019) * add logs * restart only if python changed * refactor --- client/src/lsp_client/DbtWizardLanguageClient.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/lsp_client/DbtWizardLanguageClient.ts b/client/src/lsp_client/DbtWizardLanguageClient.ts index 5334ede8..a4875e59 100644 --- a/client/src/lsp_client/DbtWizardLanguageClient.ts +++ b/client/src/lsp_client/DbtWizardLanguageClient.ts @@ -1,4 +1,4 @@ -import { CustomInitParams, LspModeType, StatusNotification } from 'dbt-language-server-common'; +import { CustomInitParams, LspModeType, PythonInfo, StatusNotification } from 'dbt-language-server-common'; import { Uri, commands, workspace } from 'vscode'; import { Disposable, State } from 'vscode-languageclient'; import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node'; @@ -12,6 +12,8 @@ export abstract class DbtWizardLanguageClient implements Disposable { static readonly CLIENT_NAME = 'Wizard for dbt Core (TM)'; static readonly FOCUS_EDITOR_COMMAND = 'workbench.action.focusActiveEditorGroup'; + pythonInfo?: PythonInfo; + static createServerOptions(port: number, module: string): ServerOptions { const debugOptions = { execArgv: ['--nolazy', `--inspect=${port}`] }; return { @@ -65,8 +67,9 @@ export abstract class DbtWizardLanguageClient implements Disposable { async initCustomParams(): Promise { const configuration = workspace.getConfiguration('WizardForDbtCore(TM)', this.client.clientOptions.workspaceFolder); + this.pythonInfo = await this.pythonExtension.getPythonInfo(this.client.clientOptions.workspaceFolder); const customInitParams: CustomInitParams = { - pythonInfo: await this.pythonExtension.getPythonInfo(this.client.clientOptions.workspaceFolder), + pythonInfo: this.pythonInfo, enableEntireProjectAnalysis: configuration.get('enableEntireProjectAnalysis', true), enableSnowflakeSyntaxCheck: configuration.get('enableSnowflakeSyntaxCheck', false), lspMode: this.getLspMode(), @@ -81,8 +84,11 @@ export abstract class DbtWizardLanguageClient implements Disposable { (await this.pythonExtension.onDidChangeExecutionDetails())(async (resource: Uri | undefined) => { log(`onDidChangeExecutionDetails ${resource?.fsPath ?? 'undefined'}`); if (this.client.state === State.Running && this.dbtProjectUri.fsPath === resource?.fsPath) { - log('Python execution details changed, restarting...'); - await this.restart(); + const newPythonInfo = await this.pythonExtension.getPythonInfo(this.client.clientOptions.workspaceFolder); + if (newPythonInfo.path !== this.pythonInfo?.path || newPythonInfo.version?.join('.') !== this.pythonInfo.version?.join('.')) { + log(`Python info changed: ${JSON.stringify(newPythonInfo)}`); + await this.restart(); + } } }); }