@@ -13,6 +13,7 @@ import { formatGoVersion, GoEnvironmentOption, terminalCreationListener } from '
13
13
import { buildLanguageServerConfig , getLocalGoplsVersion , languageServerIsRunning , serverOutputChannel } from './goLanguageServer' ;
14
14
import { isGoFile } from './goMode' ;
15
15
import { getModFolderPath , isModSupported } from './goModules' ;
16
+ import { allToolsInformation } from './goTools' ;
16
17
import { getGoVersion } from './util' ;
17
18
18
19
export let outputChannel = vscode . window . createOutputChannel ( 'Go' ) ;
@@ -24,6 +25,7 @@ export let goEnvStatusbarItem: vscode.StatusBarItem;
24
25
25
26
let modulePath : string ;
26
27
export const languageServerIcon = '$(zap)' ;
28
+ export const languageServerErrorIcon = '$(warning)' ;
27
29
28
30
export function updateGoStatusBar ( editor : vscode . TextEditor ) {
29
31
// Only update the module path if we are in a Go file.
@@ -47,11 +49,17 @@ export async function expandGoStatusBar() {
47
49
] ;
48
50
49
51
// Get the gopls configuration
50
- const cfg = buildLanguageServerConfig ( getGoConfig ( ) ) ;
52
+ const goConfig = getGoConfig ( ) ;
53
+ const cfg = buildLanguageServerConfig ( goConfig ) ;
51
54
if ( languageServerIsRunning && cfg . serverName === 'gopls' ) {
52
55
const goplsVersion = await getLocalGoplsVersion ( cfg ) ;
53
56
options . push ( { label : `${ languageServerIcon } Open 'gopls' trace` , description : `${ goplsVersion } ` } ) ;
54
57
}
58
+ if ( ! languageServerIsRunning && ! cfg . serverName && goConfig [ 'useLanguageServer' ] ) {
59
+ options . push ( {
60
+ label : `Install Go Language Server` ,
61
+ description : `${ languageServerErrorIcon } 'gopls' is required but missing` } ) ;
62
+ }
55
63
56
64
// If modules is enabled, add link to mod file
57
65
if ( ! ! modulePath ) {
@@ -72,6 +80,9 @@ export async function expandGoStatusBar() {
72
80
serverOutputChannel . show ( ) ;
73
81
}
74
82
break ;
83
+ case `Install Go Language Server` :
84
+ vscode . commands . executeCommand ( 'go.tools.install' , [ allToolsInformation [ 'gopls' ] ] ) ;
85
+ break ;
75
86
case `Open 'go.mod'` :
76
87
const openPath = vscode . Uri . file ( item . description ) ;
77
88
vscode . workspace . openTextDocument ( openPath ) . then ( ( doc ) => {
@@ -101,27 +112,37 @@ export async function initGoStatusBar() {
101
112
// Add an icon to indicate that the 'gopls' server is running.
102
113
// Assume if it is configured it is already running, since the
103
114
// icon will be updated on an attempt to start.
104
- const cfg = buildLanguageServerConfig ( getGoConfig ( ) ) ;
105
- updateLanguageServerIconGoStatusBar ( languageServerIsRunning , cfg . serverName ) ;
115
+ const goConfig = getGoConfig ( ) ;
116
+ const cfg = buildLanguageServerConfig ( goConfig ) ;
117
+ updateLanguageServerIconGoStatusBar ( languageServerIsRunning , goConfig [ 'useLanguageServer' ] ) ;
106
118
107
119
showGoStatusBar ( ) ;
108
120
}
109
121
110
- export async function updateLanguageServerIconGoStatusBar ( started : boolean , server : string ) {
122
+ export function updateLanguageServerIconGoStatusBar ( started : boolean , enabled : boolean ) {
111
123
if ( ! goEnvStatusbarItem ) {
112
124
return ;
113
125
}
114
126
115
- const text = goEnvStatusbarItem . text ;
116
- if ( started && server === 'gopls' ) {
117
- if ( ! text . endsWith ( languageServerIcon ) ) {
118
- goEnvStatusbarItem . text = text + languageServerIcon ;
119
- }
120
- } else {
121
- if ( text . endsWith ( languageServerIcon ) ) {
122
- goEnvStatusbarItem . text = text . substring ( 0 , text . length - languageServerIcon . length ) ;
123
- }
127
+ // Split the existing goEnvStatusbarItem.text into the version string part and
128
+ // the gopls icon part.
129
+ let text = goEnvStatusbarItem . text ;
130
+ let icon = '' ;
131
+ if ( text . endsWith ( languageServerIcon ) ) {
132
+ icon = languageServerIcon ;
133
+ text = text . substring ( 0 , text . length - languageServerIcon . length ) ;
134
+ } else if ( text . endsWith ( languageServerErrorIcon ) ) {
135
+ icon = languageServerErrorIcon ;
136
+ text = text . substring ( 0 , text . length - languageServerErrorIcon . length ) ;
124
137
}
138
+
139
+ if ( started && enabled ) {
140
+ icon = languageServerIcon ;
141
+ } else if ( ! started && enabled ) {
142
+ icon = languageServerErrorIcon ;
143
+ }
144
+
145
+ goEnvStatusbarItem . text = text + icon ;
125
146
}
126
147
127
148
/**
0 commit comments