Skip to content

Commit

Permalink
Fix log paths starting with ~
Browse files Browse the repository at this point in the history
  • Loading branch information
jneira committed Dec 8, 2021
1 parent a424a6b commit 32375ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CommandNames } from './commands/constants';
import { ImportIdentifier } from './commands/importIdentifier';
import { DocsBrowser } from './docsBrowser';
import { downloadHaskellLanguageServer } from './hlsBinaries';
import { directoryExists, executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';
import { directoryExists, executableExists, expandHomeDir, ExtensionLogger, resolvePathPlaceHolders } from './utils';

// Used for environment variables later on
interface IEnvVars {
Expand Down Expand Up @@ -171,11 +171,11 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold

const logLevel = workspace.getConfiguration('haskell', uri).trace.server;
const clientLogLevel = workspace.getConfiguration('haskell', uri).trace.client;
const logFile = workspace.getConfiguration('haskell', uri).logFile;
const logFile: string = workspace.getConfiguration('haskell', uri).logFile;

const outputChannel: OutputChannel = window.createOutputChannel(langName);

const logFilePath = logFile ? path.resolve(currentWorkingDir, logFile) : undefined;
const logFilePath = path.resolve(currentWorkingDir, expandHomeDir(logFile));
const logger: Logger = new ExtensionLogger('client', clientLogLevel, outputChannel, logFilePath);
if (logFilePath) {
logger.info(`Writing client log to file ${logFilePath}`);
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ export function directoryExists(path: string): boolean {
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
}

export function expandHomeDir(path: string): string {
if (path.startsWith('~')) {
return path.replace('~', os.homedir);
}
return path;
}

export function resolvePathPlaceHolders(path: string, folder?: WorkspaceFolder) {
path = path.replace('${HOME}', os.homedir).replace('${home}', os.homedir).replace(/^~/, os.homedir);
if (folder) {
Expand Down

0 comments on commit 32375ca

Please sign in to comment.