如何在 Sublime Text 2 中解析来自 TypeScript 的错误消息? [英] How can I parse error messages from TypeScript in Sublime Text 2?

查看:39
本文介绍了如何在 Sublime Text 2 中解析来自 TypeScript 的错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 TypeScript 设置一个 Sublime Text 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.

这是我的示例 TypeScript 程序:

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): 名称我们"不存在于当前范围 C:/data/helloworld.ts(5,37): 名称 'er' 不当前作用域中存在 C:/data/helloworld.ts(5,26): 提供参数与调用目标的任何签名不匹配

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

当我在 Sublime Text 2 中构建时,我看到以下输出:

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

C:/Data/helloworld.ts(5,34): [0.6s 内完成]

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

如原始问题中所述,我尝试了 file_regex 的不同变体,所有变体都具有相同的结果.我当前的文件版本如下:

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]+)\\)\\: (.+)$"
}

当我使用 Python 正则表达式工具测试正则表达式时,此版本正确匹配了 3 个部分.但是,Sublime Text 拒绝向我显示实际的错误消息.

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?

这非常令人沮丧,尤其是一个站点甚至显示了一个正确显示错误消息的 Sublime Text 示例.

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

这是在 Windows 7 64 位上使用 Sublime Text 2.01 64 位.

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

推荐答案

似乎在刷新输出缓冲区之前进程已终止.您可以通过以下方式验证:

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]

<小时>

为了解决这个问题,你可以尝试在批处理文件tsc.cmd中加入一些延迟:

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

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

请参阅 Markus 关于使用 Windows Script Host 而不是 node 的评论.这解决了问题.进一步的研究表明,这实际上是 Windows 上节点的一个已知问题:请参阅此处此处.

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.

这篇关于如何在 Sublime Text 2 中解析来自 TypeScript 的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆