Skip to content

Commit

Permalink
fix finding python executable (#1323)
Browse files Browse the repository at this point in the history
* fix finding python executable

* bump version
  • Loading branch information
pgrivachev authored Oct 31, 2023
1 parent 5bbede8 commit a3a0bf6
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 250 deletions.
17 changes: 17 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"@google-cloud/bigquery": "^7.3.0",
"@types/vscode": "^1.83.1",
"@vscode/python-extension": "^1.0.5",
"@vscode/test-electron": "^2.3.6"
}
}
11 changes: 10 additions & 1 deletion client/src/DbtLanguageClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { WorkspaceHelper } from './WorkspaceHelper';
import { DbtLanguageClient } from './lsp_client/DbtLanguageClient';
import { DbtWizardLanguageClient } from './lsp_client/DbtWizardLanguageClient';
import { NoProjectLanguageClient } from './lsp_client/NoProjectLanguageClient';
import { PythonExtensionWrapper } from './python/PythonExtensionWrapper';
import { StatusHandler } from './status/StatusHandler';
import path = require('node:path');

Expand All @@ -23,6 +24,7 @@ export class DbtLanguageClientManager {

constructor(
private previewContentProvider: SqlPreviewContentProvider,
private pythonExtension: PythonExtensionWrapper,
private outputChannelProvider: OutputChannelProvider,
private serverAbsolutePath: string,
private manifestParsedEventEmitter: EventEmitter,
Expand Down Expand Up @@ -124,6 +126,7 @@ export class DbtLanguageClientManager {
if (!this.clients.has(projectUri.fsPath)) {
const client = new DbtLanguageClient(
6009 + this.clients.size,
this.pythonExtension,
this.outputChannelProvider,
this.serverAbsolutePath,
projectUri,
Expand All @@ -145,7 +148,13 @@ export class DbtLanguageClientManager {

async ensureNoProjectClient(): Promise<void> {
if (!this.noProjectClient) {
this.noProjectClient = new NoProjectLanguageClient(6008, this.outputChannelProvider, this.statusHandler, this.serverAbsolutePath);
this.noProjectClient = new NoProjectLanguageClient(
6008,
this.pythonExtension,
this.outputChannelProvider,
this.statusHandler,
this.serverAbsolutePath,
);
await this.initAndStartClient(this.noProjectClient);
}
}
Expand Down
5 changes: 4 additions & 1 deletion client/src/ExtensionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DbtDeps } from './commands/DbtDeps';
import { GoogleAuth } from './commands/GoogleAuth';
import { NotUseConfigForRefsPreview } from './commands/NotUseConfigForRefsPreview';
import { UseConfigForRefsPreview } from './commands/UseConfigForRefsPreview';
import { PythonExtensionWrapper } from './python/PythonExtensionWrapper';

export interface PackageJson {
name: string;
Expand All @@ -38,6 +39,7 @@ export class ExtensionClient {
commandManager = new CommandManager();
packageJson?: PackageJson;
activeTextEditorHandler: ActiveTextEditorHandler;
pythonExtension = new PythonExtensionWrapper();

constructor(
private context: ExtensionContext,
Expand All @@ -46,6 +48,7 @@ export class ExtensionClient {
) {
this.dbtLanguageClientManager = new DbtLanguageClientManager(
this.previewContentProvider,
this.pythonExtension,
this.outputChannelProvider,
this.context.asAbsolutePath(path.join('server', 'out', 'server.js')),
manifestParsedEventEmitter,
Expand Down Expand Up @@ -123,7 +126,7 @@ export class ExtensionClient {
this.commandManager.register(new DbtDeps(this.dbtLanguageClientManager));
this.commandManager.register(new GoogleAuth(this.dbtLanguageClientManager));
this.commandManager.register(new AnalyzeEntireProject(this.dbtLanguageClientManager));
this.commandManager.register(new CreateDbtProject(this.context.globalState));
this.commandManager.register(new CreateDbtProject(this.context.globalState, this.pythonExtension));
this.commandManager.register(new InstallDbtCore(this.dbtLanguageClientManager, this.outputChannelProvider));
this.commandManager.register(new InstallDbtAdapters(this.dbtLanguageClientManager, this.outputChannelProvider));
this.commandManager.register(new OpenOrCreatePackagesYml());
Expand Down
9 changes: 6 additions & 3 deletions client/src/commands/CreateDbtProject/CreateDbtProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EOL } from 'node:os';
import { promisify, TextEncoder } from 'node:util';
import { commands, Memento, OpenDialogOptions, Uri, window, workspace } from 'vscode';
import { log } from '../../Logger';
import { PythonExtension } from '../../python/PythonExtension';
import { PythonExtensionWrapper } from '../../python/PythonExtensionWrapper';
import { DBT_PROJECT_YML } from '../../Utils';
import { Command } from '../CommandManager';
import { DbtInitTerminal } from './DbtInitTerminal';
Expand All @@ -28,7 +28,10 @@ export class CreateDbtProject implements Command {
}
`;

constructor(private extensionGlobalState: Memento) {}
constructor(
private extensionGlobalState: Memento,
private pythonExtension: PythonExtensionWrapper,
) {}

async execute(projectFolder?: string, skipOpen?: boolean): Promise<void> {
const dbtInitCommandPromise = this.getDbtInitCommand();
Expand Down Expand Up @@ -97,7 +100,7 @@ export class CreateDbtProject implements Command {
}

async getDbtInitCommand(): Promise<string | undefined> {
const pythonInfo = await new PythonExtension().getPythonInfo();
const pythonInfo = await this.pythonExtension.getPythonInfo();

const promisifiedExec = promisify(exec);
const pythonOldCommand = `${pythonInfo.path} -c "import ${CreateDbtProject.PYTHON_CODE_OLD}(['--version'])"`;
Expand Down
4 changes: 3 additions & 1 deletion client/src/lsp_client/DbtLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ProjectProgressHandler } from '../ProjectProgressHandler';
import SqlPreviewContentProvider from '../SqlPreviewContentProvider';
import { TelemetryClient } from '../TelemetryClient';
import { DBT_PROJECT_YML, PACKAGES_YML, SNOWFLAKE_SQL_LANG_ID, SQL_LANG_ID, SUPPORTED_LANG_IDS } from '../Utils';
import { PythonExtensionWrapper } from '../python/PythonExtensionWrapper';
import { StatusHandler } from '../status/StatusHandler';
import { DbtWizardLanguageClient } from './DbtWizardLanguageClient';

Expand All @@ -32,6 +33,7 @@ export class DbtLanguageClient extends DbtWizardLanguageClient {

constructor(
private port: number,
pythonExtension: PythonExtensionWrapper,
outputChannelProvider: OutputChannelProvider,
private serverAbsolutePath: string,
dbtProjectUri: Uri,
Expand All @@ -41,7 +43,7 @@ export class DbtLanguageClient extends DbtWizardLanguageClient {
statusHandler: StatusHandler,
private snowflakeExtensionExists: Lazy<boolean>,
) {
super(outputChannelProvider, statusHandler, dbtProjectUri);
super(pythonExtension, outputChannelProvider, statusHandler, dbtProjectUri);
window.onDidChangeVisibleTextEditors((e: readonly TextEditor[]) => this.onDidChangeVisibleTextEditors(e));
}

Expand Down
12 changes: 7 additions & 5 deletions client/src/lsp_client/DbtWizardLanguageClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ActiveEnvironmentPathChangeEvent } from '@vscode/python-extension';
import { CustomInitParams, LspModeType, PythonInfo, StatusNotification } from 'dbt-language-server-common';
import { Uri, WorkspaceFolder, commands, workspace } from 'vscode';
import { Disposable, State } from 'vscode-languageclient';
import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node';
import { log } from '../Logger';
import { OutputChannelProvider } from '../OutputChannelProvider';
import { PythonExtension } from '../python/PythonExtension';
import { PythonExtensionWrapper } from '../python/PythonExtensionWrapper';
import { StatusHandler } from '../status/StatusHandler';

export abstract class DbtWizardLanguageClient implements Disposable {
Expand All @@ -23,10 +24,10 @@ export abstract class DbtWizardLanguageClient implements Disposable {
}

protected disposables: Disposable[] = [];
protected pythonExtension = new PythonExtension();
protected client!: LanguageClient;

constructor(
private pythonExtension: PythonExtensionWrapper,
protected outputChannelProvider: OutputChannelProvider,
protected statusHandler: StatusHandler,
protected dbtProjectUri: Uri,
Expand Down Expand Up @@ -87,9 +88,10 @@ export abstract class DbtWizardLanguageClient implements Disposable {

async start(): Promise<void> {
await this.client.start().catch(e => log(`Error while starting server: ${e instanceof Error ? e.message : String(e)}`));
(await this.pythonExtension.onDidChangeExecutionDetails())(async (resource: Uri | undefined) => {
log(`onDidChangeExecutionDetails ${resource?.fsPath ?? 'undefined'}`);
if (this.client.state === State.Running && this.dbtProjectUri.fsPath === resource?.fsPath) {

(await this.pythonExtension.onDidChangeActiveEnvironmentPath())(async (e: ActiveEnvironmentPathChangeEvent) => {
log(`onDidChangeActiveEnvironmentPath ${e.resource?.uri.fsPath ?? 'undefined'}`);
if (this.client.state === State.Running && this.dbtProjectUri.fsPath === e.resource?.uri.fsPath) {
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)}`);
Expand Down
4 changes: 3 additions & 1 deletion client/src/lsp_client/NoProjectLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { LspModeType, NO_PROJECT_PATH } from 'dbt-language-server-common';
import { Uri } from 'vscode';
import { LanguageClient } from 'vscode-languageclient/node';
import { OutputChannelProvider } from '../OutputChannelProvider';
import { PythonExtensionWrapper } from '../python/PythonExtensionWrapper';
import { StatusHandler } from '../status/StatusHandler';
import { DbtWizardLanguageClient } from './DbtWizardLanguageClient';

export class NoProjectLanguageClient extends DbtWizardLanguageClient {
constructor(
private port: number,
pythonExtension: PythonExtensionWrapper,
outputChannelProvider: OutputChannelProvider,
statusHandler: StatusHandler,
private serverAbsolutePath: string,
) {
super(outputChannelProvider, statusHandler, Uri.file(NO_PROJECT_PATH));
super(pythonExtension, outputChannelProvider, statusHandler, Uri.file(NO_PROJECT_PATH));
}

initializeClient(): LanguageClient {
Expand Down
Loading

0 comments on commit a3a0bf6

Please sign in to comment.