Skip to content

Commit

Permalink
Add logs to initpathenv (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-wiemer authored Oct 29, 2024
1 parent c05e25e commit 16c0722
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions server/src/scriptrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import { resolve } from 'path';
* Simple runner for LSP server initializiaton via AHK.
* Not used for running user-defined scripts.
*/
export function runscript(script: string) {
export function runscript(script: string): string | undefined {
const funcName = 'runscript';
const executePath = resolvePath(interpreterPath, true);
console.log(`${funcName} executePath`, executePath);
if (!executePath)
return;
const process = spawnSync(`"${executePath}" /CP65001 /ErrorStdOut=utf-8 *`, [], { cwd: executePath.replace(/[\\/].+?$/, ''), shell: true, input: script });
const result = (process?.stdout ?? '').toString();
console.log(`${funcName} result`, result)
if (process)
return (process.stdout ?? '').toString();
return result;
}

export function existsSync(path: string): boolean {
Expand Down
12 changes: 10 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ async function patherr(msg: string) {
}

async function initpathenv(samefolder = false, retry = true): Promise<boolean> {
const funcName = 'initpathenv';
console.log(`Starting ${funcName}(${samefolder}, ${retry})`);
const script = `
#NoTrayIcon
#Warn All, Off
Expand All @@ -289,6 +291,7 @@ async function initpathenv(samefolder = false, retry = true): Promise<boolean> {
}`;
let fail = 0,
data = runscript(script);
console.log(`data:`, data);
if (data === undefined) {
if (retry) return initpathenv(samefolder, false);
patherr(setting.ahkpatherr());
Expand Down Expand Up @@ -316,10 +319,15 @@ async function initpathenv(samefolder = false, retry = true): Promise<boolean> {
} else fail = 1;
if (fail !== 2 && retry) return initpathenv(samefolder, false);
if (!a_vars.mydocuments)
connection.window.showErrorMessage(setting.getenverr());
console.log('a_vars', a_vars);
connection.window.showWarningMessage(setting.getenverr());
return false;
}
Object.assign(a_vars, Object.fromEntries(data.replace(/|[A-Z]:\\/g, m => m.toLowerCase()).split('\n').map(l => l.split('|'))));
const intermediateData = data.replace(/|[A-Z]:\\/g, m => m.toLowerCase()).split('\n').map(l => l.split('|'));
console.log('intermediateData', intermediateData);
const finalData = Object.fromEntries(intermediateData);
console.log('finalData', finalData);
Object.assign(a_vars, finalData);
a_vars.ahkpath ??= interpreterPath;
set_version(a_vars.ahkversion ??= '2.0.0');
if (a_vars.ahkversion.startsWith('1.'))
Expand Down

0 comments on commit 16c0722

Please sign in to comment.