Skip to content

Fix replaceVars #287

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
64 changes: 40 additions & 24 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,13 @@
"test": "npm run compile"
},
"dependencies": {
"encoding": "^0.1.13"
"encoding": "^0.1.13",
"vscode-variables": "~1.0.1"
},
"devDependencies": {
"@types/node": "^16.10.4",
"@types/vscode": "^1.58.0",
"typescript": "^4.4.3",
"vsce": "^2.11.0"
"@types/vscode": "^1.97.0",
"typescript": "^5.7.3",
"vsce": "^2.15.0"
}
}
50 changes: 35 additions & 15 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,52 @@ class XMakeExplorerItem extends vscode.TreeItem {
switch (info.type) {
case XMakeExplorerItemType.GROUP:
this.iconPath = {
dark: path.join(...resDirPath, "dark", "symbol-misc.svg"),
light: path.join(...resDirPath, "light", "symbol-misc.svg")
}
dark: vscode.Uri.file(
path.join(...resDirPath, "dark", "symbol-misc.svg")
),
light: vscode.Uri.file(
path.join(...resDirPath, "light", "symbol-misc.svg")
),
};
break;
case XMakeExplorerItemType.TARGET:
if (info.kind === "binary")
this.iconPath = {
dark: path.join(...resDirPath, "dark", "window.svg"),
light: path.join(...resDirPath, "light", "window.svg")
}
dark: vscode.Uri.file(
path.join(...resDirPath, "dark", "window.svg")
),
light: vscode.Uri.file(
path.join(...resDirPath, "light", "window.svg")
),
};
else if (info.kind === "shared")
this.iconPath = {
dark: path.join(...resDirPath, "dark", "gear.svg"),
light: path.join(...resDirPath, "light", "gear.svg")
}
dark: vscode.Uri.file(
path.join(...resDirPath, "dark", "gear.svg")
),
light: vscode.Uri.file(
path.join(...resDirPath, "light", "gear.svg")
),
};
else if (info.kind == "static")
this.iconPath = {
dark: path.join(...resDirPath, "dark", "library.svg"),
light: path.join(...resDirPath, "light", "library.svg")
}
dark: vscode.Uri.file(
path.join(...resDirPath, "dark", "library.svg")
),
light: vscode.Uri.file(
path.join(...resDirPath, "light", "library.svg")
),
};
else {
// Icon for phony target
this.iconPath = {
dark: path.join(...resDirPath, "dark", "archive.svg"),
light: path.join(...resDirPath, "light", "archive.svg")
}
dark: vscode.Uri.file(
path.join(...resDirPath, "dark", "archive.svg")
),
light: vscode.Uri.file(
path.join(...resDirPath, "light", "archive.svg")
),
};
}
break;
case XMakeExplorerItemType.DIRECTORY:
Expand Down
11 changes: 2 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// imports
import * as vscode from 'vscode';
import * as path from 'path';
import vscodeVaraibles from 'vscode-variables';

// get project root directory
var projectRoot = null;
Expand All @@ -26,15 +26,8 @@ export function replaceAll(str: string, needle: string, what: string) {

// replace variables
export function replaceVars(str: string): string {

// init replacements
const replacements = [
['${workspaceRoot}', getProjectRoot()],
['${workspaceRootFolderName}', path.basename(getProjectRoot() || '.')]
] as [string, string][];

// replace all variables
return replacements.reduce((accdir, [needle, what]) => replaceAll(accdir, needle, what), str);
return vscodeVaraibles(str);
}

// simplistic function for just checking if a string can be parsed as json
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "ES2018",
"outDir": "out",
"lib": [
"es6"
Expand Down
3 changes: 3 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "vscode-variables" {
export default function variables(str: string, recursive?: boolean): string;
}
Loading