Skip to content

Commit d114767

Browse files
Or Binhyangah
authored andcommitted
commands: add go.goroot command
Add go.goroot command, similar to the existing go.gopath. Closes #2379. Change-Id: I4851df5406897b347dbf17bd1f35e751d6ffa85a GitHub-Last-Rev: 0e355e9 GitHub-Pull-Request: #2381 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/419834 TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent 484a3ba commit d114767

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

docs/commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Finally, you can also see a full list by using a meta command: `Go: Show All Com
2727

2828
See the currently set GOPATH.
2929

30+
### `Go: Current GOROOT`
31+
32+
See the currently set GOROOT.
33+
3034
### `Go: Locate Configured Go Tools`
3135

3236
List all the Go tools being used by this extension along with their locations.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"workspaceContains:*/*.go",
9696
"workspaceContains:*/*/*.go",
9797
"onCommand:go.gopath",
98+
"onCommand:go.goroot",
9899
"onCommand:go.tools.install",
99100
"onCommand:go.locate.tools",
100101
"onCommand:go.show.commands",
@@ -211,6 +212,11 @@
211212
"title": "Go: Current GOPATH",
212213
"description": "See the currently set GOPATH."
213214
},
215+
{
216+
"command": "go.goroot",
217+
"title": "Go: Current GOROOT",
218+
"description": "See the currently set GOROOT."
219+
},
214220
{
215221
"command": "go.locate.tools",
216222
"title": "Go: Locate Configured Go Tools",

src/commands/getCurrentGoRoot.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------
2+
* Copyright 2022 The Go Authors. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for license information.
4+
*--------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
8+
import { CommandFactory } from '.';
9+
import { getCurrentGoRoot as utilGetCurrentGoRoot } from '../utils/pathUtils';
10+
11+
export const getCurrentGoRoot: CommandFactory = () => {
12+
return () => {
13+
const goroot = utilGetCurrentGoRoot();
14+
const msg = `${goroot} is the current GOROOT.`;
15+
vscode.window.showInformationMessage(msg);
16+
return goroot;
17+
};
18+
};

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { GoExtensionContext } from '../context';
1010
export { applyCoverprofile } from './applyCoverprofile';
1111
export { getConfiguredGoTools } from './getConfiguredGoTools';
1212
export { getCurrentGoPath } from './getCurrentGoPath';
13+
export { getCurrentGoRoot } from './getCurrentGoRoot';
1314
export { extractFunction, extractVariable } from '../goDoctor';
1415
export { runFillStruct } from '../goFillStruct';
1516
export { implCursor } from '../goImpl';

src/goMain.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<ExtensionA
136136
ctx.subscriptions.push(goCtx.vetDiagnosticCollection);
137137

138138
registerCommand('go.gopath', commands.getCurrentGoPath);
139+
registerCommand('go.goroot', commands.getCurrentGoRoot);
139140
registerCommand('go.locate.tools', commands.getConfiguredGoTools);
140141
registerCommand('go.add.tags', commands.addTags);
141142
registerCommand('go.remove.tags', commands.removeTags);

0 commit comments

Comments
 (0)