Skip to content

Commit

Permalink
Use cwd when calling openscad (fixes #68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antyos committed Oct 27, 2024
1 parent 3ac0133 commit b9059db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/extension.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function activate(context: vscode.ExtensionContext): void {
loggingService.logInfo(`Activating ${extensionName} v${extensionVersion}`);

/** New launch object */
const previewManager = new PreviewManager(loggingService);
const previewManager = new PreviewManager(loggingService, context);

// Register commands
const commands = [
Expand Down Expand Up @@ -66,7 +66,7 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor),
vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration)
);
onDidChangeConfiguration();
// onDidChangeConfiguration();

// Update status bar item once at start
Cheatsheet.updateStatusBar();
Expand Down
15 changes: 10 additions & 5 deletions src/preview/openscad-exe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { promisify } from 'util';

import commandExists = require('command-exists');
import { realpath } from 'fs/promises';
import { ExtensionContext } from 'vscode';

import { LoggingService } from 'src/logging-service';

Expand All @@ -34,17 +35,21 @@ export class OpenscadExecutableManager {
private openscadPath?: string;
private arguments_: string[] = [];

public constructor(private loggingService: LoggingService) {}
public constructor(
private readonly loggingService: LoggingService,
private readonly context: ExtensionContext
) {}

private async getOpenscadVersion(
openscadPath: string,
arguments_: string[] = []
): Promise<string | undefined> {
try {
const { stdout, stderr } = await execFile(openscadPath, [
...arguments_,
'--version',
]);
const { stdout, stderr } = await execFile(
openscadPath,
[...arguments_, '--version'],
{ cwd: this.context.extensionPath.toString() }
);

// For some reason, OpenSCAD seems to use stderr for all console output...
// If there is no error, assume stderr should be treated as stdout
Expand Down
10 changes: 7 additions & 3 deletions src/preview/preview-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,15 @@ export class PreviewManager {

/** Constructor */

public constructor(private loggingService: LoggingService) {
this.previewStore = new PreviewStore(this.loggingService);
public constructor(
private loggingService: LoggingService,
private context: vscode.ExtensionContext
) {
this.previewStore = new PreviewStore(this.loggingService, this.context);
this.variableResolver = new VariableResolver(this.loggingService);
this.openscadExecutableManager = new OpenscadExecutableManager(
this.loggingService
this.loggingService,
this.context
);
// Load configutation
this.onDidChangeConfiguration(
Expand Down
2 changes: 2 additions & 0 deletions src/preview/preview-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class PreviewStore /* extends vscode.Disposable */ {
/** Create a new PreviewStore with a max number of previews */
public constructor(
private readonly loggingService: LoggingService,
private readonly context: vscode.ExtensionContext,
maxPreviews = 0
) {
this._maxPreviews = maxPreviews;
Expand Down Expand Up @@ -77,6 +78,7 @@ export class PreviewStore /* extends vscode.Disposable */ {

const preview = new Preview(
this.loggingService,
this.context,
openscadExecutable,
uri,
hasGui,
Expand Down
2 changes: 2 additions & 0 deletions src/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Preview {
/** Launch an instance of OpenSCAD to prview a file */
constructor(
private readonly loggingService: LoggingService,
private readonly context: vscode.ExtensionContext,
private readonly openscadExecutable: OpenscadExecutable,
public readonly uri: vscode.Uri,
public readonly hasGui: boolean,
Expand All @@ -40,6 +41,7 @@ export class Preview {
this._process = child.execFile(
this.openscadExecutable.filePath,
commandArguments,
{ cwd: this.context.extensionPath.toString() },
(error, stdout, stderr) => {
// If there's an error
if (error) {
Expand Down

0 comments on commit b9059db

Please sign in to comment.