简体   繁体   English

无法在Visual Studio代码和Windows 10中编译Swift文件

[英]Unable to compile swift file in Visual Studio code and Windows 10

What I am trying to do is use Visual Studio code to compile a swift language code that I am trying to run but unfortunately I am getting an error with tasks.json file 我想做的是使用Visual Studio代码编译我要运行的快速语言代码,但不幸的是,我在task.json文件中遇到错误

error TS6054: File 'section-1.swift' must have extension '.ts' or '.d.ts'. 错误TS6054:文件“ section-1.swift”必须具有扩展名“ .ts”或“ .d.ts”。

I have followed the steps as mentioned by David Owens II http://owensd.io/2015/05/21/swift-vscode.html and also referenced older stuff from Stack Overflow and installed Typescript from npm command prompt and modified Tasks.json file as shown below 我遵循了David Owens II http://owensd.io/2015/05/21/swift-vscode.html所述的步骤,还引用了Stack Overflow中的旧内容,并从npm命令提示符下安装了Typescript,并修改了Tasks.json文件如下图所示

{
    "version": "0.1.0",

    // The command is tsc.
    "command": "swiftc",

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "silent",

    // Under windows use tsc.exe. This ensures we don't need a shell.
    "windows": {
        "command": "tsc.cmd"
    },

    // args is the HelloWorld program to compile.
    "args": ["section-1.swift"],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": {
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

My question in here is as my file is a swift file how would I convert it to .ts file as this is causing the error?Any help will be appreciated.Thanks 我在这里的问题是因为我的文件是swift文件,如何将其转换为.ts文件,因为这会导致错误?任何帮助将不胜感激。

Looks like VSCode is trying to execute the file as if it were a TS file, and not a swift file. 似乎VSCode试图执行该文件,就好像它是TS文件而不是swift文件一样。 Perhaps it's the following lines? 也许是以下几行?

// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
    "command": "tsc.cmd"
},

I know you're not on windows, but VSCode could be confused by this line, vs the other line. 我知道您不在Windows上,但此行与另一行可能会使VSCode感到困惑。 Perhaps just try changing it to swift.cmd, or removing the section entirely. 也许只是尝试将其更改为swift.cmd,或完全删除该部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM