Skip to content

Commit

Permalink
Fix restart issue (#1019)
Browse files Browse the repository at this point in the history
* add logs

* restart only if python changed

* refactor
  • Loading branch information
pgrivachev authored Jun 18, 2023
1 parent 99a3cf3 commit 3479319
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/src/lsp_client/DbtWizardLanguageClient.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -65,8 +67,9 @@ export abstract class DbtWizardLanguageClient implements Disposable {

async initCustomParams(): Promise<void> {
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<boolean>('enableEntireProjectAnalysis', true),
enableSnowflakeSyntaxCheck: configuration.get<boolean>('enableSnowflakeSyntaxCheck', false),
lspMode: this.getLspMode(),
Expand All @@ -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();
}
}
});
}
Expand Down

0 comments on commit 3479319

Please sign in to comment.