Skip to content

Commit

Permalink
Modify file paths to be platform independent
Browse files Browse the repository at this point in the history
  • Loading branch information
mchadalavada committed Oct 13, 2023
1 parent 569636c commit 9b1d03f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

18 changes: 9 additions & 9 deletions src/ide/ui/compileCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ async function showFiles() {
}
//Change the command WHEN the user selects a different item.
async function changeCompilationCommand(item: vscode.QuickPickItem) {
CompileCommands.command = "cd " + item.description + " && p compile";
CompileCommands.command = "cd " + item.description + " ; p compile";
CompileCommands.currProject = [
item.label,
item.description + "PGenerated/Stately/",
];
await TestingEditor.updateTestCasesList(item.description ?? "**/");
await TestingEditor.updateTestCasesList(item.description ?? "**");
}

// Runs p compile in the terminal.
Expand All @@ -96,7 +96,7 @@ async function createCompileTask() {
vscode.tasks.registerTaskProvider(type, {
async provideTasks(token?: vscode.CancellationToken) {
var msg =
'echo -e "\x1b[1;31m ' + messages.Messages.Installation.noP + '"';
'echo "' + messages.Messages.Installation.noP + '"';
var execution = new vscode.ShellExecution(msg);

//var problemMatchers = ["$Parse", "$Type"];
Expand Down Expand Up @@ -128,7 +128,7 @@ async function createCompileTask() {
var stately_execution = new vscode.ShellExecution(
msg +
" --mode stately" +
'; echo -e "\\e[1;31m ' +
'; echo "' +
messages.Messages.CompilationStatus.Visualization +
CompileCommands.currProject[1] +
CompileCommands.currProject[0].replace(".pproj", "") +
Expand Down Expand Up @@ -180,7 +180,7 @@ This is run WHEN:

//IDEA: only update the files being deleted or created, instead of running this everytime.
async function generateProjects() {
var files = await searchDirectory("**/*.pproj");
var files = await searchDirectory(path.join("**", "*.pproj"));
if (files == null) {
//No directory to speak of.
vscode.window.showErrorMessage(
Expand All @@ -196,14 +196,14 @@ async function generateProjects() {
} else {
//If there is only a single pproj file: Set the command and a single project.
if (files.length == 1 && files.at(0) != undefined) {
var fileName = files.at(0)?.fsPath.split("/").at(-1);
var fileName = path.parse(files.at(0)?.fsPath!).base;

if (fileName != undefined) {
var directory = files.at(0)?.path.replace(fileName, "");
CompileCommands.projects = [
{ label: fileName, description: directory },
];
CompileCommands.command = "cd " + directory + " && p compile";
CompileCommands.command = "cd " + directory + " ; p compile";

if (directory != undefined) {
CompileCommands.currProject = [
Expand All @@ -218,7 +218,7 @@ async function generateProjects() {
CompileCommands.projects = [];
for (var f of files) {
//Add all the file pproj files to the options for the user to choose from.
var fileName = f.fsPath.split("/").at(-1);
var fileName = path.parse(f.fsPath).base;
if (fileName != undefined) {
var item: vscode.QuickPickItem = {
label: fileName,
Expand All @@ -230,7 +230,7 @@ async function generateProjects() {

//Set the compile command to the first P project discovered.
CompileCommands.command =
"cd " + CompileCommands.projects.at(0)?.description + " && p compile";
"cd " + CompileCommands.projects.at(0)?.description + " ; p compile";
if (CompileCommands.projects.at(0) != undefined) {
CompileCommands.currProject = [
CompileCommands.projects.at(0)?.label || "",
Expand Down
11 changes: 2 additions & 9 deletions src/ide/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export namespace Messages {
export const MultiplePprofFile =
"The current directory contains multiple *.pproj folders. Please select which project to compile.";
export const NoDirectory = "The current directory is invalid.";
export const Visualization = `
Code Generation Success!!
Visualize P state machines by copy-and-pasting code from the following file:
`;
export const Visualization = `Code Generation Success!! Visualize P state machines by copy-and-pasting code from the following file: `;
}

export namespace Compiler {
Expand All @@ -17,11 +14,7 @@ Visualize P state machines by copy-and-pasting code from the following file:
}

export namespace Installation {
export const noP = `
P LANGUAGE is not installed on your computer!
Automatic Compilation and P testing capabilities will not work.
Download P at https://p-org.github.io/P/getstarted/install/.
Then, reload VS Code.`;
export const noP = `P LANGUAGE is not installed on your computer! Automatic Compilation and P testing capabilities will not work. Download P at https://p-org.github.io/P/getstarted/install/. Then, reload VS Code.`;
export const Start = "Starting P installation";
export const Error = "An error occurred during the installation of P.";
export const Completed = "P installation completed";
Expand Down
15 changes: 9 additions & 6 deletions src/ide/ui/testinginEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import * as messages from "./messages";
import { checkPInstalled, searchDirectory } from "../../miscTools";
import * as child_process from "child_process";
import * as path from "path";

export default class TestingEditor {
static instance: TestingEditor;
Expand Down Expand Up @@ -44,7 +45,7 @@ export default class TestingEditor {
);

//Looks through the entire test folder to discover where is the test file and where the tests are.
var files = await searchDirectory("**/PTst/Test*.p");
var files = await searchDirectory(path.join("**", "PTst", "Test*.p"));
if (files != null) {
for (var i = 0; i < files.length; i++) {
var x = files.at(i);
Expand All @@ -64,9 +65,9 @@ export default class TestingEditor {

if (vscode.workspace.workspaceFolders !== undefined) {
const folder = vscode.workspace.workspaceFolders[0].uri;
currProject = currProject.replace(folder.path, "**");
currProject = currProject.replace(folder.fsPath, "**");
// Create relative path pattern to the workspace
var files = await searchDirectory(`${currProject}PTst/Test*.p`);
var files = await searchDirectory(path.join(currProject, "PTst", "Test*.p"));

// Create test items for selected p project in the testing panel
if (files != null) {
Expand Down Expand Up @@ -186,7 +187,7 @@ function runPTestcaseIfQueueNotEmpty(run: vscode.TestRun, queue: vscode.TestItem
function runPTestCase(run: vscode.TestRun, tc: vscode.TestItem, tcOutput: vscode.OutputChannel, queue: vscode.TestItem[], token: vscode.CancellationToken) {
run.started(tc);
//Sends P Check command through the terminal
var projectDirectory = tc.uri?.fsPath.split("PTst")[0];
var projectDirectory = tc.uri?.fsPath !== undefined ? path.parse(path.parse(tc.uri?.fsPath).dir).dir : "";

if (vscode.workspace.workspaceFolders !== undefined) {
runCheckCommand(
Expand Down Expand Up @@ -315,8 +316,10 @@ function cancelTestcaseRun(run: vscode.TestRun, test: vscode.TestItem, isTestRun
}

function updateNodeFromDocument(e: vscode.TextDocument) {
const name = e.fileName.split("/");
if (name.at(-1) == undefined || !name.includes("PTst")) {

const filename = path.parse(e.fileName).base;
const dirname = path.parse(e.fileName).dir;
if (filename == undefined || !dirname.endsWith("PTst")) {
return;
}
if (e.uri.scheme !== "file") {
Expand Down
5 changes: 3 additions & 2 deletions src/miscTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export async function searchDirectory(pattern: string) {
var files = null;
if (vscode.workspace.workspaceFolders !== undefined) {
const folder = vscode.workspace.workspaceFolders[0].uri;
pattern = pattern.replace(folder.fsPath, "");
let filePattern: vscode.RelativePattern = new vscode.RelativePattern(
folder,
folder.fsPath,
pattern
);
var excludeFolders: Array<string> = vscode.workspace.getConfiguration("p-vscode").get("pcompile.exclude") || ["**/Build/*", "**/build/**"];
Expand All @@ -23,7 +24,7 @@ export async function searchDirectory(pattern: string) {
export function checkPInstalled(): boolean {
try {
const homedir = require('os').homedir();
var dirPath = homedir + "/.dotnet/tools";
var dirPath = path.join(homedir, ".dotnet", "tools");
var dirFiles = fs.readdirSync(dirPath);
var isPFileFound = false;
dirFiles.forEach((file: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/trace-visualizer/PeasyVizPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import shivizScripts from "./constants/shivizScripts";
import { IShiVizScriptsUri } from "./types/shiviz";
import shivizSourceHtml from "./shivizSourceHtml";
import visualizerErrorHtml from "./visualizerErrorHtml";
import * as path from "path";

export class PeasyVizPanel {
/**
Expand Down Expand Up @@ -220,7 +221,7 @@ export class PeasyVizPanel {
for (const file of files || []) {

// Get the trace filename
var traceName: string = file.path.split('/').pop() ?? "";
var traceName: string = path.parse(file.path).base || "";
traceName = traceName.split('.')[0];

// Get the trace content
Expand Down

0 comments on commit 9b1d03f

Please sign in to comment.