oleg-shilo / cs-script.vscode

VSCode extension for CS-Script
MIT License
37 stars 7 forks source link

How to Run CSScript in VSCode using lastest Extension #19

Closed AlGantori closed 4 years ago

AlGantori commented 4 years ago

How to Run CSScript in VSCode

20200215

Goals

  1. It's been a while, can't remember how to run it, and it does not look it wants to run
  2. Last used successfully in VSCode was around 20180517

Extensions Installed?

  1. It appears my VSCode has both of them
    ![image](https://user-images.githubusercontent.com/11699920/74601393-c9b76080-5052-11ea-88e8-279ca858d815.png) >

    ![image](https://user-images.githubusercontent.com/11699920/74601408-f1a6c400-5052-11ea-9cc1-e783eb525202.png)
     
  2. The Toolbar appears as soon as I switch these particular .CS files, That's NICE !!!
    ![image](https://user-images.githubusercontent.com/11699920/74601415-1307b000-5053-11ea-8d92-8eabb4f45d5b.png)
  3. But the Run button produces the following error:
    ![image](https://user-images.githubusercontent.com/11699920/74601623-01270c80-5055-11ea-937f-406b1301ea02.png)

but CS-Script has External? Dependencies...Requirements...

  1. Back in 2018 for the first time in VSCode the Mono was
    The latest Stable Mono release is: 5.12.0 Stable (5.12.0.226)

    I am definitely behind...
     
  2. Download - Stable | Mono
    The latest Stable Mono release is: 6.8.0 Stable (6.8.0.105)
    ![image](https://user-images.githubusercontent.com/11699920/74601465-96c19c80-5053-11ea-8906-5de7e74b6cb5.png)
  3. I downloaded mono-6.8.0.105-x64-0.msi Installed it
  4. No mention whether GTK version? is needed, I forgot what GTK stands for :)
  5. Verified C:\Program Files\Mono\bin\ is still on the path from previous setup....
    ECHO %PATH% >> TMP.TXT

    ![image](https://user-images.githubusercontent.com/11699920/74601497-ebfdae00-5053-11ea-8a78-1fe33d324465.png)
     

My real problem is probably CSCS.EXE is NOT on the path

  1. Searching C:\ reveals the following:

    ![image](https://user-images.githubusercontent.com/11699920/74601501-f750d980-5053-11ea-9328-1f3117ae0c7f.png)
     
  2. So which one should I use?
    1. C:\Users\AXM\AppData\Roaming\Code\User\cs-script.user
    2. C:\Users\AXM\.vscode\extensions\oleg-shilo.cs-script-1.5.10\bin
       
    3. Why wasn't it installed? 
      Perhaps VSCode extension can't do that?


    4.  
  3. Computer Properties...
    ![image](https://user-images.githubusercontent.com/11699920/74601510-0f285d80-5054-11ea-8105-ceb0e82f502b.png)

User Variable

  1. It was set to:

    1. C:\PHP;C:\Ruby22-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Chocolatey\bin;C:\Users\AXM\AppData\Roaming\scriptcs;C:\Program Files\Microsoft VS Code\bin;C:\Users\AXM\AppData\Roaming\npm
  2. Replaced with:
    1. C:\PHP;C:\Ruby22-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Chocolatey\bin;C:\Users\AXM\AppData\Roaming\Code\User\cs-script.user;C:\Program Files\Microsoft VS Code\bin;C:\Users\AXM\AppData\Roaming\npm
  3. Then replaced with
    1. C:\PHP;C:\Ruby22-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Chocolatey\bin;C:\Users\AXM\.vscode\extensions\oleg-shilo.cs-script-1.5.10\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\AXM\AppData\Roaming\npm

System Variables

  1. It was set to:

    1. C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Program Files\Java\jdk1.7.0_03\bin;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\QuickTime\QTSystem\;%JAVA_HOME%\bin;%ADT_HOME%\tools;%ADT_HOME%\platform-tools;%ANT_HOME%\bin;%GIT_HOME%\cmd;C:\Program Files\Microsoft\Web Platform Installer\;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Mono\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd
  2. DID NOT TOUCH
  3. This is kind of a mess, I need an app to manage these vertically, one path per line

Seems like the Path fixed something but not quite CS-Script is still crashing...

  1. Check Syntax works
  2. I get to run once but with the following error
    ![image](https://user-images.githubusercontent.com/11699920/74601520-1cdde300-5054-11ea-9113-a6c0e34cdc9e.png)
  3. my main is practically empty.
     
![INDEX 79](https://user-images.githubusercontent.com/11699920/74601766-70513080-5056-11ea-8b46-7c2054f3028e.jpg) .END. Something wrong with GitHub issues, pasting pictures fails to display some the pictures, instead it displays the link only (preview and after posting) weird. It takes several attempts then sometime it requires drag and drop .
oleg-shilo commented 4 years ago

Sorry, I'll need some time to get through the info you provided. And answer all your questions one by one.

But something has definitely changed in VSCode. The extension is broken now and it has nothing to do with the extension itself as it has not been changed since Mar 18, 2019. Though unfortunately it's not so uncommon with VSCode. :(

Will have a look tomorrow

oleg-shilo commented 4 years ago

I think I have found it.

The problem is quite nasty. It was introduced by the changes in the latest/later version of VSCode. However the problem itself is ultimately caused by the ugly nature of JS runtime, not by the VSCode team changes.

This is what happens:

CS-Scriprt.vscode had this line of code:

let exec = require("child_process").exec;
. . .
process = exec(command);

Note that I missed it and did not use neither var nor let, what is of course is totally legal in JS. It worked in prev versions of VSCode but I am guessing recently VSCode team introduced global variable process: image Meaning that the extension really messes up with the IDE. And it does it so spectacularly that the instance of IDE being debugged crashes completely. This way (under debugger) I was able to pinpoint the offending code line.

Fixing the declaration as below has done the trick:

let exec = require("child_process").exec;
. . .
var process = exec(command); // it's local variable now

The version v1.5.11 should be OK now

AlGantori commented 4 years ago

It's a Fix

A quick test make it a fix. It looks like you are understanding and doing a great job with all this JS stuff :) I jumped into Ionic framework and TypeScript couple years ago, and I dumped all the promises of Microsoft for cross-platform development just to find more headaches :). On the upside I only have to deal in general with three things HTML, TS and CSS.

Help

May I point out few suggestions.

So it looks like define/option CS_SCRIPT is not longer around? I doubt it's something I created? From what I can recall I was using it to switch between debug stepping the script and my assemblies from Visual Studio 2013 then. Also handling things like MessageBox either coming from Winforms or WPF. For today's run I had the remove the Not/Bang "!" as in: #if ! CS_SCRIPT to get it to compile in VSCode. UPDATE: Never mind, I deleted the crucial line by mistake which I have in my other scripts. After all it is my define.

// -) detect if we are running as a script, then define a main()
//css_co /define:CS_SCRIPT;

image

How to handle/configure system PATH

Does VSCode pickup the location of CSScript extension from the path? Is the path something that has to be re-adjusted with every update/revision? C:\Users\AXM\.vscode\extensions\oleg-shilo.cs-script-1.5.11\bin

Thank you for all the assistance and effort you put into this.

oleg-shilo commented 4 years ago

Now, let's answer our questions:

And starting from the next release the changelog will include dates. All is prepared for that: CHANGELOG.md. Good suggestion.

Now available on GitHub: https://github.com/oleg-shilo/cs-script.vscode/blob/master/README.md

Just to give you the context:

AlGantori commented 4 years ago

Thanks for all the answers and additions. Regarding the path one more clarification is needed. It does not appear the installation/update of the extension adjusts the system env. variable path and since VSCode will use path #1 above, then that's the one I need to manually fix my system path with, it appears stable. This is just in case I need cscs.exe from the command line, really no plan for that.

Sorry about path #3, that was remnants from my first days with CSScript plugin in NPP. I no longer intend to use CSScript from NPP with VSCode being around, so I have deleted manually that plugin.

You may close this issue with this bit of info as it completes the title of this issue. Thanks again.

oleg-shilo commented 4 years ago

It does not appear the installation/update of the extension adjusts the system env. variable path and since...

It does not use custom envars it starts the process with an absolute path:

export function user_dir(): string {
    let extensionRoot = path.dirname(path.dirname(path.dirname(__dirname)));
    let isPortable = path.basename(extensionRoot).toLowerCase() == "data" || path.basename(extensionRoot).toLowerCase() == "code-portable-data";

    if (!_user_dir) {

        if (isPortable) {
            _user_dir = path.join(extensionRoot, 'user-data', 'cs-script.user');
        } else {
            if (os.platform() == 'win32') { // win
                _user_dir = path.join(process.env.APPDATA, 'Code', 'User', 'cs-script.user');
            }
            else if (os.platform() == 'darwin') { // mac
                _user_dir = path.join(process.env.HOME, 'Library', 'Application Support', 'Code', 'User', 'cs-script.user');
            }
            else { // linux
                _user_dir = path.join(process.env.HOME, '.config', 'Code', 'User', 'cs-script.user');
            }
        }
    }

    create_dir(_user_dir);
    return _user_dir;
}
...
let cscs_exe: string = path.join(user_dir(), "cscs.exe");
let command = build_command(`"${cscs_exe}" "${file}"`);
let p = exec(command);
...
AlGantori commented 4 years ago

I just wanted to leave you this hint regarding including the version and other release info summary, check out how this extension is doing it. You might be able to do the same, I have no experience authoring extension so you are way ahead of me on this topic.

image

Last time I missed to notice the version in the sidebar because it was narrow or simply my brain/eyes did not expected it to be there.

oleg-shilo commented 4 years ago

Yes the badges is a good idea. They are simply taken form the GitHub page during the publishing. I have updated GitHub so the badges will be available in VSCode with very next release:

https://github.com/oleg-shilo/cs-script.vscode/blob/master/README.md