2

I am trying to setup a Sublime Text 2 build system for TypeScript. I have followed the directions I found here. Actually calling out to the compiler works, however it does not pick up the error messages correctly.

Here is my sample TypeScript program:

function greeter(person: string) {
     return "Hello, " + person;
}
var user = "Jane User";
document.body.innerHTML = greeter(us-er);

When I compile from the command line, I see the following output:

C:/data/helloworld.ts(5,34): The name 'us' does not exist in the current scope C:/data/helloworld.ts(5,37): The name 'er' does not exist in the current scope C:/data/helloworld.ts(5,26): Supplied parameters do not match any signature of call target

When I build from within Sublime Text 2 I see the following output:

C:/Data/helloworld.ts(5,34): [Finished in 0.6s]

I have tried different variations of the file_regex, as mentioned in the original question, all with the same result. My current version of the file looks like:

{
    "selector": "source.ts",
    "cmd": ["tsc.cmd", "--target","ES5", "$file"],
    "file_regex": "^(.+?)\\(([0-9]+,[0-9]+)\\)\\: (.+)$"
}

When I test the regex using the Python Regex Tool this version matches the 3 parts correctly. However, Sublime Text refuses to show me the actual error message.

Can anybody point out what I am doing wrong?

It is very frustrating, especially as the one site even shows an example of Sublime Text correctly displaying the error message.

This is with Sublime Text 2.01 64-bit on Windows 7 64-bit.

Community
  • 1
  • 1
David Sykes
  • 7,131
  • 4
  • 36
  • 39

1 Answers1

1

It looks like the process is terminated before the output buffer is flushed. You could verify this with:

{
    "selector": "source.ts",
    "cmd": ["tsc.cmd", "--target","ES5", "$file"],
    "file_regex": "(.*)"
}

You should still only get something like

C:/Data/helloworld.ts(5,34): [Finished in 0.6s]

To solve this problem, you could try to put some delay into the batch-file tsc.cmd:

@echo off
:: Run the compiler
node "C:\typescript\tsc.js" %*

:: Waits for 500ms
ping 1.1.1.1 -n 1 -w 500

EDIT: See Markus' comment about using Windows Script Host instead of node. This fixes the problem. Further research suggests this is actually a known issue with node on Windows: see here and here.

David Sykes
  • 7,131
  • 4
  • 36
  • 39
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • Thanks for the tip Markus. I tried what you suggested, but the result is basically the same. It now looks like: "C:/Data/helloworld.ts(5,34): C:\Data>SilentWaiter 2000 Done waiting! [Finished in 2.7s]" - I am out of ideas of what to try next :-( – David Sykes Nov 15 '12 at 20:01
  • What javascript engine are you using? Could you call it directly? Could you try another one? – Markus Jarderot Nov 15 '12 at 22:43
  • I am using nodejs, "node -v" displays "v0.8.14". This is the official Windows install from the nodejs.org web site. It appears to be 64-bit as well. What other options do I even have? – David Sykes Nov 15 '12 at 22:48
  • 1
    It should work. Try calling it directly, instead of trough `tsc.cmd`. If nothing works, you could try Windows Scripting Host: `cscript //NoLogo tsc.js --target ES5 yourfile.ts` – Markus Jarderot Nov 15 '12 at 23:04
  • Thanks Markus, using Windows Scripting Host fixed the problem. Turns out it is a known issue with node on Windows. I updated your answer to include this info and accepted it. – David Sykes Nov 16 '12 at 05:51