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 Quadroid JEDI Code Format engine #52

Merged
merged 1 commit into from
Feb 9, 2023
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"enum": [
"embarcadero",
"jcf",
"jcf-quadroid",
"ptop"
]
},
Expand Down
9 changes: 8 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ export async function activate(context: vscode.ExtensionContext) {
const optionJCF = <vscode.MessageItem>{
title: "Jedi Code Format"
};
const optionJCFQ = <vscode.MessageItem>{
title: "JCF (Quadroid)"
};
const optionPTOP = <vscode.MessageItem>{
title: "FreePascal PtoP"
};
vscode.window.showErrorMessage('The "pascal.formatter.engine" setting is not defined. Do you want to download some formatter tool first?', optionJCF, optionPTOP).then(option => {
vscode.window.showErrorMessage('The "pascal.formatter.engine" setting is not defined. Do you want to download some formatter tool first?', optionJCF, optionJCFQ, optionPTOP).then(option => {
// nothing selected
if (typeof option === 'undefined') {
reject('undefined');
Expand All @@ -204,6 +207,10 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.env.openExternal(vscode.Uri.parse("http://jedicodeformat.sourceforge.net/"));
break;

case optionJCFQ.title:
vscode.env.openExternal(vscode.Uri.parse("https://github.com/quadroid/jcf-pascal-format"));
break;

case optionPTOP.title:
vscode.env.openExternal(vscode.Uri.parse("https://www.freepascal.org/tools/ptop.html"));
break;
Expand Down
39 changes: 24 additions & 15 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import npath = require('path');

/*

linux:
linux:
"pascal.formatter.engine": "ptop",
"pascal.formatter.enginePath": "/usr/bin/ptop",

Expand Down Expand Up @@ -40,7 +40,7 @@ export class Formatter {
public format(range: vscode.Range, engine: string, path: string, parameters: string, indent: number, wrapLineLength: number) {

return new Promise((resolve, reject) => {

// entire document - if not range is provided
range = range || new vscode.Range(
0, 0,
Expand All @@ -60,42 +60,47 @@ export class Formatter {
if (textToFormat) {

try {

if (engine === 'embarcadero') {
if (parameters !== '') {
configFileParameters = ' -config ' + parameters;
configFileParameters = ' -config ' + parameters;
}
command = "\"" + path + "\" -silent " + configFileParameters + ' "$file" ';
command = command.replace('$file', tempFile);
readFile = tempFile;
} else if (engine === 'ptop') {
if (parameters !== '') {
configFileParameters = ' -c ' + parameters;
configFileParameters = ' -c ' + parameters;
}

let indentConfig = '';
if (indent > 0) {
indentConfig = ' -i ' + indent;
}

let wrapLineLengthConfig = '';
if (wrapLineLength > 0) {
wrapLineLengthConfig = ' -l ' + wrapLineLength;
}

command = "\"" + path + "\" " + configFileParameters + indentConfig + wrapLineLengthConfig + ' "$file" "$outfile" ';
command = command.replace('$file', tempFile);
command = command.replace('$outfile', tempFileOut);
readFile = tempFileOut
command = command.replace('$outfile', tempFileOut);
readFile = tempFileOut
} else { // jcf
if (parameters !== '') {
configFileParameters = ' -config=' + parameters;
configFileParameters = ' -config=' + parameters;
}
if (engine === 'jcf-quadroid') {
command = "\"" + path + "\" " + configFileParameters + ' -out "$fileout" "$file" ';
command = command.replace('$fileout', tempFileOut);
} else {
command = "\"" + path + "\" " + configFileParameters + ' -y -F "$file" ';
}
command = "\"" + path + "\" " + configFileParameters + ' -y -F "$file" ';
command = command.replace('$file', tempFile);
readFile = tempFileOut
}

console.log(command);
cp.exec(command, function(error, stdout, stderr) {
console.log('stdout' + stdout);
Expand All @@ -105,7 +110,11 @@ export class Formatter {
reject(stdout.toString());
}
else {
const formattedXml: string = fs.readFileSync(readFile, 'utf8');
let formattedXml: string = fs.readFileSync(readFile, 'utf8');
// remove UTF-8 BOM
if (formattedXml.charCodeAt(0) === 0xfeff) {
formattedXml = formattedXml.substr(1);
}
resolve(formattedXml);
}
});
Expand All @@ -123,4 +132,4 @@ export class Formatter {

}

}
}