nikomedes / vs-tcc

MIT License
0 stars 1 forks source link

Suggestion some features #3

Open dhunter-git opened 6 months ago

dhunter-git commented 6 months ago

Hello. I use your extension and I hope some kind of features.

Here are codes.

commands.ts

1) Check activeTextEditor, if untitled, suggest save first 2) if is not C file, cannot Run/Compile 3) Auto Save and Run/Compile 4) If already activated TCC terminal, no show terminal, so cursor leaved TextEditor

function call_tcc(run_arg:string): void
{
  if(vscode.window.activeTextEditor === undefined)
  {
    vscode.window.showInformationMessage('Tiny-C Compiler tcc Extension : Load file first');
  }  
  else if( vscode.window.activeTextEditor.document.isUntitled )
  {
    vscode.window.showInformationMessage('Tiny-C Compiler tcc Extension : Save file first');
  }
  else if(vscode.window.activeTextEditor.document.languageId === "c")
  {
    let _activeTextEditor: vscode.TextDocument = vscode.window.activeTextEditor.document;
    if (_activeTextEditor.isDirty) {_activeTextEditor.save();};
    checkTerminal();
    getLatestTerminal().sendText(tcc(getFlags() + run_arg + getArgs()));
    if ( (vscode.window.activeTerminal === undefined) || (vscode.window.activeTerminal !== _terminalStack[0]) )
    { 
      getLatestTerminal().show(); 
    }
  }
  else
  {
    vscode.window.showInformationMessage('Tiny-C Compiler tcc Extension : must Edit C file');
  } 
}

export function run(): void {
  call_tcc(" -run ");
}

export function compile(): void {
  call_tcc(" ");
}

Bug Fix 1) If terminal closed by user, make new terminal.

function newTerminal() {
    let terminal = vscode.window.createTerminal(
      `TCC Terminal`
    );
    _terminalStack.push(terminal);
}

function checkTerminal() {
  if (0 === _terminalStack.length) {
   newTerminal();
  }
  else if(!vscode.window.terminals.includes(_terminalStack[0]))
  {
    _terminalStack.pop();
    newTerminal();
  }
}
nikomedes commented 6 months ago

Hello, thanks for your feedback. I will check this for the next release.