如何在 VS Code 上使 golint 在类型检查时运行,而不是在保存时运行?

huangapple go评论82阅读模式
英文:

How can I make golint run on VS Code on type instead of on save?

问题

我正在使用VS Code和lukehoban的Go扩展:

https://github.com/Microsoft/vscode-go

看起来当你保存文件时会运行golint,有没有办法让golint在我开始输入时运行?通常,当我们在其他扩展和语言(如jslint和tslint)上输入时会进行linting,在VS Code上也可以这样做会很好。

我该怎么做才能实现这个功能呢?

英文:

I am using VS Code and the Go extension from lukehoban:

https://github.com/Microsoft/vscode-go

It seems like the golint is run when you save the file, is there a way for me to make golint run when I start typing? Usually linting happens when we type on other extensions and languages such as jslint, and tslint on VS Code. It would be nice to have the option to also be able to do this with golint.

What could I do to achieve this?

答案1

得分: 5

似乎根本不可能。

关于 golint,只有以下可用的配置项:

// 在保存时运行 Lint 工具。
"go.lintOnSave": true,

// 指定 Lint 工具的名称。
"go.lintTool": "golint",

// 传递给 Lint 工具的标志(例如 ["-min_confidence=.8"])。
"go.lintFlags": [],

不过,也许你可以通过更改这些选项来进行修改:

// 控制自动保存脏文件。接受的值为 "off"、"afterDelay"、"onFocusChange"(编辑器失去焦点)和 "onWindowChange"(窗口失去焦点)。如果设置为 "afterDelay",可以配置延迟时间("files.autoSaveDelay")。
"files.autoSave": "off",

// 在脏文件自动保存之前的延迟时间(以毫秒为单位)。仅当 "files.autoSave" 设置为 "afterDelay" 时才适用。
"files.autoSaveDelay": 1000,

你可以将 files.autoSave 设置为 afterDelay,并降低 files.autoSaveDelay 的值。

英文:

It seems like it's not possible at all.

The only available configs regarding golint are:

  // Run Lint tool on save.
  "go.lintOnSave": true,

  // Specifies Lint tool name.
  "go.lintTool": "golint",

  // Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
  "go.lintFlags": [],

Maybe you can hack this by changing these options though:

  // Controls auto save of dirty files. Accepted values:  "off", "afterDelay", "onFocusChange" (editor loses focus), "onWindowChange" (window loses focus). If set to "afterDelay", you can configure the delay in "files.autoSaveDelay".
  "files.autoSave": "off",

  // Controls the delay in ms after which a dirty file is saved automatically. Only applies when "files.autoSave" is set to "afterDelay"
  "files.autoSaveDelay": 1000,

You could set files.autoSave to afterDelay and a lower files.autoSaveDelay.

答案2

得分: 5

这边的Go让我疯狂...

所以,我找到了一个叫做"go.useLanguageServer"的选项(很可能我之前找到过它,但出于某种原因,这个选项并不容易找到)。

"go.useLanguageServer": true,

此外,还有这些选项:

"go.languageServerExperimentalFeatures": {
    "diagnostics": true,
    "documentLink": true
},
"go.liveErrors": {
    "enabled": true,
    "delay": 500,
},
英文:

This side of Go makes me crazy...

So, I've found an option called "go.useLanguageServer" (most likely I had found it some-when earlier, but for some reason it's not so easy to find that option anyway).

"go.useLanguageServer": true,

Also, there're these options:

"go.languageServerExperimentalFeatures": {
    "diagnostics": true,
    "documentLink": true
},
"go.liveErrors": {
    "enabled": true,
    "delay": 500,
},

huangapple
  • 本文由 发表于 2017年2月21日 00:30:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/42349678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定