@@ -9,16 +9,14 @@ import path from 'path';
9
9
import { CommandFactory } from '.' ;
10
10
import { getGoConfig , getGoplsConfig } from '../config' ;
11
11
import { inspectGoToolVersion } from '../goInstallTools' ;
12
- import { outputChannel } from '../goStatus' ;
13
12
import { getConfiguredTools } from '../goTools' ;
14
13
import { getBinPath , getCurrentGoPath , getGoEnv , getGoVersion , getToolsGopath } from '../util' ;
15
14
import { getEnvPath , initialEnvPath , getCurrentGoRoot } from '../utils/pathUtils' ;
16
15
17
16
export const getConfiguredGoTools : CommandFactory = ( ) => {
18
17
return async ( ) => {
19
- outputChannel . show ( ) ;
20
- outputChannel . clear ( ) ;
21
- outputChannel . appendLine ( 'Checking configured tools....' ) ;
18
+ // create an untitled markdown document.
19
+ const buf = [ ] ;
22
20
// Tool's path search is done by getBinPathWithPreferredGopath
23
21
// which searches places in the following order
24
22
// 1) absolute path for the alternateTool
@@ -27,45 +25,51 @@ export const getConfiguredGoTools: CommandFactory = () => {
27
25
// 4) gopath
28
26
// 5) GOROOT
29
27
// 6) PATH
30
- outputChannel . appendLine ( 'GOBIN: ' + process . env [ 'GOBIN' ] ) ;
31
- outputChannel . appendLine ( 'toolsGopath: ' + getToolsGopath ( ) ) ;
32
- outputChannel . appendLine ( 'gopath: ' + getCurrentGoPath ( ) ) ;
33
- outputChannel . appendLine ( 'GOROOT: ' + getCurrentGoRoot ( ) ) ;
28
+ buf . push ( '# Tools Configuration\n' ) ;
29
+ buf . push ( '\n## Environment\n' ) ;
30
+ buf . push ( 'GOBIN: ' + process . env [ 'GOBIN' ] ) ;
31
+ buf . push ( 'toolsGopath: ' + getToolsGopath ( ) ) ;
32
+ buf . push ( 'gopath: ' + getCurrentGoPath ( ) ) ;
33
+ buf . push ( 'GOROOT: ' + getCurrentGoRoot ( ) ) ;
34
34
const currentEnvPath = getEnvPath ( ) ;
35
- outputChannel . appendLine ( 'PATH: ' + currentEnvPath ) ;
35
+ buf . push ( 'PATH: ' + currentEnvPath ) ;
36
36
if ( currentEnvPath !== initialEnvPath ) {
37
- outputChannel . appendLine ( `PATH (vscode launched with): ${ initialEnvPath } ` ) ;
37
+ buf . push ( `PATH (vscode launched with): ${ initialEnvPath } ` ) ;
38
38
}
39
- outputChannel . appendLine ( '' ) ;
40
39
41
- const goVersion = await getGoVersion ( ) ;
42
- const allTools = getConfiguredTools ( getGoConfig ( ) , getGoplsConfig ( ) ) ;
43
- const goVersionTooOld = goVersion ?. lt ( '1.12' ) || false ;
40
+ buf . push ( '\n## Tools\n' ) ;
41
+ try {
42
+ const goVersion = await getGoVersion ( ) ;
43
+ const allTools = getConfiguredTools ( getGoConfig ( ) , getGoplsConfig ( ) ) ;
44
+ const goVersionTooOld = goVersion ?. lt ( '1.18' ) || false ;
44
45
45
- outputChannel . appendLine ( `\tgo:\t${ goVersion ?. binaryPath } : ${ goVersion ?. version } ` ) ;
46
- const toolsInfo = await Promise . all (
47
- allTools . map ( async ( tool ) => {
48
- const toolPath = getBinPath ( tool . name ) ;
49
- // TODO(hyangah): print alternate tool info if set.
50
- if ( ! path . isAbsolute ( toolPath ) ) {
51
- // getBinPath returns the absolute path is the tool exists.
52
- // (See getBinPathWithPreferredGopath which is called underneath)
53
- return `\t${ tool . name } :\tnot installed` ;
54
- }
55
- if ( goVersionTooOld ) {
56
- return `\t${ tool . name } :\t${ toolPath } : unknown version` ;
57
- }
58
- const { goVersion, moduleVersion, debugInfo } = await inspectGoToolVersion ( toolPath ) ;
59
- if ( goVersion || moduleVersion ) {
60
- return `\t${ tool . name } :\t${ toolPath } \t(version: ${ moduleVersion } built with go: ${ goVersion } )` ;
61
- } else {
62
- return `\t${ tool . name } :\t${ toolPath } \t(version: unknown - ${ debugInfo } )` ;
63
- }
64
- } )
65
- ) ;
66
- toolsInfo . forEach ( ( info ) => {
67
- outputChannel . appendLine ( info ) ;
68
- } ) ;
46
+ buf . push ( `\tgo:\t${ goVersion ?. binaryPath } : ${ goVersion ?. version } ` ) ;
47
+ const toolsInfo = await Promise . all (
48
+ allTools . map ( async ( tool ) => {
49
+ const toolPath = getBinPath ( tool . name ) ;
50
+ // TODO(hyangah): print alternate tool info if set.
51
+ if ( ! path . isAbsolute ( toolPath ) ) {
52
+ // getBinPath returns the absolute path is the tool exists.
53
+ // (See getBinPathWithPreferredGopath which is called underneath)
54
+ return `\t${ tool . name } :\tnot installed` ;
55
+ }
56
+ if ( goVersionTooOld ) {
57
+ return `\t${ tool . name } :\t${ toolPath } : unknown version` ;
58
+ }
59
+ const { goVersion, moduleVersion, debugInfo } = await inspectGoToolVersion ( toolPath ) ;
60
+ if ( goVersion || moduleVersion ) {
61
+ return `\t${ tool . name } :\t${ toolPath } \t(version: ${ moduleVersion } built with go: ${ goVersion } )` ;
62
+ } else {
63
+ return `\t${ tool . name } :\t${ toolPath } \t(version: unknown - ${ debugInfo } )` ;
64
+ }
65
+ } )
66
+ ) ;
67
+ toolsInfo . forEach ( ( info ) => {
68
+ buf . push ( info ) ;
69
+ } ) ;
70
+ } catch ( e ) {
71
+ buf . push ( `failed to get tools info: ${ e } ` ) ;
72
+ }
69
73
70
74
let folders = vscode . workspace . workspaceFolders ?. map < { name : string ; path ?: string } > ( ( folder ) => {
71
75
return { name : folder . name , path : folder . uri . fsPath } ;
@@ -74,18 +78,24 @@ export const getConfiguredGoTools: CommandFactory = () => {
74
78
folders = [ { name : 'no folder' , path : undefined } ] ;
75
79
}
76
80
77
- outputChannel . appendLine ( '' ) ;
78
- outputChannel . appendLine ( 'go env' ) ;
81
+ buf . push ( '\n## Go env\n' ) ;
79
82
for ( const folder of folders ) {
80
- outputChannel . appendLine ( `Workspace Folder (${ folder . name } ): ${ folder . path } ` ) ;
83
+ buf . push ( `Workspace Folder (${ folder . name } ): ${ folder . path } \n ` ) ;
81
84
try {
82
85
const out = await getGoEnv ( folder . path ) ;
83
86
// Append '\t' to the beginning of every line (^) of 'out'.
84
87
// 'g' = 'global matching', and 'm' = 'multi-line matching'
85
- outputChannel . appendLine ( out . replace ( / ^ / gm, '\t' ) ) ;
88
+ buf . push ( out . replace ( / ^ / gm, '\t' ) ) ;
86
89
} catch ( e ) {
87
- outputChannel . appendLine ( `failed to run 'go env': ${ e } ` ) ;
90
+ buf . push ( `failed to run 'go env': ${ e } ` ) ;
88
91
}
89
92
}
93
+
94
+ // create a new untitled document
95
+ const doc = await vscode . workspace . openTextDocument ( {
96
+ content : buf . join ( '\n' ) ,
97
+ language : 'markdown'
98
+ } ) ;
99
+ await vscode . window . showTextDocument ( doc ) ;
90
100
} ;
91
101
} ;
0 commit comments