@@ -18,7 +18,7 @@ import {
18
18
serverOutputChannel
19
19
} from './goLanguageServer' ;
20
20
import { isGoFile } from './goMode' ;
21
- import { getModFolderPath , isModSupported } from './goModules' ;
21
+ import { isModSupported , runGoEnv } from './goModules' ;
22
22
import { allToolsInformation } from './goToolsInformation' ;
23
23
import { getGoVersion } from './util' ;
24
24
@@ -34,22 +34,26 @@ diagnosticsStatusBarItem.name = STATUS_BAR_ITEM_NAME;
34
34
// statusbar item for switching the Go environment
35
35
export let goEnvStatusbarItem : vscode . StatusBarItem ;
36
36
37
- let modulePath : string ;
37
+ let gomod : string ;
38
+ let gowork : string ;
38
39
export const languageServerIcon = '$(zap)' ;
39
40
export const languageServerErrorIcon = '$(warning)' ;
40
41
41
- export function updateGoStatusBar ( editor : vscode . TextEditor ) {
42
+ export async function updateGoStatusBar ( editor : vscode . TextEditor ) {
42
43
// Only update the module path if we are in a Go file.
43
44
// This allows the user to open output windows without losing
44
45
// the go.mod information in the status bar.
45
46
if ( ! ! editor && isGoFile ( editor . document ) ) {
46
- isModSupported ( editor . document . uri ) . then ( ( isMod ) => {
47
- if ( isMod ) {
48
- getModFolderPath ( editor . document . uri ) . then ( ( p ) => ( modulePath = p ) ) ;
49
- } else {
50
- modulePath = '' ;
51
- }
52
- } ) ;
47
+ const isMod = await isModSupported ( editor . document . uri ) ;
48
+ if ( isMod ) {
49
+ runGoEnv ( path . dirname ( editor . document . uri . fsPath ) , [ 'GOMOD' , 'GOWORK' ] ) . then ( ( p ) => {
50
+ gomod = p [ 'GOMOD' ] === '/dev/null' || p [ 'GOMOD' ] === 'NUL' ? '' : p [ 'GOMOD' ] ;
51
+ gowork = p [ 'GOWORK' ] ;
52
+ } ) ;
53
+ } else {
54
+ gomod = '' ;
55
+ gowork = '' ;
56
+ }
53
57
}
54
58
}
55
59
@@ -74,8 +78,12 @@ export async function expandGoStatusBar() {
74
78
}
75
79
76
80
// If modules is enabled, add link to mod file
77
- if ( modulePath ) {
78
- options . push ( { label : "Open 'go.mod'" , description : path . join ( modulePath , 'go.mod' ) } ) ;
81
+ if ( gomod ) {
82
+ options . push ( { label : "Open 'go.mod'" , description : gomod } ) ;
83
+ }
84
+
85
+ if ( gowork ) {
86
+ options . push ( { label : "Open 'go.work'" , description : gowork } ) ;
79
87
}
80
88
81
89
vscode . window . showQuickPick ( options ) . then ( ( item ) => {
@@ -95,6 +103,7 @@ export async function expandGoStatusBar() {
95
103
case 'Install Go Language Server' :
96
104
vscode . commands . executeCommand ( 'go.tools.install' , [ allToolsInformation [ 'gopls' ] ] ) ;
97
105
break ;
106
+ case "Open 'go.work'" :
98
107
case "Open 'go.mod'" :
99
108
const openPath = vscode . Uri . file ( item . description ) ;
100
109
vscode . workspace . openTextDocument ( openPath ) . then ( ( doc ) => {
0 commit comments