Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspace path variable expansion to settings #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@ import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';

function substitute_workplace_folder(setting: string): string {
let workplace_folder: string = "";

for (const possible_path of [vscode.workspace.rootPath, vscode.window.activeTextEditor]) {
if (possible_path !== undefined) {
workplace_folder = possible_path;
break;
}
}

for (const workspace_varible of ['workspaceRoot', 'workspaceFolder']) {
setting = setting.replace('${' + workspace_varible + '}', workplace_folder);
}
return setting;
}

function absolutePath(userDefinedPath: string) {
return userDefinedPath.includes('~') ?
path.normalize(userDefinedPath.replace(/^~/, os.homedir() + '/')) :
userDefinedPath;

if (userDefinedPath.includes('~'))
return path.normalize(userDefinedPath.replace(/^~/, os.homedir() + '/'));
return path.normalize(substitute_workplace_folder(userDefinedPath))
}

export function prodSettings(): Settings {
return {
gnPath: () =>
absolutePath(vscode.workspace.getConfiguration().get('gnformat.path')),
absolutePath(vscode.workspace.getConfiguration('gnformat').get('path')),
};
}

Expand Down