Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

go.vetFlags does not support ${workspaceRoot} #2527

Closed
tamayika opened this issue May 20, 2019 · 5 comments · Fixed by #2528
Closed

go.vetFlags does not support ${workspaceRoot} #2527

tamayika opened this issue May 20, 2019 · 5 comments · Fixed by #2528

Comments

@tamayika
Copy link
Contributor

tamayika commented May 20, 2019

I'm using custom go analyzer using https://godoc.org/golang.org/x/tools/go/analysis and https://godoc.org/golang.org/x/tools/go/analysis/unitchecker.
In command line, I can execute like below.

$ go vet -vettool=`which mytool`

I also want to use mytool in vscode-go extension, but vscode runs go vet in package dir, so I must set absolute path like below.

{
  "go.vetFlags": [
    "-vettool=${workspaceRoot}/bin/mytool"
  ]
}

However "go.vetFlags" does not support ${workspaceRoot}, it remains as is.

I found go.lintFlags support ${workspaceRoot} especially for config flag.

vscode-go/src/goLint.ts

Lines 70 to 85 in af6f7a0

lintFlags.forEach(flag => {
// --json is not a valid flag for golint and in gometalinter, it is used to print output in json which we dont want
if (flag === '--json') {
return;
}
if (flag.startsWith('--config=') || flag.startsWith('-config=')) {
let configFilePath = flag.substr(flag.indexOf('=') + 1).trim();
if (!configFilePath) {
return;
}
configFilePath = resolvePath(configFilePath);
args.push(`${flag.substr(0, flag.indexOf('=') + 1)}${configFilePath}`);
return;
}
args.push(flag);
});

Is it difficult to support this feature in vscode-go?

@ramya-rao-a
Copy link
Contributor

Its not difficult

You see the support for $workspaceRoot for just the config flag in the lint flags. The same can be done for -vettool as well.

PRs to add this feature are most welcome.
Code Pointers:

  • Build and Debug the extension
  • goVet.ts is the file to update and

    vscode-go/src/goLint.ts

    Lines 70 to 85 in af6f7a0

    lintFlags.forEach(flag => {
    // --json is not a valid flag for golint and in gometalinter, it is used to print output in json which we dont want
    if (flag === '--json') {
    return;
    }
    if (flag.startsWith('--config=') || flag.startsWith('-config=')) {
    let configFilePath = flag.substr(flag.indexOf('=') + 1).trim();
    if (!configFilePath) {
    return;
    }
    configFilePath = resolvePath(configFilePath);
    args.push(`${flag.substr(0, flag.indexOf('=') + 1)}${configFilePath}`);
    return;
    }
    args.push(flag);
    });
    can be taken as reference

@tamayika
Copy link
Contributor Author

thanks for the reply. I'll make a PR

@ramya-rao-a
Copy link
Contributor

Your changes are in the latest beta version of this extension. Can you try it out and confirm that the fix works as expected?

@tamayika
Copy link
Contributor Author

Thanks for the beta release. I confirmed it works as expected!

@ramya-rao-a
Copy link
Contributor

This feature is now available in the latest update (0.11.0) to the Go extension. Thanks @tamayika!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 8, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants