@@ -9,16 +9,14 @@ import path from 'path';
99import { CommandFactory } from '.' ;
1010import { getGoConfig , getGoplsConfig } from '../config' ;
1111import { inspectGoToolVersion } from '../goInstallTools' ;
12- import { outputChannel } from '../goStatus' ;
1312import { getConfiguredTools } from '../goTools' ;
1413import { getBinPath , getCurrentGoPath , getGoEnv , getGoVersion , getToolsGopath } from '../util' ;
1514import { getEnvPath , initialEnvPath , getCurrentGoRoot } from '../utils/pathUtils' ;
1615
1716export const getConfiguredGoTools : CommandFactory = ( ) => {
1817 return async ( ) => {
19- outputChannel . show ( ) ;
20- outputChannel . clear ( ) ;
21- outputChannel . appendLine ( 'Checking configured tools....' ) ;
18+ // create an untitled markdown document.
19+ const buf = [ ] ;
2220 // Tool's path search is done by getBinPathWithPreferredGopath
2321 // which searches places in the following order
2422 // 1) absolute path for the alternateTool
@@ -27,45 +25,51 @@ export const getConfiguredGoTools: CommandFactory = () => {
2725 // 4) gopath
2826 // 5) GOROOT
2927 // 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 ( ) ) ;
3434 const currentEnvPath = getEnvPath ( ) ;
35- outputChannel . appendLine ( 'PATH: ' + currentEnvPath ) ;
35+ buf . push ( 'PATH: ' + currentEnvPath ) ;
3636 if ( currentEnvPath !== initialEnvPath ) {
37- outputChannel . appendLine ( `PATH (vscode launched with): ${ initialEnvPath } ` ) ;
37+ buf . push ( `PATH (vscode launched with): ${ initialEnvPath } ` ) ;
3838 }
39- outputChannel . appendLine ( '' ) ;
4039
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 ;
4445
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+ }
6973
7074 let folders = vscode . workspace . workspaceFolders ?. map < { name : string ; path ?: string } > ( ( folder ) => {
7175 return { name : folder . name , path : folder . uri . fsPath } ;
@@ -74,18 +78,24 @@ export const getConfiguredGoTools: CommandFactory = () => {
7478 folders = [ { name : 'no folder' , path : undefined } ] ;
7579 }
7680
77- outputChannel . appendLine ( '' ) ;
78- outputChannel . appendLine ( 'go env' ) ;
81+ buf . push ( '\n## Go env\n' ) ;
7982 for ( const folder of folders ) {
80- outputChannel . appendLine ( `Workspace Folder (${ folder . name } ): ${ folder . path } ` ) ;
83+ buf . push ( `Workspace Folder (${ folder . name } ): ${ folder . path } \n ` ) ;
8184 try {
8285 const out = await getGoEnv ( folder . path ) ;
8386 // Append '\t' to the beginning of every line (^) of 'out'.
8487 // 'g' = 'global matching', and 'm' = 'multi-line matching'
85- outputChannel . appendLine ( out . replace ( / ^ / gm, '\t' ) ) ;
88+ buf . push ( out . replace ( / ^ / gm, '\t' ) ) ;
8689 } catch ( e ) {
87- outputChannel . appendLine ( `failed to run 'go env': ${ e } ` ) ;
90+ buf . push ( `failed to run 'go env': ${ e } ` ) ;
8891 }
8992 }
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 ) ;
90100 } ;
91101} ;
0 commit comments